如何在最后一个数字上加1? [英] How to add 1 to last number?
问题描述
我使用标签作为订单号.我希望每次下订单时给订单号加 1.我需要做一个循环吗?如果是这样,如何?
i use label for a order number.i want it add 1 to order number each time the order is placed. do i need do a loop ? And if so, how?
Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click
'ordernumber = 0
ordernumber = ordernumber + 1
Lblorn.Text = ("Order Number:" & ordernumber)
推荐答案
在这种情况下您不需要循环,因为只有在触发 btnprint_Click
事件时才会增加订单号.
You don't need a loop in this case as incrementing the order number should happen only when the btnprint_Click
event is triggered.
如果您想在事件触发后继续打印 n
编号或订单,则需要循环.
A loop is required if you want to keep printing an n
number or orders once the event is triggered.
您需要声明一个变量,该变量对于存在此按钮和标签的窗体/窗口是全局的,并且将在内存中保留最新的 ordernumber
- 仅在窗口打开之前.关闭应用程序后,再次打开它 - 它将默认为 0
.
You need to declare a variable which is global to the form/window where this button and the label is present and that will keep the latest ordernumber
in memory - only till the window is open. Once you close the application, and open it again - it will be defaulted to 0
.
如果您希望这个最新的 ordernumber
在应用程序的其他部分可用,则需要在应用程序级别将 ordernumber
声明为全局变量.
If you want this latest ordernumber
available in other parts of the application, you need to declare the ordernumber
as a global variable, in the application level.
如果您想存储最新的ordernumber
的值,即使在应用程序关闭或之后,您也需要将其存储在数据库或文件中,并在应用程序再次加载时检索它.
If you want to store the value of latest ordernumber
, even after the application is closed or after , you need to store it in a database or file and retrieve it while the application is loaded again.
这篇关于如何在最后一个数字上加1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!