I have an application written in VB6.
I would like to add a capability to have a text box that would accept Currency data entry, so I can specify: (let's say) 5 whole numbers, and (possibly) 2 digits for cents.
As of now, I have this:
and this Function:
It 'works', kind of.
I can type 123.45, it does not allow me to add any more numbers after .45, which is what I want. But I cannot do anything with the 123 part of the number. I must be doing something or missing something here.
Too bad I cannot use Regular Expressions.
Does anybody have any logic to allow typing currency and modifying it in VB6 in a text box?
Right now we have 2 text boxes: one for whole number and one for decimal part, and I hate this approach.
Have fun.
---- Andy
There is a great need for a sarcasm font.
I would like to add a capability to have a text box that would accept Currency data entry, so I can specify: (let's say) 5 whole numbers, and (possibly) 2 digits for cents.
As of now, I have this:
Code:
Private Sub txtMoney_KeyPress(KeyAscii As Integer)
KeyAscii = TextBoxNumber(txtMoney, KeyAscii, 5, 2)
End Sub
and this Function:
Code:
Public Function TextBoxNumber(ByRef txt As TextBox, KA As Integer, _
ByRef intW As Integer, ByRef intDec As Integer) As Integer
TextBoxNumber = KA
[green]
'46 - period
' 8 - BackSpace
[/green]
If KA = 8 Then [green]'BackSpace[/green]
TextBoxNumber = KA
Exit Function
End If
If InStr(txt, ".") And KA = 46 Then[green]
'Allow one period only[/green]
TextBoxNumber = 0
Exit Function
End If
If Len(txt.Text) > 0 Then
If Len(Split(txt.Text, ".")(0)) > intW - 1 Then[green]
'We exceeded allowed digits[/green]
TextBoxNumber = 0
Exit Function
End If
If InStr(txt.Text, ".") Then
If Len(Split(txt.Text, ".")(1)) > intDec - 1 Then[green]
'We exceeded allowed digits after the period[/green]
TextBoxNumber = 0
Exit Function
End If
End If
End If
If (KA > 47 And KA < 58) Or KA = 46 Then[green]
'Only numbers are entered - it is OK[/green]
Else
TextBoxNumber = 0
End If
End Function
It 'works', kind of.
I can type 123.45, it does not allow me to add any more numbers after .45, which is what I want. But I cannot do anything with the 123 part of the number. I must be doing something or missing something here.
Too bad I cannot use Regular Expressions.
Does anybody have any logic to allow typing currency and modifying it in VB6 in a text box?
Right now we have 2 text boxes: one for whole number and one for decimal part, and I hate this approach.
Have fun.
---- Andy
There is a great need for a sarcasm font.