English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 questions, probably 2 simple answers!

1. Is there any way to validate what is entered into a text box, e.g. when a save button is pressed (i only want letters going into the text box, no symbols or numbers)

2. Is there any way to make the first letter of a text box entry validated so it has an uppercase first letter, and lowercase for every other letter.

Cheers

2007-02-20 10:16:38 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

reate a string like:

dim strFirstRow as string="qwertyuop"

it's 9 letters.. now generate a random number from 1 to 9 and then get that letter from your string

something like this

Dim strFirstRow As String = "qwertyuop"
Dim myRND As New Random

Dim iNum As Integer = myRND.Next(1, 9)
MsgBox(strFirstRow.Substring(i... 1))

2007-02-28 04:01:01 · answer #1 · answered by Freddy Krueger 3 · 1 0

To answer number 2, on the TextChanged event, add the following code

myTextBox.Text = myTextBox.Text.SubString(0, 1).ToUpper() +
myTextBox.Text.SubString(1)
.ToLower();

That will give you a Capital first letter, and the rest in lower case

Thats a C# example but I think the VB one would be the same but without the ; at the end.

Hope that helps.

A

p.s Yahoo answers cut the code line short, had to seperate onto 3 lines. Its all meant to be on the same line.

2007-02-21 08:56:55 · answer #2 · answered by Andy D 2 · 0 0

You can use the KeyASCII value of the KeyPress event on the textbox - that's the way to do it in VB-6 anyway, not sure if VB 2005 has the same thing or not, but worth researching.

Use UCase(), and Left() functions -

Ucase(Left(txtSomeTextBox,1))

Again, that's using VB-6. It might not be the same for VB 2005.

2007-02-20 18:34:14 · answer #3 · answered by Richard H 7 · 0 0

yes,

1. by using keydown event and by morning key value you can avoid your text box to have anything else but letters.

for number 1

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If (e.KeyCode < 65 Or e.KeyCode > 90) Then
e.SuppressKeyPress = True
End If
End Sub


for 2nd more tricky ;-)

2007-02-20 19:01:06 · answer #4 · answered by Zlavzilla 3 · 0 0

fedest.com, questions and answers