| | |
Using Mid function and/or statement in IF
![]() |
•
•
Join Date: Aug 2006
Posts: 5
Reputation:
Solved Threads: 0
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:
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)
Public Function Getareaname(flname As String) As String Dim fposn As Long, i As Integer Dim fName As String Dim tmpname As String fName = "d:\getarea" fposn = 11 For i = 1 To Len(flname) If Mid(flname, i, 2) = "//" Then GoTo skipnext If Mid(flname, i, 2) = "u:" Then GoTo skiplev If Mid(flname, i, 1) = "/" Then Mid(fName, fposn, 1) = "\" Else: Mid(fName, fposn, 1) = Mid(flname, i) fposn = fposn + 1 skipnext: Next i Getareaname = fName
Last edited by Comatose; Aug 16th, 2006 at 5:49 pm.
•
•
•
•
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
... Mid(fName, fposn, 1) = Mid(flname, i)
•
•
Join Date: Aug 2006
Posts: 5
Reputation:
Solved Threads: 0
Thank you for responding.
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.
No, I've just tried a number of different ways of coding this command I originally had Mid(flname,i,1).
•
•
•
•
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?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
... 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.
Last edited by VBWayne; Aug 16th, 2006 at 4:46 pm.
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:
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
ublic Function Getareaname(flname As String) As String Dim fposn As Long, i As Integer Dim fName As String Dim tmpname As String fName = "d:\getarea" fposn = 11 msgbox "starting loop" For i = 1 To Len(flname) msgbox "at first if" If Mid(flname, i, 2) = "//" Then GoTo skipnext msgbox "value is: " & mid(flname, i, 2) If Mid(flname, i, 2) = "u:" Then GoTo skiplev If Mid(flname, i, 1) = "/" Then Mid(fName, fposn, 1) = "\" Else: Mid(fName, fposn, 1) = Mid(flname, i) fposn = fposn + 1 skipnext: msgbox "at skip next" Next i Getareaname = fName
•
•
Join Date: Aug 2006
Posts: 5
Reputation:
Solved Threads: 0
I'm on my way to success. Thank you! My big problem that stopped my code from running was with this statement.
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- writing my own MID FUNCTION (Visual Basic 4 / 5 / 6)
- How can I create a user defined function (MS SQL)
- loop in main function to an "if" statement (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: help needed to show Excel graphs (only) in VB window
- Next Thread: Input without a form for DLL
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






