I use label and the caption is "1234 - 345 - 1242 - 001" .I have four textbox, How I can fill it in the textbox just one click button using command button
Printable View
I use label and the caption is "1234 - 345 - 1242 - 001" .I have four textbox, How I can fill it in the textbox just one click button using command button
You want each number in its own textbox? If so, use the Split() function along with some trimming. Following assumes you have indexed/array of textboxes.
Code:Dim sData() As String, I As Integer
sData=Split(Label1.Caption, "-")
' may want to add a line of code to ensure UBound(sDAta)=>3 else caption wasn't formatted right
For I=0 To 3
Text1(I).Text = Trim$(sData(I))
Next
Look into the "Split" function:
[EDIT] LaVolpe, fast on the draw. :)Code:Dim sString As String, sSplit() As String, lCount As Long
sString = "1234 - 345 - 1242 - 001"
sSplit = Split(sString, " - ")
For lCount = LBound(sSplit) To UBound(sSplit)
Debug.Print sSplit(lCount)
Next lCount
If the numbers are all seperated with the 'dash' then you can split the string.
Use the InStr Function
I haven't tested this, but if it's wrong, it should point you in the right direction.Code:Dim lngPos As Long
Dim strTmp As String
Dim strInput As String
strInput = "123 - 456 - 789)
'find first - seperator
lngPos = InStr(strInput, "-")
'add the first part to the textbox
Text1.Text = Left$(strInput, lngPos - 1)
'place the remainder of the original string into temporary string for next search
strTmp = Mid$(strInput, lngPos + 1)
'find next empty space
lngPos = InStr(strTmp, "-")
'add the middle part of string to the second text box
Text2.Text = Mid$(strTmp, lngPos - 1)
'now add what is left to the third textbox
Text3.Text = Mid$(strTmp, lngPos + 1)
If not post back ;)
Boy am I slow, and the long way round as well :lol: