Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating Data specific characters Help

Status
Not open for further replies.

digipad

Programmer
Jun 17, 2007
7
0
0
US
Hey Guys,

I'm trying to validate a data from Inputbox.
But it gets little complicated, because I dont know first of all how many characters data going to be , and it is not really important for the project.
WHat I need to validate is the first character of the data and the last character, for example

InputBox = " Hello World! "
Validate this box that if InputBox first character is "H" and last character is "!" then do something

else
please type correct format


Anybody can help me with this coding
 
Plese do not duplicate posts.

Assuming that you are talking about the inputbox function then try something like this:

Code:
Dim Test As String
Test = InputBox("Please enter some data that begins with a " & _
"""H""" & "and ends with a " & """!""", "Enter Data", " Hello World! ")
If Left$(Test, 1) = "H" And Right$(Test, 1) = "!" Then
    MsgBox "Data Valid!", vbInformation + vbOKOnly
Else
    MsgBox "Invalid data, please re-enter!", vbCritical + vbOKOnly
End If

If you are talking about a string called inputbox try this:

Code:
Dim InputBox As String
InputBox = " Hello World! "
If Left$(InputBox, 1) = "H" And Right$(InputBox, 1) = "!" Then
    MsgBox "Data Valid!", vbInformation + vbOKOnly
Else
    MsgBox "Invalid data, please re-enter!", vbCritical + vbOKOnly
End If

Also, you example will always return a negative result since you have spaces at the beginning and ending of your text.

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top