Solved

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

Posted on 2008-10-10
4
2,732 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 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