Hello Im new to these forums. Im using VB for our thesis and Im just wondering how to be able to put numbers only on text boxes without causing an error.
Printable View
Hello Im new to these forums. Im using VB for our thesis and Im just wondering how to be able to put numbers only on text boxes without causing an error.
We can only put text into textboxes.
Where we need numbers the entry needs to be converted in some way. The easiest way is to get Excel to do the conversion by declaring a variable. eg.
Code:Dim MyNumber As Double
MyNumber = TextBox1.Value
That's what I do:
nSNR = CInt(txtNoise.Text)
And as soon as I type a non-number character...
VB Code:
Option Explicit Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii <> 46 And KeyAscii <> 48 And KeyAscii <> 49 And KeyAscii <> 50 Then 'Etc. KeyAscii = vbNull End If End Sub