+ Reply to Thread
Results 1 to 2 of 2

Thread: problem with recursive function

  1. #1
    Learning Programmer reniery is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    45

    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

  2. #2
    Moderator Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe's Avatar
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Age
    16
    Posts
    8,794
    Blog Entries
    5

    Re: problem with recursive function

    What's this line supposed to do?

    Code:
     
    FileExists carpetaRaiz, filename

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. XML Result from PHP?
    By Ricardo-san in forum PHP Forum
    Replies: 14
    Last Post: 04-09-2009, 11:03 PM
  2. Recursive Problem
    By chili5 in forum Java Help
    Replies: 3
    Last Post: 11-26-2008, 09:23 PM
  3. C++ - Problem with a binary tree program; need help
    By Ratchet2246 in forum C and C++
    Replies: 4
    Last Post: 07-15-2008, 02:32 PM
  4. Problem n creating a function
    By bishoujo in forum Database & Database Programming
    Replies: 0
    Last Post: 06-02-2008, 01:55 AM
  5. using Template function
    By Chinmoy in forum C Tutorials
    Replies: 4
    Last Post: 04-03-2008, 04:16 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts