Solved

I how do make a basic cash register in visual basic?

Posted on 2008-10-10
4
2,610 Views
Last Modified: 2013-11-25
I have designed it and now need to code it but find that it does not accept my functions for calculating the net price, vat , total incl vat and then rounding this off to two decimal places also ensuring it rejects a non numeric input on the net price text box, I have a calculate btn that runs runs the functions...please advice where I'm going wrong.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intTxtcost As Integer
        Dim inttxtamount As Integer
        Dim intvat As Integer
        intTxtcost = CInt(TXTCOST.Text)
        inttxtamount = CInt(TXTAMOUNT.Text)
        intvat = intTxtcost * inttxtamount / 100 * 17.5
        TXTVAT.Text = CStr(intvat)
        TXTRESULT.Text = intvat + intTxtcost


    End Sub
End Class

0
Comment
Question by:learn4life
  • 3
4 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 22686177
You have everything as integers, I would first suggest you use decimals instead.
And to validate a number, the quickest way would be like:
If IsNumeric(TXTCOST.Text) Then
intTxtcost = CInt(TXTCOST.Text)
End If

0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 22686191
also keep in mind the order of operation for math (I always remember it using "MiDAS" = mulitiply, then divide, then add, then subtract)

so:
intvat = intTxtcost * inttxtamount / 100 * 17.5

intTxtcost *inttxtamount and
100*17.5
will happen first
then those two operations will get divided...be sure that is what you want, else use parenthesis
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 22686232
try:
            Dim decTxtcost As Decimal = 0.0
            Dim dectxtamount As Decimal = 0.0
            Dim decvat As Decimal = 0.0
            If IsNumeric(TXTCOST.Text) = True Then
                decTxtcost = CType(TXTCOST.Text, Decimal)
            End If
            If IsNumeric(TXTAMOUNT.Text) = True Then
                dectxtamount = CType(TXTAMOUNT.Text, Decimal)
            End If
            decvat = decTxtcost * dectxtamount / 100 * 17.5
            TXTVAT.Text = FormatNumber(decvat, 2)
            TXTRESULT.Text = FormatNumber(decvat + decTxtcost, 2)

Open in new window

0
 

Author Comment

by:learn4life
ID: 22698915
Thanks for this..I haven't tried it yet but given your creds I am pretty sure it s what I need.Thanks again.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question