How do I use Left, Right and Mid Functions?
-
I am very new to Visual Basic 6, so forgive me if this is not the appropriate forum for this question. I am building a form that has a text box that will hold hexadecimal data. I want to be able to take this data and display it seperate boxes of 2 characters. I know this can be done using Left(textName, 2) and also Mid(textName, 3, 2) but I can't seem to make it work. Example: Text Box with this data: 22AB3F3202 That would yield text boxes with this: 22 AB 3F 32 02 I hope I made what I need clear and that someone can help me. Thank you!
-
I am very new to Visual Basic 6, so forgive me if this is not the appropriate forum for this question. I am building a form that has a text box that will hold hexadecimal data. I want to be able to take this data and display it seperate boxes of 2 characters. I know this can be done using Left(textName, 2) and also Mid(textName, 3, 2) but I can't seem to make it work. Example: Text Box with this data: 22AB3F3202 That would yield text boxes with this: 22 AB 3F 32 02 I hope I made what I need clear and that someone can help me. Thank you!
While there are a number of different ways you can do this, here is just a quick example:
Dim str, buff As String
str = Me.TextBox1.Text
Do While Len(str)
buff = Left(str, 2)
ListBox1.AddItem (buff)
str = Right(str, Len(str) - 2)
LoopYou can obviously remove the listbox instruction, this is only an example. Hope this helps. :) -Nick Parker
-
I am very new to Visual Basic 6, so forgive me if this is not the appropriate forum for this question. I am building a form that has a text box that will hold hexadecimal data. I want to be able to take this data and display it seperate boxes of 2 characters. I know this can be done using Left(textName, 2) and also Mid(textName, 3, 2) but I can't seem to make it work. Example: Text Box with this data: 22AB3F3202 That would yield text boxes with this: 22 AB 3F 32 02 I hope I made what I need clear and that someone can help me. Thank you!
plz post some code so we can help :)
-
plz post some code so we can help :)
I finally got it to work using the following code. It's probably not the most efficient code, so if there is a better way, please let me know. Private Sub txtCMD_Change() Dim Length As String Dim Hash As String Dim Code2 As String Dim Code3 As String Dim Code4 As String Dim Code5 As String Dim Code6 As String Dim Code7 As String Dim Code8 As String Dim Code9 As String Dim Code10 As String Dim Code11 As String Dim Code12 As String Dim Code13 As String Dim Code14 As String Dim Code15 As String Dim Code16 As String Dim Code17 As String Dim Code18 As String Dim Code19 As String Dim Code20 As String Dim Code21 As String Dim Code22 As String Dim Code23 As String Dim Code24 As String Dim Code25 As String Dim Code26 As String Dim Code27 As String Dim Code28 As String Dim Code29 As String Dim Code30 As String Dim Code31 As String Dim Code32 As String Dim Code33 As String Dim Code34 As String Dim Code35 As String Dim Code36 As String Dim Code37 As String Dim Code38 As String Dim Code39 As String Dim Code40 As String Dim Code41 As String Dim Code42 As String Dim Code43 As String Dim Code44 As String Dim Code45 As String Dim Code46 As String Dim Code47 As String Dim Code48 As String Dim Code49 As String Length = txtCMDLength.Text Hash = txtHashRange.Text Code2 = Hex2.Text Code3 = Hex3.Text Code4 = Hex4.Text Code5 = Hex5.Text Code6 = Hex6.Text Code7 = Hex7.Text Code8 = Hex8.Text Code9 = Hex9.Text Code10 = Hex10.Text Code11 = Hex11.Text Code12 = Hex12.Text Code13 = Hex13.Text Code14 = Hex14.Text Code15 = Hex15.Text Code16 = Hex16.Text Code17 = Hex17.Text Code18 = Hex18.Text Code19 = Hex19.Text Code20 = Hex20.Text Code21 = Hex21.Text Code22 = Hex22.Text Code23 = Hex23.Text Code24 = Hex24.Text Code25 = Hex25.Text Code26 = Hex26.Text Code27 = Hex27.Text Code28 = Hex28.Text Code29 = Hex29.Text Code30 = Hex30.Text Code31 = Hex31.Text Code32 = Hex32.Text Code33 = Hex33.Text Code34 = Hex34.Text Code35 = Hex35.Text Code36 = Hex36.Text Code37 = Hex37.Text Code38 = Hex38.Text Code39 = Hex39.Text Code40 = Hex40.Text Code41 = Hex41.Text Code42 = Hex42.Text Code43 = Hex43.Text Code44 = Hex44.Text Code45 = Hex45.Text Code46 = Hex46.Text Code47 = Hex47.Text Code48 = Hex48.Text Code49 = Hex49.Text Length = UCase(Mid(txtCMD,
-
I finally got it to work using the following code. It's probably not the most efficient code, so if there is a better way, please let me know. Private Sub txtCMD_Change() Dim Length As String Dim Hash As String Dim Code2 As String Dim Code3 As String Dim Code4 As String Dim Code5 As String Dim Code6 As String Dim Code7 As String Dim Code8 As String Dim Code9 As String Dim Code10 As String Dim Code11 As String Dim Code12 As String Dim Code13 As String Dim Code14 As String Dim Code15 As String Dim Code16 As String Dim Code17 As String Dim Code18 As String Dim Code19 As String Dim Code20 As String Dim Code21 As String Dim Code22 As String Dim Code23 As String Dim Code24 As String Dim Code25 As String Dim Code26 As String Dim Code27 As String Dim Code28 As String Dim Code29 As String Dim Code30 As String Dim Code31 As String Dim Code32 As String Dim Code33 As String Dim Code34 As String Dim Code35 As String Dim Code36 As String Dim Code37 As String Dim Code38 As String Dim Code39 As String Dim Code40 As String Dim Code41 As String Dim Code42 As String Dim Code43 As String Dim Code44 As String Dim Code45 As String Dim Code46 As String Dim Code47 As String Dim Code48 As String Dim Code49 As String Length = txtCMDLength.Text Hash = txtHashRange.Text Code2 = Hex2.Text Code3 = Hex3.Text Code4 = Hex4.Text Code5 = Hex5.Text Code6 = Hex6.Text Code7 = Hex7.Text Code8 = Hex8.Text Code9 = Hex9.Text Code10 = Hex10.Text Code11 = Hex11.Text Code12 = Hex12.Text Code13 = Hex13.Text Code14 = Hex14.Text Code15 = Hex15.Text Code16 = Hex16.Text Code17 = Hex17.Text Code18 = Hex18.Text Code19 = Hex19.Text Code20 = Hex20.Text Code21 = Hex21.Text Code22 = Hex22.Text Code23 = Hex23.Text Code24 = Hex24.Text Code25 = Hex25.Text Code26 = Hex26.Text Code27 = Hex27.Text Code28 = Hex28.Text Code29 = Hex29.Text Code30 = Hex30.Text Code31 = Hex31.Text Code32 = Hex32.Text Code33 = Hex33.Text Code34 = Hex34.Text Code35 = Hex35.Text Code36 = Hex36.Text Code37 = Hex37.Text Code38 = Hex38.Text Code39 = Hex39.Text Code40 = Hex40.Text Code41 = Hex41.Text Code42 = Hex42.Text Code43 = Hex43.Text Code44 = Hex44.Text Code45 = Hex45.Text Code46 = Hex46.Text Code47 = Hex47.Text Code48 = Hex48.Text Code49 = Hex49.Text Length = UCase(Mid(txtCMD,
you could cut down with the string , also you could make an array of your textboxes , then you could use something like this : Vb6:
Private Sub Command1_Click()
Dim code(2 To 49) As String, x As Long
Dim txthx(2 To 49) As String
Dim tb As TextBoxFor x = 2 To 49
For Each tb In Controls
If tb.Name = txthx(x) Then
tb.Text = code(x)
End If
Next
NextEnd Sub
that would cut out a lot of code :) Vb:
Public Function TwinsOnWay(ByVal twins As String) As String
Select Case twins
Case "Gender"
Return "Two Girls"
End Select
End Function
-
you could cut down with the string , also you could make an array of your textboxes , then you could use something like this : Vb6:
Private Sub Command1_Click()
Dim code(2 To 49) As String, x As Long
Dim txthx(2 To 49) As String
Dim tb As TextBoxFor x = 2 To 49
For Each tb In Controls
If tb.Name = txthx(x) Then
tb.Text = code(x)
End If
Next
NextEnd Sub
that would cut out a lot of code :) Vb:
Public Function TwinsOnWay(ByVal twins As String) As String
Select Case twins
Case "Gender"
Return "Two Girls"
End Select
End Function