Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   IT / Communications (http://www.chiefdelphi.com/forums/forumdisplay.php?f=85)
-   -   Need Visual Basic Help (http://www.chiefdelphi.com/forums/showthread.php?t=80852)

KC1AJT 22-01-2010 10:53

Need Visual Basic Help
 
I am in the process of designing a scouting program.
I have the following code:
Private Sub teamnum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles teamnum.KeyPress

Dim allowedChars As String = "0123456789"

If allowedChars.IndexOf(e.KeyChar) = -1 Then
' Invalid Character
e.Handled = True
End If

End Sub

But I would like to add the function of a backspace key.:confused:

riptide 22-01-2010 11:04

Re: Need Visual Basic Help
 
You have to use the ascii character for backspace which is 8.

Try this:

Dim allowedChars As String = "0123456789" + Chr(8)

Tristan Lall 22-01-2010 11:06

Re: Need Visual Basic Help
 
The solution to this problem in DOS-mode Pascal was to read ASCII character 8. In C, you would use \b or \x08. See this table for a VB constant called "vbBack" that may work equivalently.

KC1AJT 22-01-2010 11:11

Re: Need Visual Basic Help
 
Quote:

Originally Posted by riptide (Post 904592)
You have to use the ascii character for backspace which is 8.

Try this:

Dim allowedChars As String = "0123456789" + Chr(8)

Thanks! Works Perfectly!:D

riptide 22-01-2010 11:13

Re: Need Visual Basic Help
 
the constant vbBack will work as well.

KC1AJT 22-01-2010 17:15

Re: Need Visual Basic Help
 
Thanks for all the answers, I will release the the database and cooresponding programs as soon as they are finished.

KC1AJT 23-01-2010 14:45

Re: Need Visual Basic Help
 
Ran into another issue I have a checkedlistbox with 6 checkboxes and would like to put code in a clear button to uncheck all of the 6 checkboxes.

Nate Smith 24-01-2010 08:25

Re: Need Visual Basic Help
 
Two ways you can do it...

1. If they are the only checkboxes on the form(or panel, etc):
Code:

For each ctl as Control in Me.Controls
    If TypeOf ctl is Checkbox then CType(ctl, Checkbox).Checked = False
Next ctl

2. If there are other controls you don't want to mess with, you'll need to just specify each checkbox by name, such as:
Code:

CheckBox1.Checked=False
CheckBox2.Checked=False
...


riptide 24-01-2010 12:22

Re: Need Visual Basic Help
 
You want to try something like this. Place it in the ButtonUnchecked clicked sub.

For i As Integer = 0 To checklistbox1.Items.Count - 1
checklistbox1.SetItemChecked(i, False)
Next i

KC1AJT 24-01-2010 12:25

Re: Need Visual Basic Help
 
Ok I finally found it. After a day on Google, here's the code:


Dim i As Integer
For i = 0 To Me.CheckedListBox1.CheckedIndices.Count - 1
Me.CheckedListBox1.SetItemChecked(Me.CheckedListBo x1.CheckedIndices(0), False)
Next i


All times are GMT -5. The time now is 02:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi