Go Back   CodeCall Programming Forum > Software Development > Visual Basic Programming
Register Blogs Search Today's Posts Mark Forums Read

Visual Basic Programming Discussion forum for Visual Basic, an event driven programming language and associated development environment from Microsoft for its COM programming model.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-10-2009, 03:40 PM
Learning Programmer
 
Join Date: May 2008
Posts: 45
reniery is an unknown quantity at this point
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-10-2009, 07:15 PM
Vswe's Avatar
Code Slinger
 
Join Date: Apr 2009
Location: Uppsala, Sweden
Age: 16
Posts: 8,536
Vswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond repute
Send a message via MSN to Vswe Send a message via Skype™ to Vswe
Re: problem with recursive function

What's this line supposed to do?

Code:
 
FileExists carpetaRaiz, filename
__________________
My CC Blog | My Website |Periodic table | Pm me | Ask me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0