VB怎么实现点击“新建”按钮自动编号,每点击一次自动加一,并且判断每天从001开始累加。
3个回答
展开全部
专门写的一个代码,你的要求需要保存文件里面,下面的代码调试通过,修改一下,切记有一段是只能使用一次的代码。使用完了要删除的
Private Type ef
a As Date
b As Long
End Type
Private Sub Command1_Click()
Dim xin As ef
Open App.Path & "\gs.bin" For Binary As #1
Get #1, 1, xin
Close #1
'm = Date
If xin.a = Date Then
Label1.Caption = "S" & Year(xin.a) & Right("00" & Month(xin.a), 2) & Right("00" & Day(xin.a), 2) & Right("000" & xin.b, 3)
xin.b = xin.b + 1
Else
xin.a = Date
xin.b = 1
End If
Open App.Path & "\gs.bin" For Binary As #1
Put #1, 1, xin
Close #1
End Sub
Private Sub Form_Load()
'下面是初始化代码,只是第一次使用,开始产生文件gs.bin文件以后不用下面代码了
Dim xin As ef
xin.a = Date
xin.b = 1
Open App.Path & "\gs.bin" For Binary As #1
Put #1, 1, xin
Close #1
'初始化结束
End Sub
Private Type ef
a As Date
b As Long
End Type
Private Sub Command1_Click()
Dim xin As ef
Open App.Path & "\gs.bin" For Binary As #1
Get #1, 1, xin
Close #1
'm = Date
If xin.a = Date Then
Label1.Caption = "S" & Year(xin.a) & Right("00" & Month(xin.a), 2) & Right("00" & Day(xin.a), 2) & Right("000" & xin.b, 3)
xin.b = xin.b + 1
Else
xin.a = Date
xin.b = 1
End If
Open App.Path & "\gs.bin" For Binary As #1
Put #1, 1, xin
Close #1
End Sub
Private Sub Form_Load()
'下面是初始化代码,只是第一次使用,开始产生文件gs.bin文件以后不用下面代码了
Dim xin As ef
xin.a = Date
xin.b = 1
Open App.Path & "\gs.bin" For Binary As #1
Put #1, 1, xin
Close #1
'初始化结束
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Static i
i = i + 1
Debug.Print "S" & Format(Date, "YYYYMMDD") & Format(i, "000")
End Sub
Static i
i = i + 1
Debug.Print "S" & Format(Date, "YYYYMMDD") & Format(i, "000")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询