Please help new at this.

wrangler

New member
Joined
Oct 18, 2004
Messages
4
Programming Experience
Beginner
I am trying to get a loop to check if the correck number of charracters are present. This is homework and I can not figure it out. Below is the assignment. The only part I can not do is the first check. Can anyone help...

I can not figure out how to get a loop to work that checks to see that the input in textbox1 = 12. If the input does not = 12 charracters, a messege box pops up and the textbox is reset.
So far I can check the value using lenght, get the message to post, and clear the input in textbox but that is were it gets stuck. Once I click the "OK" button on the msgbox, it pops back up I have to get the loop to wait until you type new text before it checks the value again.

I have to make it so the msgbox pops up and once you click ok you return to the inputting int textbox1. My teacher said to use the control.focus() but I am lost. once the length value of textbox = 12 you exit loop and continue with program.



Homework: Below it is were I need help...
Design and develop a program that validates the value a user enters into a TextBox control to ensure that the entry is a valid telephone number. The application should accept a maximum of 12 characters. When the user clicks a button, the program should determine if the entry is of the form 999-999-9999, where the character 9 represents any number.
If the entry is determined to be a telephone number, display an appropriate message, along with the separate substrings that compose the telephone number without the dashes. If the entry is not a telephone number, then display a message as to the reason why the entry is not a valid telephone number, clear the TextBox control and set focus to the TextBox control. Use String class methods to solve the problem.
Here are a few hints to help you code the String methods:

1. Check that the user has entered two dashes in the appropriate spaces.
2. Break the string into 3 substrings, represented as 999,999, and 9999.

Use the Visual Basic .NET IsNumeric() function to determine whether each substring is a valid number. The function accepts one parameter and returns a True or False value.
Here is some information about the IsNumeric function:
http://msdn.microsoft.com/library/d...ctisnumeric.asp


Tips for Unit 3 IP (ITP330)

• New key ideas of this assignment include:
o String variables
o Substring and Length() methods. See pp. 319-320
o MsgBox(), see text p.72, p.136, and p.159
o Focus():
 syntax: control.Focus() , where control is the name of a control that will receive focus during run time.
 Example: cmbCreditRating.Focus()
The cmbCreditRating control receives focus when the above statement is executed
o IsNumeric() as explained in the assignment
o IsNumeric does not filter dash "-", comma "," or decimal point "." characters so your program must use IndexOf to filter for these characters in your substrings

• Logic:
o There are many ways to give user feedback on the correctness of the input. Some are more user friendly than others. However, it may require a lot of coding to account for various situations.
o The simple way is the following:
First check the length of the input string: it must be exactly 12. everything but this works fine.
 Then check for Substring(3, 1) and Substring(7, 1),i.e. the fourth and eighth character must be “-“
 Use the Substring method to separate the input string into 3 parts
 Check to see if each part is only numeric characters, using IsNumeric and IndexOf.
 If error, display error message box.
o You don’t have to use loops (you can if you want to), but you have to use the if-then-else statement

this is where I am not,

phone = TextBox1.Text
lphone = phone.Length

Do
TextBox1.ResetText()
TextBox1.Focus()
If lphone <> 12 Then MsgBox("Incorrect number of digits")


Loop Until lphone = 12
 

wrangler

New member
Joined
Oct 18, 2004
Messages
4
Programming Experience
Beginner
this is what i used



[font=verdana, arial, helvetica]this is what I used, does all he asked for; day ; day late though. Thanks for all your help

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
phone = TextBox1.Text
lphone = phone.Length

phone = TextBox1.Text
lphone = phone.Length

Do
TextBox1.Text = String.Empty
TextBox1.Focus()
If lphone <> 12 Then
MsgBox("Incorrect number of digits")
TextBox1.Text = ""
TextBox1.Focus()
Exit Sub
End If
Loop Until lphone = 12

acode = phone.Substring(0, 3)
pref = phone.Substring(4, 3)
last4 = phone.Substring(8, 4)
Label1.Text = (acode)
Label2.Text = (pref)
Label3.Text = (last4)

Do
fash = phone.Substring(3, 1)
sash = phone.Substring(7, 1)
If fash <> "-" Or sash <> "-" Then
MsgBox("Use only number, and '-'. input data in XXX-XXX-XXXX format")
TextBox1.Text = ""
TextBox1.Focus()
Exit Sub
End If
Loop Until fash = "-" And sash = "-"

Do
vacode = IsNumeric(acode)
vpref = IsNumeric(pref)
vlast4 = IsNumeric(last4)
If vacode = False Or vpref = False Or vlast4 = False Then
MsgBox("Use only number, and '-'. input data in XXX-XXX-XXXX format")
TextBox1.Text = ""
TextBox1.Focus()
Exit Sub
End If
Loop Until vacode = True And vpref = True And vlast4 = True

fash = phone.Substring(3, 1)
sash = phone.Substring(7, 1)


End Sub
[/font]
 
Top Bottom