Solved

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

Posted on 2008-10-10
4
2,525 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now