|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
need bad help pls
4) Make sure that only letters are entered into the name text boxes. Print an error message if this is not the case: “First Name and Last Name must only contain alpha characters”.
5) Make sure that only numbers are entered into the number1 and number2 text boxes. Print an error message if this is not the case: “Number1 and Number2 must contain only numerics”. 6) The Postal Code textbox should only accept 6 characters. 7) The Number1 textbox should only accept 2 characters. The Number2 textbox should only accept 1 character. 8) The info.asp script will display the following in the browser. (use a loop to print your name Number2 times, each name separated by 3 spaces) Your full name is: firstname lastname firstname lastname firstname lastname (print out names in lowercase letters) Your name was printed: Number2 times The last 3 characters of your Postal Code are: (print the result). The length of your first and last name is (print the result) characters. (print number1) x (print number2) = (print result) Your address (print address) has/does not have the letter E in it. Number 2 can represent: (print number2 followed by a decimal and two zeros. Include a dollar sign in front of number2). The random number (Print a random number between 1 and 10) multiplied by (print number 1) is: (print result) __________________________________________________ __ This is my task that i have to do.......so far i've gotten some of the codes but most of it still doesnt work.....please help me on this..i just started this course and its getting complicated....any kind person help me ![]() thanks |
|
#2
|
|||
|
|||
|
A crosspost is not necessary, and your subject line is not good.
|
|
#3
|
|||
|
|||
|
Hi there,
You have a number of problems to solve but I'll give you two ways to solve the problems of only letters or numbers in the text box. This first method requires that you declare two strings and then fill those strings with the numbers, or letters that you want to allow into each text box. Public ChkAlph As String Public ChkNum As String ChkAlph = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX YZ" ChkNum = "1234567890" Private Sub Text1_Keypress(KeyAscii As Integer) ' Assuming you want letters in this textbox Dim a As String, res As Variant a = Chr$(KeyAscii) res = InStr(ChkAlph, a) If res = 0 Then 'This is not a letter KeyAscii = 0 'Cancel the keypress Call MsgBox("You can only enter alphabetical characters into this textbox!", vbCritical, "Letters Only Please!") End If End Sub Private Sub Text2_Keypress(KeyAscii As Integer) ' Assuming you want numbers in this textbox Dim a As String, res As Variant a = Chr$(KeyAscii) res = InStr(ChkNum, a) If res = 0 Then 'This is not a number KeyAscii = 0 'Cancel the keypress Call MsgBox("You can only enter numerical characters into this textbox!", vbCritical, "Numbers OnlyPlease!") End If End Sub The other method requires much less coding because we'll use the value of the Keyascii variable directly, to match the Ascii value of the key pressed. Private Sub Text3_Keypress(KeyAscii As Integer) ' Assuming you want numbers in this textbox If ((KeyAscii > 64) And (KeyAscii < 91)) Or ((KeyAscii > 96) And (KeyAscii < 123)) Then 'This is a letter KeyAscii = 0 'Cancel the keypress Call MsgBox("You can only enter numerical characters into this textbox!", vbCritical, "Numbers Only Please!") End If End Sub Private Sub Text4_Keypress(KeyAscii As Integer) ' Assuming you want letters in this textbox If (KeyAscii > 47) And (KeyAscii < 58) Then 'This is a number KeyAscii = 0 'Cancel the keypress Call MsgBox("You can only enter alphabetical characters into this textbox!", vbCritical, "Letters Only Please!") End If End Sub Although the second method requires less coding, the first method is much more flexible and user friendly because you can format the string to contain all the characters you want just by typing them there. For instance, the string used for numerical values should probably contain a period, for decimal calculations, and the hyphen for negative values whereas the string for alphabetical values could probably contain at least a space, a comma and a period. Using the first method you would just type these extra characters into the string and it's done. In the second method you would have to find the ascii value of these extra characters and then change the 'If/Then' statement to include them. To set a maximum number of entries into a textbox just set the MaxLength property of the Textbox to your required length. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > need bad help pls |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|