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

    Question [ASK]Read and Separate

    hi vbforumers.....
    now i have problem

    i have list of number on teksbox like this:
    45.65.667.54.222.4444.9876.20.999.8765.7654.10.90.21
    and my question is, how to separate the numbers that I have a set of numbers based on numbers like this??


    or view my attachments


    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [ASK]Read and Separate

    This would give you a good start :

    Code:
    Private Sub Command1_Click()
    Dim TextArr() As String
    TextArr = Split(Text1.Text, ".")
    
    Dim i As Integer
    Dim ArrCount As Integer
    ArrCount = UBound(TextArr)
    For i = 0 To ArrCount - 1
    List1.AddItem (TextArr(i))
    Next
    
    End Sub
    It separates all the numbers, and adds them to a listbox.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Talking Re: [ASK]Read and Separate

    OK, you have softened my heart....

    Here is all the numbers organised into 3 separate listboxes :

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim TextArr() As String
    TextArr = Split(Text1.Text, ".")
    
    Dim i As Integer
    Dim ArrCount As Integer
    ArrCount = UBound(TextArr)
    For i = 0 To ArrCount - 1
    If Len(TextArr(i)) = 2 Then
    List1.AddItem (TextArr(i))
    ElseIf Len(TextArr(i)) = 3 Then
    List2.AddItem (TextArr(i))
    ElseIf Len(TextArr(i)) = 4 Then
    List3.AddItem (TextArr(i))
    End If
    
    Next
    
    End Sub
    To count the items I have used Len.

    I am attaching a sample for you because I am such a nice guy today
    Attached Files Attached Files

  4. #4
    Join Date
    May 2009
    Posts
    4

    Question Re: [ASK]Read and Separate

    Quote Originally Posted by HanneSThEGreaT View Post
    OK, you have softened my heart....

    Here is all the numbers organised into 3 separate listboxes :

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim TextArr() As String
    TextArr = Split(Text1.Text, ".")
    
    Dim i As Integer
    Dim ArrCount As Integer
    ArrCount = UBound(TextArr)
    For i = 0 To ArrCount - 1
    If Len(TextArr(i)) = 2 Then
    List1.AddItem (TextArr(i))
    ElseIf Len(TextArr(i)) = 3 Then
    List2.AddItem (TextArr(i))
    ElseIf Len(TextArr(i)) = 4 Then
    List3.AddItem (TextArr(i))
    End If
    
    Next
    
    End Sub
    To count the items I have used Len.

    I am attaching a sample for you because I am such a nice guy today

    thanks HanneSThEGreaT...
    but now i have new case....
    can u tell me how to read and split the number then read number or digit after cross symbol

    from data like this??
    Code:
    45.65.667.54.222.4444.9876.20.999.8765.7654.10.90.21x325
    and this sample output for my problem

    Attached Images Attached Images  

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

    Re: [ASK]Read and Separate

    InStr$() will search within a string, for any patter you want.

    Code:
    Option Explicit
    
    Dim strBuff As String
    Dim str() As String
    
    Private Sub Command1_Click()
      Dim x As Long, st As String
      x = Search(Text2.Text, Text1.Text)
      If x > 0 Then
        MsgBox "Found and deleted. Score= " & x
      Else
        MsgBox "Not found..."
      End If
      For x = 0 To UBound(str)
        st = st & str(x) & vbCrLf
      Next x
      MsgBox st
    End Sub
    
    Private Sub Form_Load()
      Dim x As Integer
      Dim ff As Integer
      Text1.Text = App.Path & "\scores.txt"
      Text2.Text = "David"
      ff = FreeFile
      Open Text1.Text For Input As #ff
        strBuff = Input(LOF(ff), ff)
      Close #ff
      str() = Split(strBuff, vbCrLf)
    End Sub
    
    Function Search(n As String, f As String) As Integer
      ' This finds a person's score, and removes the line
      ' it rewrites the file
      Dim x As Integer, out As String, ff As Integer
      Dim num As Long
      For x = 0 To UBound(str)
        If InStr(str(x), n) > 0 Then
          n = InStr(str(x), "=") + 1
          num = Val(Mid(str(x), n, Len(str(x)) - n + 1))
        Else
          out = out & str(x) & vbCrLf
        End If
      Next x
      ff = FreeFile
      Open f For Output As #ff
        Print #ff, out
      Close #ff
      str() = Split(out, vbCrLf)
      Search = num
    End Function
    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!

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: [ASK]Read and Separate

    Code:
      dim px%
      px = InStrRev(SourceString, "x")
      If px Then DigitsAfterX = Mid$(SourceString, px + 1)

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