2009年2月27日 星期五

四則運算

image

image

image

image

image

Public Class Form1
    Dim a As Integer
    Dim b As Integer
    Dim id As Integer
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        id = 0

    End Sub
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

        id = 1
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged

        id = 2
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        id = 3

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        Select Case id
            Case 0
                TextBox3.Text = a + b
            Case 1
                TextBox3.Text = a - b
            Case 2
                TextBox3.Text = a * b
            Case 3
                TextBox3.Text = a / b
        End Select
    End Sub
End Class

99-37

image 

'37.計算輸入英文文字檔案中,各「英文字」出現的次數。

Public Class Form1
       Dim i, a1, j
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Dim b = "abcdefghijklmnopqrstuvwxyz"
        Dim c = " i Love You. "
        a1 = 0

          For j = 1 To 14
            If Mid(c, j, 1) = "o" Then a1 = a1 + 1
        Next
        MsgBox("o" & " 出現的次數: " & a1)
    End Sub
End Class

以前校內程式設計比賽的題目-第一題

image

image

Public Class Form1
    Dim a As Single
    Dim s As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = 0
        a = TextBox1.Text
        a = a * 1000
        If a <= 1000 Then
            s = 70
        Else
            a = a - 1000
            If a Mod 400 = 0 Then
                s = 70 + ((a / 400) * 5)
            Else
                s = 70 + ((a \ 400) * 5) + 5
            End If
        End If
        TextBox2.Text = s
    End Sub
End Class

麗山50題之41

image

image

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text < 100 Then
            If TextBox2.Text < 100 Then
                TextBox3.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
            End If
        End If
    End Sub

End Class

簡單四則運算

 

image         相加

image         相減

image        相乘

image       相除

Public Class Form1
    Dim a, b
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a + b
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a - b
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a * b
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a / b
    End Sub
End Class

四則運算(簡單版)

image

Public Class Form1
    Dim a, b
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a + b
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a - b
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a * b
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a / b
    End Sub
End Class

國字轉英文

image

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r1 = "做我自己"
        Dim r2 = " Do myself. "

        MsgBox(r1 & " 中文換英文: " & r2)
    End Sub
End Class

 

 

'想請問,如果可以隨意打字就可變成英文的翻譯系統的程式

'必須怎麼來設計?

數字轉換國字

 

image

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a = " 1 5 2 6 9 0 "
        Dim f = a
        f = Replace(f, "1", "壹")
        f = Replace(f, "2", "貳")
        f = Replace(f, "3", "參")
        f = Replace(f, "4", "肆")
        f = Replace(f, "5", "伍")
        f = Replace(f, "6", "陸")
        f = Replace(f, "7", "柒")
        f = Replace(f, "8", "捌")
        f = Replace(f, "9", "玖")
        f = Replace(f, "0", "零")
        MsgBox(a & "    轉換成大寫國字:" & f)
    End Sub
End Class

九九乘法表(課本例題)

image

 

image

 

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mx(9, 9) As Integer
        Dim loop_I, loop_j As Integer
        Dim outstr As String
        For loop_I = 1 To 9
            For loop_j = 1 To 9
                mx(loop_I, loop_j) = loop_I * loop_j
            Next
        Next
        For loop_I = 9 To 1 Step -1
            For loop_j = 9 To 1 Step -1
                outstr = Format(loop_I, "0#")
                outstr = outstr & "*"
                outstr = outstr & Format(loop_j, "0#")
                outstr = outstr & "="
                outstr = outstr & Format(mx(loop_I, loop_j), "0#")
                TextBox1.Text = TextBox1.Text & "   " & outstr
            Next
            TextBox1.Text = TextBox1.Text & vbNewLine
        Next
    End Sub
End Class

 

[VB 2005 6-9頁例題]

二個字串各一次取一個合併

 

image

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r3 = "萬仟百拾"
        Dim r4 = "壹貳参肆伍"
        Dim str1 = ""
        For i = 1 To 4
            str1 = str1 & Mid(r4, i, 1) & Mid(r3, i, 1)
        Next
        str1 = str1 & Microsoft.VisualBasic.Right(r4, 1)
        MsgBox(str1)
    End Sub
End Class

英文轉換大寫英文

image

'利用,數字轉國字大寫的方法,來寫出英文轉換大寫的作法

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a1 = "abcdefghijklmnopqrstuvwxyz"
        Dim a2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Dim c = "h a p p y"
        Dim d = c

        For i = 1 To 26
            d = Replace(d, Mid(a1, i, 1), Mid(a2, i, 1))
        Next i
        MsgBox(c & " 英文轉換大寫: " & d)
    End Sub
End Class

數字順序反轉

image

 

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s = "123456789"
        Dim str1 = ""
        For i = 9 To 1 Step -1
            str1 = str1 + Mid(s, i, 1)
        Next
        MsgBox(str1)
    End Sub
End Class

100以內數字相除

image

image

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text < 100 Then
            If TextBox2.Text < 100 Then
                TextBox3.Text = Val(TextBox1.Text) / Val(TextBox2.Text)

            End If
        End If
    End Sub
End Class

(參考20133陳怡娟的程式)

99-21

image

'21.將輸入字串之英文字母大小寫互換。

Public Class Form1 
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Dim a2 = "abcdefghijklmnopqrstuvwxyz"
        Dim f = "APPLE"
        Dim c = f
        For i = 1 To 26
            c = Replace(c, Mid(a1, i, 1), Mid(a2, i, 1))
        Next
        MsgBox(f & " 英文轉換大小寫: " & c)
    End Sub
End Class

99-7

image

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a = 0
        For i = 1 To 99
            a = a + i
        Next
        MsgBox(a)
    End Sub
End Class

數字轉國字大寫

image

'數字轉國字大寫
'改以mid函數及迴路處理
Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r1 = "0123456789"
        Dim r2 = "零壹貳参肆伍陸柒捌玖"
        Dim d = "135790"
        Dim s = d
        For i = 1 To 10
            s = Replace(s, Mid(r1, i, 1), Mid(r2, i, 1))
        Next
        MsgBox(d & " → " & s)

    End Sub
End Class

二個字串各一次取一個合併

image

'講解二個字串各一次取一個合併
Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r3 = "萬仟佰拾"
        Dim r4 = "壹貳参肆伍"
        Dim strl = ""

        For i = 1 To 4
            strl = strl & Mid(r4, i, 1) & Mid(r3, i, 1)
        Next

        'MsgBox(strl & Microsoft.VisualBasic.Right(r4, 1)

        MsgBox(strl & Mid(r4, 5, 1))
    End Sub
End Class

數字轉國字大寫

image

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r1 = "0123456789"
        Dim r2 = "零壹貳参肆伍陸柒捌玖"
        Dim d = "571683"
        Dim s = d
        For i = 1 To 10
            s = Replace(s, Mid(r1, i, 1), Mid(r2, i, 1))
        Next
        MsgBox(s)
    End Sub
End Class

100以內數字相加

image

image

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text < 100 Then
            If TextBox2.Text < 100 Then
                TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
            End If
        End If
    End Sub
End Class

數字轉國字大寫2

image

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim f1 = "0123456789"
        Dim f2 = "壹貳参肆伍陸柒捌玖零"
        Dim g = "4 8 9 5 2"
        Dim a = g
        For i = 1 To 10
            a = Replace(a, Mid(f1, i, 1), Mid(f2, i, 1))
        Next i

        MsgBox(g & "國字大寫為:" & a)
    End Sub
End Class

數字轉國字

image

 

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r1 = "1987302645"
        Dim r2 = "零壹貳参肆伍陸柒捌玖"
        Dim d = "135897"
        Dim s = d
        For i = 1 To 10
            s = Replace(s, Mid(r1, i, 1), Mid(r2, i, 1))
        Next i

        'Dim d = "1987302645"
        'Dim s = d
        's = Replace(s, "1", "壹")
        's = Replace(s, "2", "貳")
        's = Replace(s, "3", "叁")
        's = Replace(s, "4", "肆")
        's = Replace(s, "5", "伍")
        's = Replace(s, "6", "陸")
        's = Replace(s, "7", "柒")
        's = Replace(s, "8", "捌")
        's = Replace(s, "9", "玖")
        's = Replace(s, "0", "零")

        MsgBox(d & "  " & "數字轉國字:  " & s)

    End Sub
End Class

數字轉國字大寫

 

 

image 

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim d = "135897"
        Dim s = d
        s = Replace(s, "1", "壹")
        s = Replace(s, "2", "貳")
        s = Replace(s, "3", "參")
        s = Replace(s, "4", "肆")
        s = Replace(s, "5", "伍")
        s = Replace(s, "6", "陸")
        s = Replace(s, "7", "柒")
        s = Replace(s, "8", "捌")
        s = Replace(s, "9", "玖")
        s = Replace(s, "0", "零")

        MsgBox(d & "國字大寫為:" & s)

    End Sub
End Class

數字轉國字

image

 

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r1 = ("0123456789")
        Dim r2 = ("零壹貳參肆伍陸柒捌玖")
        Dim d = "123456"
        Dim s = d
        For i = 1 To 10
            s = Replace(s, Mid(r1, i, 1), Mid(r2, i, 1))
        Next i
        MsgBox(d & " 轉國字為:" & s)
    End Sub
End Class

數字轉國字大寫

image

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s = "1 2 5 8 7 4"
        Dim d = s

        s = Replace(s, "1", "壹")
        s = Replace(s, "2", "貳")
        s = Replace(s, "3", "参")
        s = Replace(s, "4", "肆")
        s = Replace(s, "5", "伍")
        s = Replace(s, "6", "陸")
        s = Replace(s, "7", "柒")
        s = Replace(s, "8", "捌")
        s = Replace(s, "9", "玖")
        s = Replace(s, "0", "零")
        MsgBox(d & "國字大寫為:" & s)
    End Sub
End Class

彰商程式設計隊的99題練習題(48.計算兩個相當長之整數的乘積,如 1234567890123 * 1234567890123。)

 

image image

 

  image   image

 

  imageimage

程式

 

Public Class Form1
    Dim a As Decimal
    Dim b As Decimal
    Dim k
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = TextBox1.Text
        b = TextBox2.Text
        k = a * b
        MsgBox(k)
    End Sub
End Class

2009年2月25日 星期三

數字跳動版 Lucky Seven

image

'數字跳動版 Lucky Seven
Public Class Form1
    Dim n1, k1
    Dim n2, k2
    Dim n3, k3
    Dim money, s7
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Randomize()
        money = 1000
        Timer1.Interval = 150
        Timer1.Enabled = False

        With Label1
            .AutoSize = True
            .Text = 1
            .Font = New Font("impact", 55)
            .ForeColor = Color.Yellow
            .BackColor = Color.Blue
        End With
        With Label2
            .AutoSize = True
            .Text = 2
            .Font = New Font("impact", 55)
            .ForeColor = Color.Yellow
            .BackColor = Color.Blue
        End With
        With Label3
            .AutoSize = True
            .Text = 3
            .Font = New Font("impact", 55)
            .ForeColor = Color.Yellow
            .BackColor = Color.Blue
        End With
        With Label4
            .AutoSize = True
            .Text = "$" & money
            .Font = New Font("impact", 20)
            .ForeColor = Color.Red
        End With
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        money = money - 50
        Label4.Text = "$" & money

        n1 = Int(Rnd() * 10)
        k1 = 0
        Timer1.Enabled = True

        n2 = Int(Rnd() * 10)
        k2 = 0
        Timer2.Enabled = True

        n3 = Int(Rnd() * 10)
        k3 = 0
        Timer3.Enabled = True

        If n1 = 7 Then s7 = s7 + 1
        If n2 = 7 Then s7 = s7 + 1
        If n3 = 7 Then s7 = s7 + 1
        If s7 = 3 Then money = money + 6000
        If s7 = 2 Then money = money + 600
        If s7 = 1 Then money = money + 60
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = k1
        If k1 = n1 Then Timer1.Enabled = False
        k1 = k1 + 1
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label2.Text = k2
        If k2 = n2 Then Timer2.Enabled = False
        k2 = k2 + 1
    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        Label3.Text = k3
        If k3 = n3 Then Timer3.Enabled = False
        k3 = k3 + 1
    End Sub
End Class

2009年2月24日 星期二

二個字串各一次取一個合併 -- 改用雙參數迴路

image

'講解二個字串各一次取一個合併
'改用雙參數迴路,解決不定數值均可適用問題
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r3 = "拾佰仟萬拾佰仟億拾佰仟兆"
        Dim r4 = "壹貳参肆伍陸柒"
        Dim str1 = ""

        Dim i = Len(r4) - 1
        Dim j = 1
        While i >= 1
            str1 = Mid(r4, i, 1) & Mid(r3, j, 1) & str1
            i = i - 1
            j = j + 1
        End While
        str1 = str1 & Microsoft.VisualBasic.Right(r4, 1)

        MsgBox(str1)
    End Sub
End Class

二個字串各一次取一個合併

image

'講解二個字串各一次取一個合併
Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim r3 = "拾佰仟萬拾佰仟億拾佰仟兆"

        Dim r3 = "萬仟佰拾"
        Dim r4 = "壹貳参肆伍"

        Dim str1 = ""
        For i = 1 To 4
            str1 = str1 & Mid(r4, i, 1) & Mid(r3, i, 1)
        Next
        str1 = str1 & Microsoft.VisualBasic.Right(r4, 1)
        MsgBox(str1)
    End Sub
End Class

數字轉國字大寫

改以mid函數及迴路處理

image

'數字轉國字大寫
'改以mid函數及迴路處理

Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim r1 = "0123456789"
        Dim r2 = "零壹貳参肆伍陸柒捌玖"
        Dim d = "135897"
        Dim s = d
        's = Replace(s, "1", "壹")
        's = Replace(s, "2", "貳")
        's = Replace(s, "3", "参")
        's = Replace(s, "4", "肆")
        's = Replace(s, "5", "伍")
        's = Replace(s, "6", "陸")
        's = Replace(s, "7", "柒")
        's = Replace(s, "8", "捌")
        's = Replace(s, "9", "玖")
        's = Replace(s, "0", "零")

        For i = 1 To 10
            s = Replace(s, Mid(r1, i, 1), Mid(r2, i, 1))
        Next i

        MsgBox(d & " 國字大寫為:" & s)
    End Sub
End Class

數字轉國字大寫

image

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim d = "135897"
        Dim s = d
        s = Replace(s, "1", "壹")
        s = Replace(s, "2", "貳")
        s = Replace(s, "3", "参")
        s = Replace(s, "4", "肆")
        s = Replace(s, "5", "伍")
        s = Replace(s, "6", "陸")
        s = Replace(s, "7", "柒")
        s = Replace(s, "8", "捌")
        s = Replace(s, "9", "玖")
        s = Replace(s, "0", "零")
        MsgBox(d & " 國字大寫為:" & s)
    End Sub
End Class

2009年2月23日 星期一

數字跳動3字自動停止版

image

'簡易版數字變化效果
'到一定數字會停止

'擴為3個字

Public Class Form1
    Dim i1, i2, i3
    Dim n1, n2, n3
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Randomize()
        Timer1.Interval = 150
        Timer1.Enabled = False
        Timer2.Interval = 150
        Timer2.Enabled = False
        Timer3.Interval = 150
        Timer3.Enabled = False

        '格式設定
        With Label1
            .BackColor = Color.Blue
            .ForeColor = Color.Yellow
            .Font = New Font("Arial Black", 50)
            .AutoSize = True
        End With
        With Label2
            .BackColor = Color.Blue
            .ForeColor = Color.Yellow
            .Font = New Font("Arial Black", 50)
            .AutoSize = True
        End With
        With Label3
            .BackColor = Color.Blue
            .ForeColor = Color.Yellow
            .Font = New Font("Arial Black", 50)
            .AutoSize = True
        End With
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = i1
        If i1 = n1 Then Timer1.Enabled = False
        i1 = i1 + 1
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label2.Text = i2
        If i2 = n2 Then Timer2.Enabled = False
        i2 = i2 + 1
    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        Label3.Text = i3
        If i3 = n3 Then Timer3.Enabled = False
        i3 = i3 + 1
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        i1 = 0
        Timer1.Enabled = True
        n1 = Int(Rnd() * 10)

        i2 = 0
        Timer2.Enabled = True
        n2 = Int(Rnd() * 10)

        i3 = 0
        Timer3.Enabled = True
        n3 = Int(Rnd() * 10)
    End Sub

End Class

簡易版數字變化自動停止版

 

image

'簡易版數字變化效果
'到一定數字會停止

Public Class Form1
    Dim i
    Dim n1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Randomize()
        Timer1.Interval = 50
        Timer1.Enabled = False
        i = 0

        '格式設定
        With Label1
            .BackColor = Color.Blue
            .ForeColor = Color.Yellow
            .Font = New Font("Arial Black", 60)
            .AutoSize = True
        End With
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = i
        If i = n1 Then Timer1.Enabled = False
        i = i + 1
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        i = 0
        Timer1.Enabled = True
        n1 = Int(Rnd() * 10)
    End Sub
End Class

簡易版數字變化效果

image

'簡易版數字變化效果
Public Class Form1
    Dim i
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 500
        Timer1.Enabled = True
        i = 0

        '格式設定
        With Label1
            .BackColor = Color.Blue
            .ForeColor = Color.Yellow
            .Font = New Font("Arial Black", 60)
            .AutoSize = True
        End With
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = i
        i = i + 1
    End Sub
End Class