Reputation: 9
I have written a program and I cannot get part of it to work. My program opens with a welcome page (form). It then moves onto a new page whereby food can be ordered and that quantity, price and total are enteresin in a table with three listboxes.
Once the order is accepted, a receipt form opens. The program then prints the receipt, collapses all the forms with data in, and opens up the welcome page (form) again, thereby returning to the start.
I am trying to add an order number in the receipt form. But because I define the ordernumber as 0 in the form, everytime the program reopens this form, it resets ordernumber to zero. Thus the instruction ordernumber = ordernumber +1 does not keep accumulating.
how to get around this?
pulic ordernumber As Integer = 1
Private Sub Formreceipt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Lblorn.Text = ordernumbeordernumber = ordernumber + 1
Lblorn.Text = ("Order Number:" & ordernumber)
Upvotes: 0
Views: 47
Reputation: 776
You can store the number in My.Settings
Go into your Project Properties, and add a setting named OrderNumber as a user-scoped integer. Start with whatever value you want.
Then from code you can access and change it, and it will also stay put when your application is not running. This way, when you start the program up again tomorrow, the order number will pick up right where it left off.
My.Settings.OrderNumber += 1 'increment the order number by one
Lblorn.Text = My.Settings.OrderNumber 'use the order number
Upvotes: 1
Reputation: 737
One of the way to save order number is use the static field. For example (sorry, but example on C# code)
Create some class:
public class Helper{
//create static field for save order number
public static int orderNum {get;set;}
}
Use class from 1 step: when you create order after that you should increase the counter:
....
Helper.orderNum++;
Use counter in welcome page
note: in the first start your app you should set the counter by zero;
Upvotes: 0