'輸入
Dim s As String ' = InputBox("數字 = ", "數字轉國字大寫", 0)
Try
s = My.Computer.FileSystem.ReadAllText("p37.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'處理 依序剪下每個字元查表轉換
'拆成列
Dim row = Split(s, vbNewLine)
Dim ans = ""
For j = 0 To UBound(row)
ans &= D2C(row(j))
ans &= If(j = UBound(row), "", vbNewLine)
Next
'輸出
Me.TextBox1.Text = ans
'a001
'讀入資料
Dim fc As String
Try
fc = My.Computer.FileSystem.ReadAllText("a001.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'資料字串拆成列
Dim row = Split(fc, vbNewLine)
'處理
Dim ans = ""
'For Each i In row
'ans &= "hello, " & i & vbNewLine
'Next
For i = 0 To UBound(row)
ans &= "hello, " & row(i) & If(i = UBound(row), "", vbNewLine)
Next
'輸出
Me.TextBox2.Text = ans
My.Computer.FileSystem.WriteAllText("a001.out", ans, False)
'A3. 算術運算+檔案
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("A3.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim ans = ""
Dim data
For j = 0 To UBound(row)
data = Split(row(j), ",")
Dim a, b As Integer
a = data(0)
b = data(1)
ans &= a \ b & ", " & Math.Abs(a - b) & If(j = UBound(row), "", vbNewLine)
Next
'輸出
Me.TextBox3.Text = ans
My.Computer.FileSystem.WriteAllText("A3.out", ans, False)
'A2. 數字轉地支
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("A2.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim ans = ""
For j = 0 To UBound(row)
ans &= D2Di(row(j))
ans &= If(j = UBound(row), "", vbNewLine)
Next
'輸出
Me.TextBox4.Text = ans
'A1
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("A1.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim a(13)
For Each p In row '陣列
a(p) += 1
Next
'輸出
Dim ans = RSet("數字", 2) & " " & "次數" & vbNewLine
For i = 1 To 13
ans &= RSet(i, 2) & " " & a(i) & vbNewLine
Next
Me.TextBox5.Text = ans
'B1
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("B1.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim ans = ""
Dim j As Integer
For j = 1 To s
For i = 1 To j
ans &= i
Next
ans &= vbNewLine
Next
'輸出
Me.TextBox6.Text = ans
'B2
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("B2.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim ans = ""
Dim data
For j = 0 To UBound(row)
data = Split(row(j), ",")
Dim a, b As Integer
a = data(0)
b = data(1)
ans &= a \ b & ", " & a Mod b & If(j = UBound(row), "", vbNewLine)
Next
'輸出
Me.TextBox7.Text = ans
My.Computer.FileSystem.WriteAllText("B2.out", ans, False)
'B3 數字轉天干
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("B3.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim ans = ""
For j = 0 To UBound(row)
ans &= D2Ten(row(j))
ans &= If(j = UBound(row), "", vbNewLine)
Next
'輸出
Me.TextBox9.Text = ans
'B6
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("B6.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim a(6)
For Each p In row '陣列
a(p) += 1
Next
'輸出
Dim ans = RSet("數字", 2) & " " & "次數" & vbNewLine
For i = 1 To 6
ans &= RSet(i, 2) & " " & a(i) & vbNewLine
Next
Me.TextBox8.Text = ans
'A4
'輸入
Dim s As String
Try
s = My.Computer.FileSystem.ReadAllText("A4.in")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'拆成列
Dim row = Split(s, vbNewLine)
'處理
Dim ans = ""
Dim j As Integer
For j = 1 To s
For i = 1 To j
ans &= i
Next
ans &= vbNewLine
Next
'輸出
Me.TextBox10.Text = ans
~~~~~~~~~~~~~~~~~~~~~~~模組~~~~~~~~~~~~~~~~~~~~~~~
'查表 陣列
Function D2C(s)
Dim c() = {"零", "壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖"}
Dim ans = ""
'轉國字
For i = 1 To Len(s)
ans &= c(Val(Mid(s, i, 1)))
Next
Return ans
End Function
'查表
Function D2Di(s)
Dim c() = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
Dim ans = ""
'轉地支
For i = 1 To Len(s)
ans &= c(Val(Mid(s, i, 1)))
Next
Return ans
End Function
'查表
Function D2Ten(s)
Dim c() = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
Dim ans = ""
'轉天干
For i = 1 To Len(s)
ans &= c(Val(Mid(s, i, 1)))
Next
Return ans
End Function
~~~~~~~~~~~~~~~~~~~~~~~結果~~~~~~~~~~~~~~~~~~~~~~~
沒有留言:
張貼留言