Search Tools Links Login

Filter numbers or characters from sting


Filter a string and return numbers or characters

Original Author: Richard_W

Returns

only numbers or only characters and optional the filtered numbers and characters in textbox

Code

Public Function NumberOrNoNumber(StrToCheck As String, Numbers As Boolean, Optional NumericTextTarget As TextBox, Optional TextualTextTarget As TextBox)
'example:
'    txtFilter = NumberOrNoNumber(txtStringIncludingNumbers, False, txtNumber, txtNoNumber)
'    txtFilter = NumberOrNoNumber(txtStringIncludingNumbers, True)
Dim Nstr As String 'targetstring for al numbers
Dim Tstr As String 'targetstring for everything exept numbers
Dim i As Integer
  For i = 1 To Len(StrToCheck)
    If IsNumeric(Mid(StrToCheck, i, 1)) Then Nstr = Nstr & Mid(StrToCheck, i, 1) Else Tstr = Tstr & Mid(StrToCheck, i, 1)
  Next
If Numbers Then NumberOrNoNumber = Nstr Else NumberOrNoNumber = Tstr
On Error Resume Next
NumericTextTarget = Nstr 'optional target for the numbers filtered out
TextualTextTarget = Tstr 'optional target for the text filtered out
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 100 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.