Ok....to make a long story short.....I had a nearly perfectly functioning vb form.....now I find that I need dhtml edit control in the form where before I had simple form controls.
So, now I need vbscript to control the html.
Sounds easy and I've found a lot of similarities in the two languages.
I'm stuck now that I've come to a function that validates text box input.
In vb....I had this:
So, now I need vbscript to control the html.
Sounds easy and I've found a lot of similarities in the two languages.
I'm stuck now that I've come to a function that validates text box input.
In vb....I had this:
Code:
Public Function NumberCase(txtBox As TextBox, KeyAscii As Integer, _
Before As Integer, After As Integer)
'Performs real-time data entry validation for text box inputs on test fields
'Takes parameters for the necessary number of decimal places needed before and
'after the decimal point
'Only allows for one occurance of the decimal, plus, or minus, sign
'greater than, or less than sign.
'allows the infinity symbol when pressing the i key
Dim iTxtLen As Integer
Dim strValid As String
iTxtLen = Len(txtBox.Text) 'length of text box
strValid = "0123456789<>.+-iI" 'string of valid characters
If KeyAscii > 31 Then 'accept Control characters
If InStr(strValid, Chr(KeyAscii)) = 0 Then 'if not part of the valid string
GoTo BadKey
ElseIf InStr(txtBox.Text, Chr(236)) Then
GoTo BadKey
Else 'is a valid character or control code
Dim iDecPos As Integer 'position of decimal
txtBox.MaxLength = Before + After + _
IIf(Before > 3, Round(Before / 3), 0) + _
IIf(After > 0, 1, 0) 'max length of text box input
If After = 0 And KeyAscii = 46 Then GoTo BadKey 'tried to enter more than one decimal
iDecPos = InStr(txtBox.Text, ".") '
If iDecPos > 0 Then
If KeyAscii = 46 And txtBox.SelLength = 0 Then GoTo BadKey
If iTxtLen + 1 > iDecPos + After And txtBox.SelLength = 0 Then GoTo BadKey
Else
If iTxtLen + 1 > Before And Not KeyAscii = 46 And txtBox.SelLength = 0 Then GoTo BadKey
End If
'accept only one < or > symbol
If KeyAscii = 60 Or KeyAscii = 62 Then
If InStr(txtBox.Text, "<") Or InStr(txtBox.Text, ">") Then GoTo BadKey
'accept only one + or - symbol
ElseIf KeyAscii = 43 Or KeyAscii = 45 Then
If InStr(txtBox.Text, "+") Or InStr(txtBox.Text, "-") Then GoTo BadKey
'accept the infinity character with the i keyboard character
ElseIf KeyAscii = 73 Or KeyAscii = 105 Then
'must use terminal font character 236 to display the infinity symbol
txtBox.FontName = "Terminal"
txtBox.Text = Chr(236)
KeyAscii = 0
End If
End If
End If
'make pressing the enter key call function the same of tab key
If KeyAscii = 13 Then
KeyAscii = 0
SendKeys "{Tab}"
End If
Exit Function
BadKey:
KeyAscii = 0
Beep
End Function
[code]
I guess what I'm wondering....is can I obtain the same functionality in vbscript (pass a text box to a function, the key that was pressed, and the before and after parameters).
This is the first time I've done any vbscript and so for my attemps to convert this function have been feeble.
I would appreciate any help!
Thanks,
dmh4ab