我正在编写一个程序,需要生成一个8位数的学号,第8位(最后一位)是校验位,通过对前7位进行求和来计算,将结果除以10并取余数并从10中减去它。用户没有输入。单击按钮时,代码必须执行并在msgBox中显示学生编号。每次学生注册时,学号必须加1。 请帮忙......
答案 0 :(得分:0)
尝试这样
Public Number As Integer = 1200000 'first seven digits of student number
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = Number
Dim StudentNumber As Integer
i += 1
While (i > 0)
StudentNumber += (i Mod 10)
i /= 10
End While
StudentNumber = 10 - (StudentNumber Mod 10)
StudentNumber = CInt(Number.ToString & StudentNumber.ToString)
Number +=1
MsgBox("Your student number is "" StudentNumber" & StudentNumber)
End Sub