當前位置:編程學習大全網 - 編程軟體 - vb題目!高分求解!

vb題目!高分求解!

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

  • 上一篇:幫我用c#寫個 xml讀取程序,實現將xml中的樹形結構在 winform中以treeView形式顯示出來
  • 下一篇:2012日產陽光有沒有前霧燈保險絲的
  • copyright 2024編程學習大全網