Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operator Help

Status
Not open for further replies.

khansen97

Programmer
Oct 14, 2003
60
US
I have a complex if statement I need to make and I am not sure how to do it.

This is the data I have:

AN3345
AN1348
DP3457.

I need to insert a line when it changes from AN to something else.

I was doing a loop to check if carlineold = carlineold, but thats not going to work because as you can see they are not equal.

Then I thought about using the Left function to grab the 2 characters, however I have a problem that I have a couple of times where it will be three characters not jsut the two.

Any suggestions?
 
Is it always a group of letters followed by numbers and when the letters change is the trigger?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
This probably isn't the best way, but it should work if the leading identify letter characters are only 2 or 3 characters long AND the rest are simply numeric numbers.

Code:
    If Val(Mid(StringName, 3, 1)) <> 0 Then
    ' 3rd character of string IS number
    ' so grab first 2 letters
        tempString = Left(StringName, 2)
    
    Else
    ' 3rd character of string IS NOT number
    ' so grab first 3 letters
        tempString = Left(StringName, 3)
    End If

Essentially it grabs the 3rd character and see's if it's numeric or not. Anyway, I hope that gives you an idea.

 
Fherrera, what about AN[highlight]0[/highlight]345 ?
I'll guess something like this:
tempString = ""
For i = 1 To Len(StringName)
x = Mid(StringName, i, 1)
If IsNumeric(x) Then Exit For
tempString = tempString & x
Next i
 
That's a good point PHV...oi... Nevermind then :D

I guess similar to yours, replacing this line:
Code:
If Val(Mid(StringName, 3, 1)) <> 0 Then

with this:

Code:
If IsNumeric(Mid(StringName, 3, 1)) Then

Should do the trick, even with the 0...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top