Hi,
I hope I can explin this properly. To try and make it easier I have broken the code down into 3 routines. place 5 text boxes onto a new project. in text 1 put in 1234567abc, in text2 type abc1234567def and in text 3 type abc1234567
also put on 3 command buttons. command 1 will deal with text1, command2 will deal with text2 and command 3 will deal with text 3.
text4 will show the result. text 5 is used by the code to get the string of 7 numbers that you want. You will be able to create 1 routine from the 3 I have created.
the code in command 2 works if your string of 7 numbers starts at either the 2nd, 3rd or 4th charector from the left. if it is 6th, 7th 8th etc you will need to add more else's and if's but hopefully you can see that and work out how to do it.
the code is
Private Sub Command1_Click()
'''''''''''''''''''''''''''
'check to see if first digit is text or number
scan = Text1.Text
Text5.Text = Mid$(scan, 1, 1)
If IsNumeric(Text5.Text) Then
Text4.Text = Mid$(scan, 1, 7)
Else
'''''''''''''''''''''''
MsgBox ("not number")
End If
End Sub
Private Sub Command2_Click()
'finds numbers in middle
scan = Text2.Text
Text5.Text = Mid$(scan, 2, 1)
If IsNumeric(Text5.Text) Then
Text4.Text = Mid$(scan, 2, 7)
Else
Text5.Text = Mid$(scan, 3, 1)
If IsNumeric(Text5.Text) Then
Text4.Text = Mid$(scan, 3, 7)
Else
Text5.Text = Mid$(scan, 4, 1)
If IsNumeric(Text5.Text) Then
Text4.Text = Mid$(scan, 4, 7)
End If
End If
End If
End Sub
Private Sub Command3_Click()
'check to see if last number digit
Dim text_length As Integer
Dim target As String ' target is all of string minus 7
' get length of string
scan = Text3.Text
text_length = Len(Text3.Text)
target = text_length - 6
Text5.Text = Mid$(scan, target, 7)
If IsNumeric(Text5.Text) Then
Text4.Text = Text5.Text
Else
MsgBox ("not all numbers")
End If
End Sub