Using Mid function and/or statement in IF

Reply

Join Date: Aug 2006
Posts: 5
Reputation: VBWayne is an unknown quantity at this point 
Solved Threads: 0
VBWayne VBWayne is offline Offline
Newbie Poster

Using Mid function and/or statement in IF

 
0
  #1
Aug 16th, 2006
I've created the following series of If statements that are totally disfunctional. I'm thinking it has to do with my lack of understanding between a function and a statement. (I'm an old mainframe programmer and sometimes have difficulties crossing over)
Even though when I do a watch on the fields, the values are what I expect, the if statement doesn't perform the Then... and the Else on the 3rd errors out.

Here's the code I'm trying to get working:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Function Getareaname(flname As String) As String
  2. Dim fposn As Long, i As Integer
  3. Dim fName As String
  4. Dim tmpname As String
  5. fName = "d:\getarea"
  6. fposn = 11
  7. For i = 1 To Len(flname)
  8. If Mid(flname, i, 2) = "//" Then GoTo skipnext
  9. If Mid(flname, i, 2) = "u:" Then GoTo skiplev
  10. If Mid(flname, i, 1) = "/" Then Mid(fName, fposn, 1) = "\" Else: Mid(fName, fposn, 1) = Mid(flname, i)
  11. fposn = fposn + 1
  12. skipnext:
  13. Next i
  14. Getareaname = fName
Last edited by Comatose; Aug 16th, 2006 at 5:49 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Using Mid function and/or statement in IF

 
0
  #2
Aug 16th, 2006
Originally Posted by VBWayne
I've created the following series of If statements that are totally disfunctional. I'm thinking it has to do with my lack of understanding between a function and a statement. (I'm an old mainframe programmer and sometimes have difficulties crossing over)
Even though when I do a watch on the fields, the values are what I expect, the if statement doesn't perform the Then... and the Else on the 3rd errors out.
I see 3 if statements. Can you be less vague? The way you phrased this you could be talking about eny one of them. And what does errors out mean?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ... Mid(fName, fposn, 1) = Mid(flname, i)
Are you trying to load multiple characters into one character here? I'm not sure but I believe you might need to rethink this command.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 5
Reputation: VBWayne is an unknown quantity at this point 
Solved Threads: 0
VBWayne VBWayne is offline Offline
Newbie Poster

Re: Using Mid function and/or statement in IF

 
0
  #3
Aug 16th, 2006
Thank you for responding.

Originally Posted by WaltP
I see 3 if statements. Can you be less vague? The way you phrased this you could be talking about eny one of them. And what does errors out mean?
All 3 are having a problem. for instance, in debug mode I see that the first IF statement value is indeed "//", but it doesn't execute the goto, but goes on to the next IF. The last IF, goes into the ELSE: even though it's value is "/" When the Else is executed it jumps to my error routine which I haven't coded and therefore I don't know what the error is.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ... Mid(fName, fposn, 1) = Mid(flname, i)
Are you trying to load multiple characters into one character here? I'm not sure but I believe you might need to rethink this command.
No, I've just tried a number of different ways of coding this command I originally had Mid(flname,i,1).
Last edited by VBWayne; Aug 16th, 2006 at 4:46 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Using Mid function and/or statement in IF

 
0
  #4
Aug 16th, 2006
Try using msgbox's at the critical portions of the code to determine that the values are right. The reason I say this, is because it's been my experience that VB's IDE doesn't do a very good job of changing variable values in the IDE. So, for example, you could do this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ublic Function Getareaname(flname As String) As String
  2. Dim fposn As Long, i As Integer
  3. Dim fName As String
  4. Dim tmpname As String
  5. fName = "d:\getarea"
  6. fposn = 11
  7. msgbox "starting loop"
  8. For i = 1 To Len(flname)
  9. msgbox "at first if"
  10. If Mid(flname, i, 2) = "//" Then GoTo skipnext
  11. msgbox "value is: " & mid(flname, i, 2)
  12. If Mid(flname, i, 2) = "u:" Then GoTo skiplev
  13. If Mid(flname, i, 1) = "/" Then Mid(fName, fposn, 1) = "\" Else: Mid(fName, fposn, 1) = Mid(flname, i)
  14. fposn = fposn + 1
  15. skipnext:
  16. msgbox "at skip next"
  17. Next i
  18. Getareaname = fName
You can add and remove msgbox's as necessary to help trace variables through your code, and figure out where it's going wrong. If you could attach a copy of the file you are passing to this function (or an example of it) then I can try to trace it myself, but since I don't know the layout inside of the file, it makes testing your function a little more difficult.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 5
Reputation: VBWayne is an unknown quantity at this point 
Solved Threads: 0
VBWayne VBWayne is offline Offline
Newbie Poster

Re: Using Mid function and/or statement in IF

 
0
  #5
Aug 16th, 2006
I'm on my way to success. Thank you! My big problem that stopped my code from running was with this statement.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. fName = "d:\getarea"

This defined the length of fName as 10 and I was trying to write to position 11 on.

I still don't know why the IF statements aren't working, but I gotta go now. I'll update you in the morning.

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC