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
What's this line supposed to do?
Code:FileExists carpetaRaiz, filename
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks