Private?Sub?cmdClear_Click()?'#清空內容?
txtNumber.Text?=?""?
txtNumberCheck.Text?=?""?
End?Sub?
Private?Sub?cmdGenerate_Click()?
strNumber?=?txtNumber.Text?
'********************檢測長度是否為7****************?
If?Len(Trim(strNumber))?<>?7?Then?
MsgBox?"準考證號輸入錯誤,請重新輸入"?
txtNumber.Text?=?""?
Exit?Sub?
End?If?
'********************檢測是否全部為數字****************?
Dim?oRegExp?
Set?oRegExp?=?CreateObject("VBscript.RegExp")?
oRegExp.IgnoreCase?=?True?
oRegExp.Global?=?True?
oRegExp.Pattern?=?"[0-9]{7}"?
If?Not?oRegExp.Test(strNumber)?Then?
MsgBox?"準考證號輸入錯誤,請重新輸入"?
txtNumber.Text?=?""?
Exit?Sub?
End?If?
'********************生成校驗碼****************?
CheckSum?=?0?
For?i?=?1?To?7?
CheckSum?=?CheckSum?+?CInt(Mid(strNumber,?8?-?i,?1))?*?i?
Next?
CheckNum?=?CheckSum?Mod?10?
txtNumberCheck.Text?=?CStr(CheckNum)?&?strNumber?
End?Sub?
Private?Sub?cmdCheck_Click()?
strNumberCheck?=?txtNumberCheck.Text?
'********************檢測長度是否為8****************?
If?Len(Trim(strNumberCheck))?<>?8?Then?
MsgBox?"準考證號輸入錯誤,請重新輸入"?
txtNumberCheck.Text?=?""?
Exit?Sub?
End?If?
'********************檢測是否全部為數字****************?
Dim?oRegExp?
Set?oRegExp?=?CreateObject("VBscript.RegExp")?
oRegExp.IgnoreCase?=?True?
oRegExp.Global?=?True?
oRegExp.Pattern?=?"[0-9]{8}"?
If?Not?oRegExp.Test(strNumberCheck)?Then?
MsgBox?"準考證號輸入錯誤,請重新輸入"?
txtNumberCheck.Text?=?""?
Exit?Sub?
End?If?
MsgBox?"校驗成功"?
End?Sub