Imports System
Imports System.Windows.Forms
Public Class Form1
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n, m, o, p, q, r As Integer
Dim r1, s1, t1, t2, t3, t4 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
If m <> 0 Then '判断 m 是否为 0,避免除零错误
o = n + m
p = n - m
q = n * m
r = n / m
'用函数将整数转换为基数为 2 的字符串
r1 = IntToBaseString(n, 2)
s1 = IntToBaseString(m, 2)
t1 = IntToBaseString(o, 2)
t2 = IntToBaseString(p, 2)
t3 = IntToBaseString(q, 2)
t4 = IntToBaseString(r, 2)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
sb.AppendLine(r1 & " - " & s1 & " = " & t2)
sb.AppendLine(r1 & " * " & s1 & " = " & t3)
sb.AppendLine(r1 & " / " & s1 & " = " & t4)
End If
Next
Next
TextBox1.Text = sb.ToString() '次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function IntToBaseString(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
Else
buffer.Insert(0, ChrW(65 + digit - 10))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim n, m, o As Integer
Dim r1, s1, t1 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
o = n + m
'用函数将整数转换为基数为 3 的字符串
r1 = IntToBaseString(n, 3)
s1 = IntToBaseString(m, 3)
t1 = IntToBaseString(o, 3)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
Next
Next
TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function a(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
Else
buffer.Insert(0, ChrW(65 + digit - 10))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
End
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text = ""
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim n, m, o As Integer
Dim r1, s1, t1 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
o = n + m
'用函数将整数转换为基数为 9 的字符串
r1 = IntToBaseString(n, 9)
s1 = IntToBaseString(m, 9)
t1 = IntToBaseString(o, 9)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
Next
Next
TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function b(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 9 Then
buffer.Insert(0, ChrW(48 + digit))
Else
buffer.Insert(0, ChrW(55 + digit)) '9 进制大于 9 的数字从 'A' 开始
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim n, m, o As Integer
Dim r1, s1, t1 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
o = n + m
'用函数将整数转换为基数为 18 的字符串
r1 = IntToBaseString(n, 18)
s1 = IntToBaseString(m, 18)
t1 = IntToBaseString(o, 18)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
Next
Next
TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function c(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 18 Then
buffer.Insert(0, ChrW(65 + digit - 10)) '10 到 17 用 A 到 H 表示
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim n, m, o As Integer
Dim r1, s1, t1 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
o = n + m
'用函数将整数转换为基数为 26 的字符串
r1 = IntToBaseString(n, 26)
s1 = IntToBaseString(m, 26)
t1 = IntToBaseString(o, 26)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
Next
Next
TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function d(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 26 Then
buffer.Insert(0, ChrW(65 + digit - 10)) '10 到 25 用 A 到 Z 表示
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim n, m, o As Integer
Dim r1, s1, t1 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
o = n + m
'用函数将整数转换为基数为 36 的字符串
r1 = IntToBaseString(n, 36)
s1 = IntToBaseString(m, 36)
t1 = IntToBaseString(o, 36)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
Next
Next
TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function e(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 36 Then
buffer.Insert(0, ChrW(55 + digit)) '10 到 35 用 A 到 Z 之后接 0 到 5
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim n, m, o As Integer
Dim r1, s1, t1 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
o = n + m
'用函数将整数转换为基数为 62 的字符串
r1 = IntToBaseString(n, 62)
s1 = IntToBaseString(m, 62)
t1 = IntToBaseString(o, 62)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
Next
Next
TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function f(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 36 Then
buffer.Insert(0, ChrW(55 + digit)) '10 到 35 用 A 到 Z
ElseIf digit < 62 Then
buffer.Insert(0, ChrW(65 + digit - 36)) '36 到 61 用 a 到 z
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim n, m, o As Integer
Dim r1, s1, t1 As String
Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串
For n = 0 To 20
For m = 0 To 20
o = n + m
'用函数将整数转换为基数为 75 的字符串
r1 = IntToBaseString(n, 75)
s1 = IntToBaseString(m, 75)
t1 = IntToBaseString(o, 75)
'构建显示字符串
sb.AppendLine(r1 & " + " & s1 & " = " & t1)
Next
Next
TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub
Private Function g(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 36 Then
buffer.Insert(0, ChrW(55 + digit)) '10 到 35 用 A 到 Z
ElseIf digit < 62 Then
buffer.Insert(0, ChrW(65 + digit - 36)) '36 到 61 用 a 到 z
ElseIf digit < 75 Then
buffer.Insert(0, ChrW(97 + digit - 62)) '62 到 74 用 0 到 ;
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(10)
For m = 0 To random.Next(10)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 2 的字符串
r1 = IntToBaseString(n, 2)
s1 = IntToBaseString(m, 2)
t1 = IntToBaseString(o, 2)
t2 = IntToBaseString(p, 2)
t3 = IntToBaseString(q, 2)
If m <> 0 Then
t4 = IntToBaseString(r, 2)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function l(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 2 Then
buffer.Insert(0, ChrW(48 + digit))
Else
buffer.Insert(0, ChrW(65 + digit - 10))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(10)
For m = 0 To random.Next(10)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 3 的字符串
r1 = IntToBaseString(n, 3)
s1 = IntToBaseString(m, 3)
t1 = IntToBaseString(o, 3)
t2 = IntToBaseString(p, 3)
t3 = IntToBaseString(q, 3)
If m <> 0 Then
t4 = IntToBaseString(r, 3)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function m(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 3 Then
buffer.Insert(0, ChrW(48 + digit))
Else
buffer.Insert(0, ChrW(65 + digit - 10))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(10)
For m = 0 To random.Next(10)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 9 的字符串
r1 = IntToBaseString(n, 9)
s1 = IntToBaseString(m, 9)
t1 = IntToBaseString(o, 9)
t2 = IntToBaseString(p, 9)
t3 = IntToBaseString(q, 9)
If m <> 0 Then
t4 = IntToBaseString(r, 9)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function n(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 9 Then
buffer.Insert(0, ChrW(48 + digit))
Else
buffer.Insert(0, ChrW(65 + digit - 10))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(10)
For m = 0 To random.Next(10)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 18 的字符串
r1 = IntToBaseString(n, 18)
s1 = IntToBaseString(m, 18)
t1 = IntToBaseString(o, 18)
t2 = IntToBaseString(p, 18)
t3 = IntToBaseString(q, 18)
If m <> 0 Then
t4 = IntToBaseString(r, 18)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function o(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 18 Then
buffer.Insert(0, ChrW(65 + digit - 10))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(100)
For m = 0 To random.Next(100)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 26 的字符串
r1 = IntToBaseString(n, 26)
s1 = IntToBaseString(m, 26)
t1 = IntToBaseString(o, 26)
t2 = IntToBaseString(p, 26)
t3 = IntToBaseString(q, 26)
If m <> 0 Then
t4 = IntToBaseString(r, 26)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function p(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 26 Then
buffer.Insert(0, ChrW(65 + digit - 10))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(10)
For m = 0 To random.Next(10)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 36 的字符串
r1 = IntToBaseString(n, 36)
s1 = IntToBaseString(m, 36)
t1 = IntToBaseString(o, 36)
t2 = IntToBaseString(p, 36)
t3 = IntToBaseString(q, 36)
If m <> 0 Then
t4 = IntToBaseString(r, 36)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function q(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 36 Then
If digit < 26 Then
buffer.Insert(0, ChrW(65 + digit - 10))
Else
buffer.Insert(0, ChrW(55 + digit - 26))
End If
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(10)
For m = 0 To random.Next(10)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 62 的字符串
r1 = IntToBaseString(n, 62)
s1 = IntToBaseString(m, 62)
t1 = IntToBaseString(o, 62)
t2 = IntToBaseString(p, 62)
t3 = IntToBaseString(q, 62)
If m <> 0 Then
t4 = IntToBaseString(r, 62)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function r(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 36 Then
buffer.Insert(0, ChrW(65 + digit - 10))
ElseIf digit < 62 Then
buffer.Insert(0, ChrW(97 + digit - 36))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
Dim n As Integer = 0
Dim m As Integer = 0
Dim o As Integer = 0
Dim p As Integer = 0
Dim q As Integer = 0
Dim r As Integer = 0
Dim r1 As String = ""
Dim s1 As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
Dim t4 As String = "" '初始化 t4 为空字符串
Dim random As New Random()
For n = 0 To random.Next(10)
For m = 0 To random.Next(10)
o = n + m
p = n - m
q = n * m
If m <> 0 Then
r = n / m
End If
'用函数将整数转换为基数为 75 的字符串
r1 = IntToBaseString(n, 75)
s1 = IntToBaseString(m, 75)
t1 = IntToBaseString(o, 75)
t2 = IntToBaseString(p, 75)
t3 = IntToBaseString(q, 75)
If m <> 0 Then
t4 = IntToBaseString(r, 75)
End If
'输出结果
TextBox1.Text &= r1 & " + " & s1 & " = " & t1 & vbCrLf
TextBox1.Text &= r1 & " - " & s1 & " = " & t2 & vbCrLf
TextBox1.Text &= r1 & " * " & s1 & " = " & t3 & vbCrLf
If m <> 0 Then
TextBox1.Text &= r1 & " / " & s1 & " = " & t4 & vbCrLf
End If
Next
Next
End Sub
Private Function s(ByVal num As Integer, ByVal base As Integer) As String
Dim buffer As New System.Text.StringBuilder(33)
Dim i As Integer = 0
Dim isNegative As Boolean = False
'处理负数
If num < 0 Then
isNegative = True
num = -num
End If
'转换为字符串
Do
Dim digit As Integer = num Mod base
If digit < 10 Then
buffer.Insert(0, ChrW(48 + digit))
ElseIf digit < 36 Then
buffer.Insert(0, ChrW(65 + digit - 10))
ElseIf digit < 62 Then
buffer.Insert(0, ChrW(97 + digit - 36))
ElseIf digit < 75 Then
buffer.Insert(0, ChrW(48 + digit - 62))
End If
num = num \ base
Loop While num > 0
'如果是负数,添加负号
If isNegative Then
buffer.Insert(0, "-")
End If
Return buffer.ToString()
End Function
End Class