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
:thumb:
cheers william
Printable View
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
:thumb:
cheers william
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.
It will filter good :wave:VB Code:
Private Sub Command1_Click() Dim MyArr() As String Dim i As Integer, StrBuff As String ReDim Preserve MyArr(4) MyArr(1) = "10" MyArr(2) = "153" MyArr(3) = "162" MyArr(4) = "142" For i = 1 To 4 StrBuff = StrBuff & Mid(Text1.Text, i, 1) Next For i = 0 To UBound(MyArr) If MyArr(i) = StrBuff Then MsgBox MyArr(i) Next i End Sub
Thanks a bunch ill try it as soon as i get home
do i click that command button before or after i have numbers in the text box :S
After, but I have my doubts that this is what you wanted. Try it and post back.
not working :/
anyone else got any ideas?
Not clear where you're getting the filter, but this will do what you need.
VB Code:
Option Explicit Private Sub Command1_Click() Dim arr() As String Dim x As Integer Dim str As String Dim test As String arr() = Split(Text1.Text, vbCrLf) For x = 0 To UBound(arr) test = Left(Format(Val(arr(x)), "##.###"), 5) If Text2.Text = test Then str = Text2.Text & vbCrLf End If Next x MsgBox str End Sub Private Sub Form_Load() Text1.Text = "94.1253454345" & vbCrLf & "94.55534534" & vbCrLf & _ "96.234345345" & vbCrLf & "66.252345345" & vbCrLf & "33.555345345" Text2.Text = "" End Sub
Just type your filter into text2, and press the button. All matching records will be in a msgbox.
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
sorry dg......i tried this just to check what exactly u wanted this code to do but i m getting empty msgbox.....
Hey, glad I didn't destroy them.
Just change the output variable.
VB Code:
Option Explicit Private Sub Command1_Click() Dim arr() As String Dim x As Integer Dim str As String Dim test As String arr() = Split(Text1.Text, vbCrLf) For x = 0 To UBound(arr) test = Left(Format(Val(arr(x)), "##.###"), 5) If Text2.Text = test Then str = str & arr(x) & vbCrLf ' <--------------- This line changed End If Next x MsgBox str End Sub Private Sub Form_Load() Text1.Text = "94.1253454345" & vbCrLf & "94.55534534" & vbCrLf & _ "96.234345345" & vbCrLf & "66.252345345" & vbCrLf & "33.555345345" Text2.Text = "" End Sub
yeah man im getting an empty msgbox aswell now :/
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
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
Here is a slight change to the routine that helps with variable number of digitsVB Code:
Private Sub Command1_Click() Dim arr() As String Dim x As Integer Dim str As String Dim test As String Dim isMatch As Boolean If Text2 = "" Then MsgBox "Enter a number in Text Box 2 first" Exit Sub End If arr() = Split(Text1.Text, vbCrLf) For x = 0 To UBound(arr) test = Left(arr(x), Len(Text2)) If Text2.Text = test Then MsgBox "Match: " & arr(x) isMatch = True End If Next x If Not isMatch Then MsgBox "No Match Found" End Sub