**note...i posted this earlier but forgot to put an appopriate subject...i apoligize if you see it twice**
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:
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
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.
This is what I've come up w/so far.....it's still a work in progress...obviously....but I'm really stuck with getting it to see the right ascii characters!
Public Function NumberCase(txtBox, KeyAscii, Before, After)
Dim iTxtLen
Dim strValid
Dim objBeep
Set objBeep = CreateObject("TONEC1.LongBeep"
Dim Char
txtBox = Document.Testform.txtTotalLeakage.Value
iTxtLen = Len(txtBox)
strValid = "0123456789<>.+-iI"
Char = KeyAscii
If Asc(Char) > 31 Then
If InStr(strValid, Char) = 0 Then
KeyAscii = 0
objBeep.BeepSound 1400, 150
Set objBeep = Nothing
ElseIf InStr(txtBox.Text, Chr(236)) Then
KeyAscii = 0
Beep
Else
Dim iDecPos, a, b
If Before > 3 Then b = Rnd(Before / 3) Else b = 0
If After > 0 Then a = 1 Else a = 0
txtBox.MaxLength = Before + After + b + a
If After = 0 And KeyAscii = 46 Then KeyAscii = 0: Beep
iDecPos = InStr(txtBox.Text, "."
If iDecPos > 0 Then
If KeyAscii = 46 And txtBox.SelLength = 0 Then KeyAscii = 0: Beep
If iTxtLen + 1 > iDecPos + After And txtBox.SelLength = 0 Then KeyAscii = 0: Beep
Else
If iTxtLen + 1 > Before And Not KeyAscii = 46 And txtBox.SelLength = 0 Then KeyAscii = 0: Beep
End If
If KeyAscii = 60 Or KeyAscii = 62 Then
If InStr(txtBox.Text, "<" Or InStr(txtBox.Text, ">" Then KeyAscii = 0: Beep
ElseIf KeyAscii = 43 Or KeyAscii = 45 Then
If InStr(txtBox.Text, "+" Or InStr(txtBox.Text, "-" Then KeyAscii = 0: Beep
ElseIf KeyAscii = 73 Or KeyAscii = 105 Then
txtBox.FontName = "Terminal"
txtBox.Text = Chr(236)
KeyAscii = 0
End If
End If
End If
If KeyAscii = CLng(13) Then
KeyAscii = 0
SendKeys "{Tab}"
End If
End Function
I would appreciate any help!
Thanks,
dmh4ab
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:
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
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.
This is what I've come up w/so far.....it's still a work in progress...obviously....but I'm really stuck with getting it to see the right ascii characters!
Public Function NumberCase(txtBox, KeyAscii, Before, After)
Dim iTxtLen
Dim strValid
Dim objBeep
Set objBeep = CreateObject("TONEC1.LongBeep"
Dim Char
txtBox = Document.Testform.txtTotalLeakage.Value
iTxtLen = Len(txtBox)
strValid = "0123456789<>.+-iI"
Char = KeyAscii
If Asc(Char) > 31 Then
If InStr(strValid, Char) = 0 Then
KeyAscii = 0
objBeep.BeepSound 1400, 150
Set objBeep = Nothing
ElseIf InStr(txtBox.Text, Chr(236)) Then
KeyAscii = 0
Beep
Else
Dim iDecPos, a, b
If Before > 3 Then b = Rnd(Before / 3) Else b = 0
If After > 0 Then a = 1 Else a = 0
txtBox.MaxLength = Before + After + b + a
If After = 0 And KeyAscii = 46 Then KeyAscii = 0: Beep
iDecPos = InStr(txtBox.Text, "."
If iDecPos > 0 Then
If KeyAscii = 46 And txtBox.SelLength = 0 Then KeyAscii = 0: Beep
If iTxtLen + 1 > iDecPos + After And txtBox.SelLength = 0 Then KeyAscii = 0: Beep
Else
If iTxtLen + 1 > Before And Not KeyAscii = 46 And txtBox.SelLength = 0 Then KeyAscii = 0: Beep
End If
If KeyAscii = 60 Or KeyAscii = 62 Then
If InStr(txtBox.Text, "<" Or InStr(txtBox.Text, ">" Then KeyAscii = 0: Beep
ElseIf KeyAscii = 43 Or KeyAscii = 45 Then
If InStr(txtBox.Text, "+" Or InStr(txtBox.Text, "-" Then KeyAscii = 0: Beep
ElseIf KeyAscii = 73 Or KeyAscii = 105 Then
txtBox.FontName = "Terminal"
txtBox.Text = Chr(236)
KeyAscii = 0
End If
End If
End If
If KeyAscii = CLng(13) Then
KeyAscii = 0
SendKeys "{Tab}"
End If
End Function
I would appreciate any help!
Thanks,
dmh4ab