|
-
May 15th, 2008, 01:43 PM
#1
Thread Starter
Member
Trim.length Help
Hi guys,
I'm using VS2005 and VB.NET for this program.
I'm trying to validate a textbox for a "State" so that the length is limited to two characters and they are both capitalized.
for ex: CA for California
any hints on how to do it using the Trim and Length methods?
I know there are probably some easier ways out there but I'm required to get it done this way for class.
Thank you
-
May 15th, 2008, 01:50 PM
#2
Re: Trim.length Help
Well, .Trim will strip leading and trailing spaces from the text. .Length will tell you how long the string is. And .ToUpper will make the string upper case.
-tg
-
May 15th, 2008, 01:55 PM
#3
Re: Trim.length Help
Look at the MaxLength property of the textbox, this property lets you limit the number of characters that can be typed into the box.
-
May 15th, 2008, 02:06 PM
#4
Re: Trim.length Help
nabilino, in this case it may be easier to consider using a combobox for this (set as a dropdownlist)
here's all 50 state's abbreviations:
Code:
New String() {"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"}
-
May 15th, 2008, 02:07 PM
#5
Re: Trim.length Help
Juggalo, maybe you missed his quote:
know there are probably some easier ways out there but I'm required to get it done this way for class.
-
May 15th, 2008, 02:07 PM
#6
Thread Starter
Member
Re: Trim.length Help
Ok! so what can I write to disable the user to input character other than letters? like if he puts in: "/S" it will generate an error...
-
May 15th, 2008, 02:12 PM
#7
Re: Trim.length Help
honestly there are about 100 ways to do this, so we would really need to know the specs of the project. Also being that this is homework, most people on this forum will be pretty reluctant to just provide fully working solutions to your homework
-
May 15th, 2008, 02:15 PM
#8
Re: Trim.length Help
 Originally Posted by kleinma
Juggalo, maybe you missed his quote:
Yes I did, sucks to be him
-
May 15th, 2008, 02:17 PM
#9
Thread Starter
Member
Re: Trim.length Help
I know...it's not really homework. it's an online lab and i'm not required to do it or graded for it. I just want to follow his rules to get the most out of it.
vb Code:
'Validate State TextBox
If Me.stateTextBox.Text = "" Then
e.Cancel = True
ErrorProvider1.SetError(stateTextBox, "State cannot be missing!")
Else
ErrorProvider1.SetError(stateTextBox, "")
End If
If Me.salesTextBox.Text IsNot "AA" Then
ErrorProvider1.SetError(stateTextBox, "State name has to be two letters!")
Else
ErrorProvider1.SetError(cityTextBox, "")
End If
-
May 15th, 2008, 02:25 PM
#10
Re: Trim.length Help
why does your second else statement reference cityTextBox?
Also I would be using if-elseif instead of multiple if-else-endif statements.
-
May 15th, 2008, 03:10 PM
#11
Re: Trim.length Help
Code:
'validate state
Dim theStates() As String = {"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"}
If Array.IndexOf(theStates, what goes here) = -1 Then
Stop
Else
Stop
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|