|
||||||
| Visual Basic Programming Discussion forum for Visual Basic, an event driven programming language and associated development environment from Microsoft for its COM programming model. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
problem with recursive function
So i'm helping my bro with this hmwk he has and he did this function. Problem is it doesn't do what he wants and I can't figure out why. The part where he does some string manipulation is completely wrong but I'm sure he can fix it. For some reason the function returns an empty string when it should return a string. So what's wrong with this function (apart from the string manipulation ) why does it return an empty string.
What the function is suppose to do is check if a file exists in a folder, if it does exists change the filename to avoid a file already exists error when moving files between folders. Code:
Function FileExists(ByVal carpetaRaiz As String, ByVal sFileName As String) As String
Dim filename As String
Dim part1 As String
Dim part2 As String
Dim part3 As String
Dim part4 As String
Dim pos1 As Integer
Dim pos2 As Integer
Dim length As Integer
Dim number As Integer
If Dir(carpetaRaiz & "\" & sFileName) <> "" Then 'file exists
length = Len(sFileName)
If InStr(sFileName, "-") <> 0 Then
pos1 = InStr(sFileName, "-")
pos2 = InStr(sFileName, ".")
part1 = Mid(sFileName, 1, pos1 - 1)
part2 = Mid(sFileName, pos1 + 1, pos2 - 1)
part3 = Mid(sFileName, pos2 + 1)
If IsNumeric(part2) Then
number = CInt(part2)
number = number + 1
part4 = Mid(part2, 1, Len(part2) - 1)
part2 = CStr(number)
part2 = part4 & part2
End If
Else
pos1 = InStr(sFileName, ".")
part1 = Mid(sFileName, 1, pos1 - 1)
part2 = "002"
part3 = Mid(sFileName, pos1 + 1)
End If
filename = part1 & "-" & part2 & "." & part3
FileExists carpetaRaiz, filename
Else ' doesnt exist
FileExists = sFileName
'sfile.Move (carpetaRaiz & "\" & sfile.Name)
End If
End Function
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| XML Result from PHP? | Ricardo-san | PHP Forum | 14 | 04-10-2009 12:03 AM |
| Recursive Problem | chili5 | Java Help | 3 | 11-26-2008 10:23 PM |
| C++ - Problem with a binary tree program; need help | Ratchet2246 | C and C++ | 4 | 07-15-2008 03:32 PM |
| Problem n creating a function | bishoujo | Database & Database Programming | 0 | 06-02-2008 02:55 AM |
| using Template function | Chinmoy | C Tutorials | 4 | 04-03-2008 05:16 AM |
All times are GMT -5. The time now is 11:39 PM.
Amrosama.cc
Arekbulski.cc
Debtboy.cc
Guest.cc
Jaan.cc
James.cc
Mathx.cc
Tsz.cc
Vswe.cc