Results 1 to 5 of 5

Thread: How to fill this text

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    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

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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

  3. #3
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    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.

  4. #4
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    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
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: How to fill this text

    Boy am I slow, and the long way round as well
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width