please whats d code i should put when requesting for a user to enter text on vb 2008

Recommended Answers

All 3 Replies

Pass more info on ur objective...

Explain further

Hi daniells,

I assume you want a textbox that only accepts letters and not numbers.

Here is how to do it:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim YOURVARIABLE As String = "0123456789"
        If InStr(YOURVARIABLE, e.KeyChar.ToString) = 0 Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

In this code, you declare yourvariable and assign the values with numbers. After that, I use InStr() function to compare yourvariable and the keys pressed. Now if the keys that are pressed, we execute e.Handled = True, meaning we will not display the pressed key which is equal to yourvariable... Hope this helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.