|
-
September 18th, 2001, 09:56 AM
#1
IF
Can anyone tell me why this does not work? When I step through it, it skips the intIDLen = 7 and goes to the intIDLen = 9 no matter what.
Thanks, Pat
If Left(cmbSite.Text, 7) < 8 Then
intIDLen = 7
ElseIf Left(cmbSite.Text, 9) > 8 Then
intIDLen = 9
End If
-
September 18th, 2001, 10:05 AM
#2
Re: IF
It seems you're missing Len(Left(...))!
-
September 18th, 2001, 10:22 AM
#3
Re: IF
I put the Len in, but it's still missing. I think what the problem is is that it is reading the seven digits of the 7 digit code, returning that, and then only reading the first seven of the nine digit code? But I don't know. And if that is the case, I'm not sure how to fix it.
Thanks
If Len(Left(cmbSite.Text, 9) = 9) Then
intIDLen = 9
ElseIf Len(Left(cmbSite.Text, 7) = 7) Then
intIDLen = 7
End If
-
September 18th, 2001, 10:25 AM
#4
Re: IF
If you compare the lenght of the string than it will not work because you take the left 7 chars
In case you need the value the mistake is that
You compare string with number. Chhange the code to the following
If CInt(Left(cmbSite.Text, 7)) < 8 Then
intIDLen = 7
ElseIf CInt(Left(cmbSite.Text, 9)) > 8 Then
intIDLen = 9
End If
Iouri Boutchkine
[email protected]
-
September 18th, 2001, 10:53 AM
#5
Re: IF
The code should be:
If len(Left(cmbSite.Text, 9)) = 9 then
intIDLen = 9
ElseIf len(Left(cmbSite.Text, 7)) = 7 then
intIDLen = 7
End If
-
September 18th, 2001, 10:54 AM
#6
Re: IF
Ok, I understand what you are saying here, but there is one more thing that I forgot to mention. The first two digits are not numeric. They are either IT or GP, followed by either 5 or 7 numeric numbers.
-
September 18th, 2001, 11:01 AM
#7
Re: IF
What are you exactly trying to do? Are you interested in lenght of string, in lenght of numeric part of string, in numeric value of a part of your string or what?
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
September 18th, 2001, 11:17 AM
#8
-
September 18th, 2001, 02:53 PM
#9
Re: IF
Extract numeric part of the string using mid or right function
right(left(YourString,7),2)
Iouri Boutchkine
[email protected]
-
September 19th, 2001, 02:00 AM
#10
Re: IF
'have not read all the answers, so do not know if someone else already told you
'this:
'If it is a fixed lenght string, you can use mid$ function to extract the whole
'number. If it is not fixed lenght, you can use mid$ function to extrat one
'char at a time and see if it is numeric. It may be a little slow for long
'strings.
'Example of last:
'(one textbox, one commandbutton)
private Sub Command1_Click()
Dim charToTest as string
Dim totalNumber as string
Dim i as Integer
If len(Text1.Text) > 0 then
for i = 1 to len(Text1.Text)
charToTest = mid$(Text1.Text, i, 1)
If IsNumeric(charToTest) then
totalNumber = totalNumber & charToTest
End If
next i
MsgBox totalNumber
End If
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|