简体   繁体   中英

How to add 1 on last data? VB2008

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)

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

我的设置

One of the way to save order number is use the static field. For example (sorry, but example on C# code)

  1. Create some class:

    public class Helper{

    //create static field for save order number

    public static int orderNum {get;set;}

    }

  2. Use class from 1 step: when you create order after that you should increase the counter:

    ....

    Helper.orderNum++;

  3. Use counter in welcome page

note: in the first start your app you should set the counter by zero;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM