Click to See Complete Forum and Search --> : IF
Pat S
September 18th, 2001, 09:56 AM
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
MKSa
September 18th, 2001, 10:05 AM
It seems you're missing Len(Left(...))!
Pat S
September 18th, 2001, 10:22 AM
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
Iouri
September 18th, 2001, 10:25 AM
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
iouri@hotsheet.com
MKSa
September 18th, 2001, 10:53 AM
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
Pat S
September 18th, 2001, 10:54 AM
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.
Cimperiali
September 18th, 2001, 11:01 AM
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
Pat S
September 18th, 2001, 11:17 AM
Numeric part of string
Iouri
September 18th, 2001, 02:53 PM
Extract numeric part of the string using mid or right function
right(left(YourString,7),2)
Iouri Boutchkine
iouri@hotsheet.com
Cimperiali
September 19th, 2001, 02:00 AM
'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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.