CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    3

    extracting numbers separated by commas >>help<<

    hello everyone

    i need ur help to do the following:

    i have a text box containing the following text 2,5,3,6,9,10,23,56

    notice that the numbers are separated by commas

    what i would like to do isto extract the numbers from that text box by order and place each one of them in a list box.


    i.e.

    2 should be placed in list1.list(0)
    5 should be placed in list1.list(1)

    ans so on...


    to better describe what i need i attached an image.


    thanks in advance
    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: extracting numbers separated by commas >>help<<

    Look up the split() function in your online help. This will allow you to parse the numbers out based on the seperator character into an array. There should be an example in the help file as well.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: extracting numbers separated by commas >>help<<

    Blast from the past! (except I had to search the forums, as I misplaced the sample's name...)
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim x As Integer, st As String
      Dim ff As Integer
      Dim strBuff As String
      Dim str() As String
      ff = FreeFile
      Open App.Path & "\to do.txt" For Input As #ff
        strBuff = Input(LOF(ff), ff)
      Close #ff
      ' ----------------- two ways to skin a cat --------------
      MsgBox "Lines = " & Len(strBuff) - Len(Replace(strBuff, vbCrLf, "x")) + 1
      ' -------------------------------------------------------
      str() = Split(strBuff, vbCrLf)
      MsgBox "There are " & UBound(str) + 1 & " lines in the file"
      For x = 0 To UBound(str)
        st = st & str(x) & vbCrLf & vbCrLf
      Next x
      MsgBox st
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Feb 2009
    Posts
    3

    Re: extracting numbers separated by commas >>help<<

    thanks for the help
    i really appreciate it.

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

Featured