Solved

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

Posted on 2008-10-10
4
2,644 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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