Creating a Cash Register StyleTextbox Display

Hello Spotty, Renee...Thank You all for helping me to learn VB2005.

I say very sincerely, It's been a lot of fun, and hard work(thinking)!.

I've pasted code to show what is presently being done. Until several keys are pressed, the end user cannot tell what they have pressed. Evereything is done by mouse down, or click, as this will be a KIOSK only Touch Screen App.

The display would be preferrably righ to left with each digit showing a nickel rounded value.

Only 4 digits are required as the max is $45. Minimum is a nickel ($.05).

I tried a hidden textbox, but is was very clunky and ugly. I couldn't make a masked TB work, and gave up on that.

So...I'm ready to liten to advice, and would like to add...I appreciated the advice about the "lostFocus" event handler, but there was no focus in this "mouse" only mode. (At least none I was aware of) :-)

Thanks Again, and as always...Make the best of this beautiful Day!

Elgee

Dim StrResult As String

Dim x As Integer = 0

'this is where the output texts are eminating from.

Public Sub keyClick( _

ByVal sender As System.Object, _

ByVal e As System.EventArgs) _

Handles key1.Click, Key2.Click, Key3.Click, Key4.Click, Key5.Click, Key6.Click, _

Key7.Click, Key8.Click, Key9.Click, Key0.Click

TB3.ForeColor = Color.Black

TB1.Text &= sender.tag

Dim value1

value1 = TB1.Text

TB3.Text = value1

Dim value2

value2 = x + 1

cliks.Text = x

If cliks.Text > 5 Then clearboxes()

If TB3.Text.Length > 0 Then

StrResult = Format("##0.00", CInt(TB3.Text) / 100)

Dim roundedvalue

roundedvalue = CInt(StrResult * 20) / 20

If roundedvalue > 45.0 Then roundedvalue = 45.0

TB3.Text = FormatCurrency(roundedvalue, 2)

End If

End Sub




Answer this question

Creating a Cash Register StyleTextbox Display

  • Jude A

    Ok...I will be able to try it in a little while...I'll let you know as soon as possible.

    Elgee



  • Cognitronic

    The first part is that the righttoleft property will allow this thing to work like a cash register. Which I think is part of the solution.

    The following is along the lines with the reformatting getting done every time you reach 4 characters long or that control loses focus which will ocur if you click on another control. Its not perfect but it may work for you.

    Public Class Form1
    Dim strResult As String

    Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
    Formating(TextBox1.Text)
    End Sub

    Function StripDot(ByVal x As String) As String
    Dim xreturn As String = ""
    For Each c As Char In x.ToString
    If Char.IsNumber(c) Then
    xreturn = xreturn & c
    End If
    Next
    Return xreturn
    End Function


    Private Sub Formating(ByRef s As String)
    If s.Length > 0 Then
    strResult = Format("##0.00", CInt(s) / 100)
    Dim roundedvalue
    roundedvalue = CInt(strResult * 20) / 20
    If roundedvalue > 45.0 Then roundedvalue = 45.0
    s = FormatCurrency(roundedvalue, 2)
    End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    If Len(TextBox1.Text) = 4 Then
    Formating(TextBox1.Text)
    End If
    End Sub
    End Class


  • Smurble

    Here is a slightly modified example to try - very similar but involves a textbox and 5 buttons called Button1, Button2, Button3, Button4 and Button5.    Ensure that the buttons have just the respective number on as there text property.

     

     

    Public Class Form1
        Dim strResult As String

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            TextBox1.RightToLeft = Windows.Forms.RightToLeft.Yes
        End Sub


        Private Sub Formating(ByRef s As String)
            If s.Length > 0 Then
                Dim TwoDP As String
                TwoDP = Format("##0.00", CInt(s) / 100)

                Dim roundedvalue As Single
                roundedvalue = CInt(TwoDP * 20) / 20
                If roundedvalue > 45.0 Then roundedvalue = 45.0
                TextBox1.Text = FormatCurrency(roundedvalue, 2)
            End If
        End Sub


        Private Sub AddButtonvalue(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click
            '//Ensures the Button Text is Numeric
            If IsNumeric(CType(sender, Button).Text) Then
                strResult = strResult & CType(sender, Button).Text
                Formating(strResult)
            End If
        End Sub

    End Class

     


  • KarlH

    Hi...

    I tried the code just as you see it here. It produced nothing in the textbox at all.

    I'm leaving work in a little bit and won't be able to respond until later tonight (the wee hours).

    Thanks...I give it a longer look at home.

    Elgee...BTW...Did you see my question about VB2005 literature

    Thanks Again.

    Public Class Form1

    Dim strResult As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    TextBox1.RightToLeft = Windows.Forms.RightToLeft.Yes

    End Sub

    Private Sub Formating(ByRef s As String)

    If s.Length > 0 Then

    Dim TwoDP As String

    TwoDP = Format("##0.00", CInt(s) / 100)

    Dim roundedvalue As Single

    roundedvalue = CInt(TwoDP * 20) / 20

    If roundedvalue > 45.0 Then roundedvalue = 45.0

    TextBox1.Text = FormatCurrency(roundedvalue, 2)

    End If

    End Sub

    Private Sub AddButtonvalue(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click

    '//Ensures the Button Text is Numeric

    If IsNumeric(CType(sender, Button).Text) Then

    strResult = strResult & CType(sender, Button).Text

    Formating(strResult)

    End If

    End Sub

    End Class



  • dglane

    Hello Elgee. It's really good to see you again and thank you for your kind words. It looks as if you are in excellent hands.

    I'll be watching. :)



  • Tom Rahav

    Would they be my hands.


  • francois974

    First of all just try the code in a simple scenario.

    Create a Form with a single textbox called textbox1 and a button on it, then use the following code.

    Obviously this code hasn't got anything to ensure only text is set but once in place type numbers only (I know youve got that code) and type numbers in rather than entering them via mouse click (I know eventually you using buttons in you application but for the testing just use keyboard). Try entering numbers and then click on the button.

    See the behaviour. If this is sort of what you want then we can expand on the scenario in this little form before we implement anything in your app. This is designed to try and demonstrate a concept which when we get it correct you'll be able to implement in your own application.


  • David Johnson MCSD

    Hi Renee...

    What's great about my words is that I mean them. Thanks!

    I tried the code just posted and got no results at all. I changed the variables to match my textboxes and nothing at all.

    For the record...

    TB1 is the main textbox from which I derive my TB3 text to show onscreen. TB1 is a hidden box. I convert the hidden number to a Decimal for the end user to see.

    It is TB3 which requires the end formatting. I'm not certain what our orgs secrecy policy is so I can't at this time share the whole code. (I'd love too!)

    Right now in its present state, the TB3 textbox is formatted as currency, and will not show the leading digit until its value is at least 5. Once again, let me make clear as well, there are no LostFocus events to work with. No one will ever be able to type or enter a textbox, and the controls (buttons) are part of an handler array (at least I think they are).

    Wow! Thanks again..Hope this is a better more clear explanation...

    By the way Renee...I found out my Tinnutis may be from too much Coffee!

    Elgee

    Here's the code from the top, that produces the output...

    Dim StrResult As String

    Dim x As Integer = 0

    'this is where the output texts are eminating from.

    Public Sub keyClick( _

    ByVal sender As System.Object, _

    ByVal e As System.EventArgs) _

    Handles key1.Click, Key2.Click, Key3.Click, Key4.Click, Key5.Click, Key6.Click, _

    Key7.Click, Key8.Click, Key9.Click, Key0.Click

    TB3.ForeColor = Color.Black

    TB1.Text &= sender.tag 'Invisible to user, but contains main values for conversion later

    Dim value1

    value1 = TB1.Text

    TB3.Text = value1

    Dim value2

    value2 = x + 1

    cliks.Text = x

    If cliks.Text > 5 Then clearboxes() 'Prevents user from continuous number clicking

    If TB3.Text.Length > 0 Then

    StrResult = Format("##0.00", CInt(TB3.Text) / 100)

    Dim roundedvalue

    roundedvalue = CInt(StrResult * 20) / 20

    If roundedvalue > 45.0 Then roundedvalue = 45.0 ' Maximum $45 Limit

    TB3.Text = FormatCurrency(roundedvalue, 2) 'What the end user sees

    End If

    End Sub

    Private Sub clearboxes()

    x = 0

    TB1.Text = ""

    TB3.Text = FormatCurrency(0.0, 2)

    FormatCurrency(TB3.Text, 2)

    cliks.Text = 0.0

    End Sub

    Private Sub Key0_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key0.MouseDown

    x = x + 1

    End Sub

    Private Sub key1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles key1.MouseDown

    x = x + 1

    End Sub

    Private Sub Key2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key2.MouseDown

    x = x + 1

    End Sub

    Private Sub Key3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key3.MouseDown

    x = x + 1

    End Sub

    Private Sub Key4_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key4.MouseDown

    x = x + 1

    End Sub

    Private Sub Key5_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key5.MouseDown

    x = x + 1

    End Sub

    Private Sub Key6_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key6.MouseDown

    x = x + 1

    End Sub

    Private Sub Key7_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key7.MouseDown

    x = x + 1

    End Sub

    Private Sub Key8_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key8.MouseDown

    x = x + 1

    End Sub

    Private Sub Key9_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Key9.MouseDown

    x = x + 1

    End Sub

    Private Sub keyDecimal_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

    x = x + 1

    End Sub

    Private Sub opclearentry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opclearentry.Click

    clearboxes()

    clearall()

    End Sub

    Public Sub fiver()

    TB3.Text = FormatCurrency(5.0, 2)

    End Sub

    Public Sub tenspot()

    TB3.Text = FormatCurrency(10.0, 2)

    End Sub

    Public Sub jefferson()

    TB3.Text = FormatCurrency(20.0, 2)

    End Sub



  • Creating a Cash Register StyleTextbox Display