Solved

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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