Module _1110534013
'取x至小數第n位四捨五入
Function round5(x As Decimal, n As Integer)
Return Int(x * 10 ^ n + 0.5) / 10 ^ n
End Function
End Module
'內建數值函數
Dim ans = ""
ans &= "math.ABS(-2)= " & Math.Abs(-2) & vbNewLine
ans &= "math.ABS(0)= " & Math.Abs(0) & vbNewLine
ans &= "Cint(2.5)= " & CInt(2.5) & vbNewLine
ans &= "Cint(2.51)= " & CInt(2.51) & vbNewLine
ans &= "Cint(3.5)= " & CInt(3.5) & vbNewLine
ans &= "Cint(-7.5)= " & CInt(-7.5) & vbNewLine
ans &= "Int(2.4)= " & Int(2.4) & vbNewLine
ans &= "Int(-2.4)= " & Int(-2.4) & vbNewLine
ans &= "Int(-3.6)= " & Int(-3.6) & vbNewLine
ans &= "Fix(2.4)= " & Fix(2.4) & vbNewLine
ans &= "Fix(-2.4)= " & Fix(-2.4) & vbNewLine
ans &= "Fix(0.3)= " & Fix(0.3) & vbNewLine
ans &= "math.Round(5/3,2)= " & Math.Round(5 / 3, 2) & vbNewLine
ans &= "math.Round(1.665,2)= " & Math.Round(1.665, 2) & vbNewLine
ans &= "math.Ceiling(7.03)= " & Math.Ceiling(7.03) & vbNewLine
ans &= "math.Ceiling(-7.03)= " & Math.Ceiling(-7.03) & vbNewLine
ans &= "math.Floor(7.03)= " & Math.Floor(7.03) & vbNewLine
ans &= "math.Floor(-7.03)= " & Math.Floor(-7.03) & vbNewLine
ans &= "math.Truncate(7.03)= " & Math.Truncate(7.03) & vbNewLine
ans &= "math.Truncate(-7.03)= " & Math.Truncate(-7.03) & vbNewLine
ans &= "math.Sqrt(4)= " & Math.Sqrt(4) & vbNewLine
ans &= "math.Sign(4)= " & Math.Sign(4) & vbNewLine
ans &= "math.Sign(0)= " & Math.Sign(0) & vbNewLine
ans &= "math.Sign(-4)= " & Math.Sign(-4) & vbNewLine
ans &= "math.Log(2)/math.Log(10)= " & Math.Log(2) / Math.Log(10) & vbNewLine
ans &= "math.Exp(1)= " & Math.Exp(1) & vbNewLine
ans &= "math.Pow(2,10)= " & Math.Pow(2, 10) & vbNewLine
ans &= "math.Max(2, 3)= " & Math.Max(2, 3) & vbNewLine
ans &= "math.Min(2, 3)= " & Math.Min(2, 3) & vbNewLine
ans &= "math.Pi= " & Math.PI & vbNewLine
ans &= "math.E= " & Math.E & vbNewLine
ans &= "dim data(10,3) as integer" & vbNewLine
Dim data(10, 3) As Integer
ans &= "UBound(data)= " & UBound(data) & vbNewLine
ans &= "UBound(data,2)= " & UBound(data, 2) & vbNewLine
ans &= "dim data(10,3) as integer" & vbNewLine
ans &= "LBound(data)= " & LBound(data) & vbNewLine
ans &= "LBound(data,2)= " & LBound(data, 2) & vbNewLine
Dim Pi As Single = 3.14159265358979
ans &= "math.Sin(PI/6)= " & Math.Sin(Pi / 6) & vbNewLine
Me.TextBox1.Text = ans
'內建字串函數
Dim ans = ""
ans &= "Chr(65)= " & Chr(65) & vbNewLine
ans &= "Asc(A)= " & Asc("A") & vbNewLine
ans &= "Hex(Asc(王))= " & Hex(Asc("王")) & vbNewLine
ans &= "ChrW(65)= " & ChrW(65) & vbNewLine
ans &= "AscW(A)= " & AscW("A") & vbNewLine
ans &= "Hex(AscW(王))= " & Hex(AscW("王")) & vbNewLine
ans &= "Hex(16)= " & Hex(16) & vbNewLine
ans &= "Oct(16)= " & Oct(16) & vbNewLine
ans &= "Val(123)= " & Val("123") & vbNewLine
ans &= "Val(52A)= " & Val("52A") & vbNewLine
ans &= "Val(xxx)= " & Val("xxx") & vbNewLine
ans &= "Str(23)= " & Str(23) & vbNewLine
ans &= "Str(-43)= " & Str(-43) & vbNewLine
ans &= "Len(ABCDE)= " & Len("ABCDE") & vbNewLine
ans &= "Left(ABCDE,2)= " & Strings.Left("ABCDE", 2) & vbNewLine
ans &= "Right(ABCDE,2)= " & Strings.Right("ABCDE", 2) & vbNewLine
ans &= "Mid(ABCDE,2,3)= " & Mid("ABCDE", 2, 3) & vbNewLine
ans &= "UCase(AbcDe)= " & UCase("AbcDe") & vbNewLine
ans &= "LCase(AbcDe)= " & LCase("AbcDe") & vbNewLine
ans &= "Trim( A B )= " & Trim(" A B ") & vbNewLine
ans &= "LTrim( A B )= " & LTrim(" A B ") & vbNewLine
ans &= "RTrim( A B )= " & RTrim(" A B ") & vbNewLine
ans &= "StrDup(4,A)= " & StrDup(4, "A") & vbNewLine
ans &= "StrReverse(ABCDE)= " & StrReverse("ABCDE") & vbNewLine
ans &= "Rset(2.3, 5)= " & RSet(2.3, 5) & vbNewLine
ans &= "Lset(2.3, 5)= " & LSet(2.3, 5) & vbNewLine
ans &= "InStr(ABCDABCD,D)= " & InStr("ABCDABCD", "D") & vbNewLine
ans &= "InStr(ABCDEF,CC)= " & InStr("ABCDEF", "CC") & vbNewLine
ans &= "InStr(6,ABCDABCD,D)= " & InStr(6, "ABCDABCD", "D") & vbNewLine
ans &= "InStr(6,ABCDABCD,Ab))= " & InStr(6, "ABCDABCD", "Ab") & vbNewLine
ans &= "InStrRev(ABCDABCD,D)= " & InStrRev("ABCDABCD", "D") & vbNewLine
ans &= "InStrRev(ABCDABCD,D,7)= " & InStrRev("ABCDABCD", "D", 7) & vbNewLine
ans &= "Replace(ABCDE,BCD,xxx)= " & Replace("ABCDE", "BCD", "xxx") & vbNewLine
ans &= "Format(Now(), Long Time)= " & Format(Now(), "Long Time") & vbNewLine
ans &= "Format(Now(), Long Date)= " & Format(Now(), "Long Date") & vbNewLine
ans &= "Format(Now(), D)= " & Format(Now(), "D") & vbNewLine
ans &= "Format(5365.6, ##,##0.00)= " & Format(5365.6, "##,##0.00") & vbNewLine
ans &= "Format(534.9, ###0.00)= " & Format(534.9, "###0.00") & vbNewLine
ans &= "Format(2.5, 0.00%)= " & Format(2.5, "0.00%") & vbNewLine
Me.TextBox2.Text = ans
'取x至小數第n位四捨五入
Dim x As Single
Dim n As Integer
x = InputBox("x= ", "取x至小數第n位四捨五入", 0)
n = InputBox("n= ", "取x至小數第n位四捨五入", 0)
Me.TextBox3.Text = "取 " & x & " 至小數第 " & n & " 位四捨五入。" & vbNewLine & "答案為 " & round5(x, n)
'丟銅板100次
Randomize()
Dim ans = ""
For i = 1 To 100
ans &= Int(Rnd() * 2) & vbNewLine
Next
Me.TextBox4.Text = ans
'擲骰子(1-6)100次
Randomize()
Dim ans = ""
For i = 1 To 100
ans &= Int(Rnd() * 6) + 1 & vbNewLine
Next
Me.TextBox5.Text = ans
'翻牌(1-13)100次
Randomize()
Dim ans = ""
For i = 1 To 100
ans &= Int(Rnd() * 13) + 1 & vbNewLine
Next
Me.TextBox6.Text = ans
'ascii
Dim ans = "ascii 字元" & vbNewLine
For i = 32 To 127
ans &= i & vbTab & Chr(i) & vbNewLine
Next
Me.TextBox7.Text = ans
'跑馬燈
Me.Text = Strings.Right(Me.Text, Len(Me.Text) - 1) & Strings.Left(Me.Text, 1)