Results 1 to 15 of 15

Thread: Filter Textbox?

  1. #1

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Filter Textbox?

    i have a multilined textbox filled with about 10 digit numbers in a list

    how would i filter so that it will only show the numbers that start with say 94.65



    cheers william
    Nothing is Impossible you say?......Try slamming a revolving door!

  2. #2

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Filter Textbox?

    forgot to mention id like to have a few filters e.g

    94.65
    80.65
    96.26

    remember there are another 6 digits after they numbers which are pretty random.
    Nothing is Impossible you say?......Try slamming a revolving door!

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Filter Textbox?

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim MyArr() As String
    3.     Dim i As Integer, StrBuff As String
    4.         ReDim Preserve MyArr(4)
    5.             MyArr(1) = "10"
    6.             MyArr(2) = "153"
    7.             MyArr(3) = "162"
    8.             MyArr(4) = "142"
    9.    For i = 1 To 4
    10.     StrBuff = StrBuff & Mid(Text1.Text, i, 1)
    11.     Next
    12.     For i = 0 To UBound(MyArr)
    13.         If MyArr(i) = StrBuff Then MsgBox MyArr(i)
    14.     Next i
    15. End Sub
    It will filter good

  4. #4

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Filter Textbox?

    Thanks a bunch ill try it as soon as i get home
    Nothing is Impossible you say?......Try slamming a revolving door!

  5. #5

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Filter Textbox?

    do i click that command button before or after i have numbers in the text box :S
    Nothing is Impossible you say?......Try slamming a revolving door!

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Filter Textbox?

    After, but I have my doubts that this is what you wanted. Try it and post back.

  7. #7

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Filter Textbox?

    not working :/

    anyone else got any ideas?
    Nothing is Impossible you say?......Try slamming a revolving door!

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Filter Textbox?

    Not clear where you're getting the filter, but this will do what you need.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.   Dim arr() As String
    5.   Dim x As Integer
    6.   Dim str As String
    7.   Dim test As String
    8.   arr() = Split(Text1.Text, vbCrLf)
    9.   For x = 0 To UBound(arr)
    10.     test = Left(Format(Val(arr(x)), "##.###"), 5)
    11.     If Text2.Text = test Then
    12.         str = Text2.Text & vbCrLf
    13.     End If
    14.   Next x
    15.   MsgBox str
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.  Text1.Text = "94.1253454345" & vbCrLf & "94.55534534" & vbCrLf & _
    20.       "96.234345345" & vbCrLf & "66.252345345" & vbCrLf & "33.555345345"
    21.  Text2.Text = ""
    22. End Sub

    Just type your filter into text2, and press the button. All matching records will be in a msgbox.
    Last edited by dglienna; Jul 18th, 2005 at 07:10 PM.

  9. #9

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Filter Textbox?

    Thats looking good so far but in the msgbox its only show what i typed, as in i still need the last 6 digits to show, so something like that but when i type in 33.55 id like the msgboz to say 33.555345345 instead of just 33.55

    Thanks for the time
    Nothing is Impossible you say?......Try slamming a revolving door!

  10. #10
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Filter Textbox?

    sorry dg......i tried this just to check what exactly u wanted this code to do but i m getting empty msgbox.....

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Filter Textbox?

    Hey, glad I didn't destroy them.
    Just change the output variable.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.   Dim arr() As String
    5.   Dim x As Integer
    6.   Dim str As String
    7.   Dim test As String
    8.   arr() = Split(Text1.Text, vbCrLf)
    9.   For x = 0 To UBound(arr)
    10.     test = Left(Format(Val(arr(x)), "##.###"), 5)
    11.     If Text2.Text = test Then
    12.         str = str & arr(x)  & vbCrLf ' <--------------- This line changed
    13.     End If
    14.   Next x
    15.   MsgBox str
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.  Text1.Text = "94.1253454345" & vbCrLf & "94.55534534" & vbCrLf & _
    20.       "96.234345345" & vbCrLf & "66.252345345" & vbCrLf & "33.555345345"
    21.  Text2.Text = ""
    22. End Sub

  12. #12

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Filter Textbox?

    yeah man im getting an empty msgbox aswell now :/
    Nothing is Impossible you say?......Try slamming a revolving door!

  13. #13
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Filter Textbox?

    I dont get why my code wont work? Mine compares the first 4 numbers with the numbers in MyArr() so i dont see whats wrong there

  14. #14

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Filter Textbox?

    em it just showed me what i typed in :/

    But problem solved i just had to tweak the number of digits after the filter

    Cheers guys
    Nothing is Impossible you say?......Try slamming a revolving door!

  15. #15
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Filter Textbox?

    Here is a slight change to the routine that helps with variable number of digits
    VB Code:
    1. Private Sub Command1_Click()
    2.   Dim arr() As String
    3.   Dim x As Integer
    4.   Dim str As String
    5.   Dim test As String
    6.   Dim isMatch As Boolean
    7.   If Text2 = "" Then
    8.     MsgBox "Enter a number in Text Box 2 first"
    9.     Exit Sub
    10.   End If
    11.   arr() = Split(Text1.Text, vbCrLf)
    12.   For x = 0 To UBound(arr)
    13.     test = Left(arr(x), Len(Text2))
    14.     If Text2.Text = test Then
    15.         MsgBox "Match: " & arr(x)
    16.         isMatch = True
    17.     End If
    18.   Next x
    19.     If Not isMatch Then MsgBox "No Match Found"
    20. End Sub

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