I have made up a program, but i want to set some boxes to accept just text and some to just numbers, anyknow how i go about this please? i am newbie by the way
Nik
I have made up a program, but i want to set some boxes to accept just text and some to just numbers, anyknow how i go about this please? i am newbie by the way
Nik
web application? console application? windows application?
do you want to limit the input, as the keyboard is typed or when they try to leave the input area?
when you say just "text" do you mean alphabetic? or alphanumeric?
which language are you programming in??? c#, vb.net, asp.net, j#?
if you can answer these questions, then yes I can certainly help.
The type of application would be useful too. (i.e Dialog, SDI/MDI etc.)
Language = Visual studio . netOriginally Posted by graham.edmon
I want the input to be alphabetic and alphanumeric
I do want to limit the input as it is a post code i am putting into the program, but this i am not really fussed about that part yet, i just want the text box to accept letters and numbers as it is a post code.
I have found the following on a vb forum
Private sub text1_keypress ( keyascii as integer)
Select case keyascii
Case vbkeyback
Case vbkey0 to vbkey9
Case vbkeya to vbkeyz
keyasciii=0
Case vbkeya + 32 to vbkeyz+32
key ascii=0
Case Else
Key ascii=0
End select
End Sub
I dunno if this is right or not, also as to where to input it in. As i have tried the post code text box code screen, and i get a shit loads of errors
Thank you
Nik
Visual Studio .NET is a development environment, it isn't actually a language in its self. VS.NET allows multiple lanuages to be compile to run on a common run time, the CLR. so the languages are C#, VB.NET, etc etc..
an example is attached.. and is written in c# as a windows application rather than a web application.. it has two levels of validation key level validation preventing you from pressing invalid keys and a regular expression to validate that the UK post code format is valid..
P.S. the code example you have found is VB and not VB.NET, VB.NET is a complete new language which is based on the older VB but which implements the language completely differently.
Cheers mate will try it, thank you for the information about the code i posted before hand too. Will post feedback soon :-)
cheers :thumbs
Nik
i found out the textbox is in an array, i have got the code so the txtbox can accept both numbers and letters but i get a shite load of errors because it is in an array. Anyone how i can change this without pulling my hair out :|
cheers
Nik
post your code here, and I will have a look at it...
Originally Posted by niky2k232
Private Sub AddressList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddressList.SelectedIndexChanged
Dim anAddress As Address
anAddress = AddressList.SelectedItem
txtName.Text = anAddress.Name
txtAddress.Text = anAddress.Address
txtCounty.Text = anAddress.County
txtpost.Text = anAddress.Postcode
txtTown.Text = anAddress.Town
txtHomeTel.Text = anAddress.HomeTel
txtOfficeTel.Text = anAddress.OfficeTel
txtEmail.Text = anAddress.Email
txtMob.Text = anAddress.Mobile
btnUpdate.Enabled = False
End Sub
Private Sub frmAddress_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
PopulateListBox()
setSelect()
setSomeButtonsTrue()
btnSave.Enabled = False
noItemsOnList()
End Sub
Private Sub noItemsOnList()
' Disables some buttons if the listbox is empty
If AddressList.Items.Count < 1 Then
btnDel.Enabled = False
btnEdit.Enabled = False
btnNew.Enabled = False
btnCancel.Enabled = False
btnUpdate.Enabled = False
btnSave.Enabled = False
End If
End Sub
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
ClearBoxes()
setSomeButtonsFalse()
editFlag = False
End Sub
Private Sub ClearBoxes()
txtName.Clear()
txtAddress.Clear()
txtCounty.Clear()
txtpost.Clear()
txtTown.Clear()
txtHomeTel.Clear()
txtOfficeTel.Clear()
txtEmail.Clear()
txtMob.Clear()
txtName.Focus()
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
editFlag = True
setSomeButtonsFalse()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
' Adds objects to the Arraylist and populates the listbox
Try
Dim anAddress As Address
If editFlag Then
anAddress = AddressList.SelectedItem
Else
anAddress = New Address
End If
anAddress.Name = txtName.Text
anAddress.Address = txtAddress.Text
anAddress.County = txtCounty.Text
anAddress.Postcode = txtpost.Text
anAddress.Town = txtTown.Text
anAddress.HomeTel = txtHomeTel.Text
anAddress.OfficeTel = txtOfficeTel.Text
anAddress.Email = txtEmail.Text
anAddress.Mobile = txtMob.Text
If Not editFlag Then
_AddressSys.AddAddress(anAddress)
AddressList.Items.Add(anAddress).ToString()
End If
PopulateListBox()
setSelect()
setSomeButtonsTrue()
btnSave.Enabled = True
Catch ex As Exception
MessageBox.Show("Please Enter Post Code", "Check Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub setSelect()
If AddressList.Items.Count > 0 Then
AddressList.SetSelected(0, True)
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
PopulateListBox()
setSelect()
setSomeButtonsTrue()
noItemsOnList()
End Sub
Private Sub setSomeButtonsTrue()
btnEdit.Enabled = True
btnDel.Enabled = True
btnNew.Enabled = True
BtnExit.Enabled = True
btnUpdate.Enabled = False
btnCancel.Enabled = False
End Sub
Private Sub setSomeButtonsFalse()
btnEdit.Enabled = False
btnDel.Enabled = False
btnNew.Enabled = False
'BtnExit.Enabled = False
btnUpdate.Enabled = True
btnCancel.Enabled = True
End Sub
Private Sub PopulateListBox()
' Add objects to the Listbox
Dim i As Integer
Dim anAddress As Address
AddressList.Items.Clear()
For i = 0 To _AddressSys.NumberOfpeople() - 1
anAddress = _AddressSys.getAddress(i)
AddressList.Items.Add(anAddress).ToString()
Next
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
Me.Close()
End Sub
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
' Deletes objects from the Arraylist and Listbox
Dim Ans As String
Dim anAddress As Address
anAddress = AddressList.SelectedItem
Ans = MessageBox.Show("Are you sure you want to Delete item?", "Please Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Ans = vbYes Then
_AddressSys.DeleteData(anAddress)
PopulateListBox()
setSelect()
btnSave.Enabled = True
If AddressList.Items.Count = 0 Then
ClearBoxes()
setSomeButtonsFalse()
End If
Else
Exit Sub
End If
End Sub
Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
btnUpdate.Enabled = True
btnCancel.Enabled = True
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'Stores data as a serialized file
_AddressSys.SaveData()
btnSave.Enabled = False
End Sub
Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub AddressList_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddressList.TextChanged
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
End Sub
Private Sub txtpost_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub txtpost_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub txtCounty_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCounty.TextChanged
End Sub
Private Sub txtpost_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpost.TextChanged
End Sub
Private Sub txtpost_TextAlignChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtpost.TextAlignChanged
End Sub
Private Sub txtpost_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtpost.Resize
End Sub
Private Sub txtpost_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtpost.Validated
End Sub
Private Sub txtpost_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtpost.Validating
End Sub
Private Sub txtpost_TabStopChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtpost.TabStopChanged
End Sub
Private Sub txtpost_CausesValidationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtpost.CausesValidationChanged
End Sub
End Class
It is the txtpost textbox where i want it to accept numbers and letters.
cheers
Nik
zip it up and attach it.. makes it easier to read, and debug.
ok will have a look @ it for you
ok cheers mate, soemone told me that i need to chnage the textbox from an array to a string, any thoughts?
Thanks for your time bytheway :-)
Nik
Use visual basic 6 m8 if your a beginner.
It gota be done in VB.NET dont ask me why its Edexcels fault!!
I managed to sort this problem now with afew ideas off a few members off this board, i changed the textbox from an array to a string. Workis fine now :-)
Thank you for all your responses tho much appreciated.
Nik
Originally Posted by niky2k232
Social Networking Bookmarks