|
-
Dec 21st, 2007, 10:12 AM
#1
Thread Starter
Frenzied Member
How to fill this text
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
-
Dec 21st, 2007, 10:22 AM
#2
Re: How to fill this text
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
-
Dec 21st, 2007, 10:22 AM
#3
Re: How to fill this text
Look into the "Split" function:
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
[EDIT] LaVolpe, fast on the draw.
-
Dec 21st, 2007, 10:26 AM
#4
Frenzied Member
Re: How to fill this text
If the numbers are all seperated with the 'dash' then you can split the string.
Use the InStr Function
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)
I haven't tested this, but if it's wrong, it should point you in the right direction.
If not post back
-
Dec 21st, 2007, 10:27 AM
#5
Frenzied Member
Re: How to fill this text
Boy am I slow, and the long way round as well
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|