如何用VB寫出 身分證字號產生器 2005版的

目前在學習VB中 老師出了題目

要我們做VB身分證字號產生器

請各位大大幫幫忙

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    Dim strID As String = TextBox1.Text

    Dim alp() As String = {10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30, 31, 33}

    Dim achar As Char = strID.Substring(0, 1)

    Dim iAlp As Integer = Convert.ToDouble(Convert.ToSByte(achar)) - 65

    Dim sAlp As String = alp(iAlp)

    Dim Num1 As Integer = Convert.ToInt32(sAlp.Substring(0, 1)) * 1

    Dim Num2 As Integer = Convert.ToInt32(sAlp.Substring(1, 1)) * 9

    Dim Num3 As Integer = Convert.ToInt32(strID.Substring(1, 1)) * 8

    Dim Num4 As Integer = Convert.ToInt32(strID.Substring(2, 1)) * 7

    Dim Num5 As Integer = Convert.ToInt32(strID.Substring(3, 1)) * 6

    Dim Num6 As Integer = Convert.ToInt32(strID.Substring(4, 1)) * 5

    Dim Num7 As Integer = Convert.ToInt32(strID.Substring(5, 1)) * 4

    Dim Num8 As Integer = Convert.ToInt32(strID.Substring(6, 1)) * 3

    Dim Num9 As Integer = Convert.ToInt32(strID.Substring(7, 1)) * 2

    Dim Num10 As Integer = Convert.ToInt32(strID.Substring(8, 1)) * 1

    Dim Sum As Integer = Num1 + Num2 + Num3 + Num4 + Num5 + Num6 + Num7 + Num8 + Num9 + Num10

    Dim Chk As Integer = 10 - (Sum Mod 10)

    TextBox1.Text = strID.Substring(0, 9) + Chk.ToString()

    2007-08-13 11:43:00 補充:

    拉一個BUTTON及一個TEXT到FORM上,再把程式碼COPY到BUTTON的EVENT就完成了

    2007-08-13 17:01:31 補充:

    這個原因應該是TEXT欄位沒有先輸入身分證的前9碼

    因為我是幫你產生驗證碼

    而不是隨機跑出身分證資料

    Source(s): 8年程式經驗
Still have questions? Get your answers by asking now.