2 Replies - 12196 Views - Last Post: 09 May 2007 - 07:43 PM Rate Topic: -----

#1 bud08girl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 21-April 07

Coding Cash register in VB.Net

Post icon  Posted 21 April 2007 - 05:40 PM

Hello- i am trying to code a gui similar to a cash register. I enter a price in a text box and click the enter button. I set a click event for the enter button so it will add the price entered to the subtotal. However, I can't seem to get the subtotal to save so the next item I enter will add to the subtotal. The following is the code (with comments) I have entered, if anyone can see what I am missing or have coded wrong, I would greatly appreciate it! There are no errors popping up and I am at a loss on what else I can try...Thanks so much!
 'declare the variables
	  Dim currentPrice As Integer
	  Dim subtotal As Decimal
	  Dim total As Decimal

	  'retrieve user input to calculate
	  currentPrice = Val(currentPriceTextBox.Text)
	  subtotal = Val(subtotalValueLabel.Text)

	  'add the items values
	  total = subtotal + currentPrice

	  
	  If currentPrice > 0 Then
		 total = Val(subtotalValueLabel.Text) + currentPrice
	  End If

	  'display subtotal
	  subtotalValueLabel.Text = String.Format("{0:C}", total)

	  'clear item price box
	  currentPriceTextBox.Text = ""


Is This A Good Question/Topic? 1
  • +

Replies To: Coding Cash register in VB.Net

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Coding Cash register in VB.Net

Posted 21 April 2007 - 06:00 PM

Where are you declaring the variables in your code?

You probably need to declare them at the Class level. If they are only declared in a procedure/function, then the variables only exist inside the scope of that procedure/function.

When the procedure/function has finished its' operations, the values are discarded.
Was This Post Helpful? 0
  • +
  • -

#3 ramper04  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 13-December 06

Re: Coding Cash register in VB.Net

Posted 09 May 2007 - 07:43 PM

create a module and add global variables that will hold the values that are entered and then will also be able to retrieve those values when needed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1