944,078 Members | Top Members by Rank

Ad:
Aug 16th, 2006
0

Using Mid function and/or statement in IF

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
VBWayne is offline Offline
5 posts
since Aug 2006
Aug 16th, 2006
0

Re: Using Mid function and/or statement in IF

Quote 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.
Moderator
Reputation Points: 3281
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Aug 16th, 2006
0

Re: Using Mid function and/or statement in IF

Thank you for responding.

Quote 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)
Quote ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
VBWayne is offline Offline
5 posts
since Aug 2006
Aug 16th, 2006
0

Re: Using Mid function and/or statement in IF

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 16th, 2006
0

Re: Using Mid function and/or statement in IF

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
VBWayne is offline Offline
5 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: help needed to show Excel graphs (only) in VB window
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Input without a form for DLL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC