2019年5月18日 星期六
11800-1060306
Public Class Form1
Dim d(100, 4)
Dim rno As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rdata()
For i = 1 To rno
If d(i, 4) = "" Then sp1(i)
If d(i, 4) = "" Then sp2(i)
If d(i, 4) = "" Then sp3(i)
Next
wdata()
End Sub
Sub rdata()
FileOpen(1, "C:\940306.sm", OpenMode.Input)
rno = 0
Do While Not EOF(1)
rno += 1
Input(1, d(rno, 1)) : Input(1, d(rno, 2)) : Input(1, d(rno, 3))
Loop
FileClose()
End Sub
Sub sp1(ByVal i)
Dim id = d(i, 1)
If id Like "[A-Z]#########" Then Else d(i, 4) = "FORMAT ERROR"
End Sub
Sub sp2(ByVal i)
Dim D1S = Mid(d(i, 1), 2, 1) & d(i, 3)
If (D1S = "1M") Or (D1S = "2F") Then Else d(i, 4) = "SEX CODE ERROR"
End Sub
Sub sp3(ByVal i)
Dim s26 = "ABCDEFGHJKLMNPQRSTUVXYWZIO"
Dim L1 = Mid(d(i, 1), 1, 1)
Dim X12 = InStr(s26, L1) + 9
Dim x1 = X12 \ 10
Dim x2 = X12 Mod 10
Dim D1 = Mid(d(i, 1), 2, 1)
Dim D2 = Mid(d(i, 1), 3, 1)
Dim D3 = Mid(d(i, 1), 4, 1)
Dim D4 = Mid(d(i, 1), 5, 1)
Dim D5 = Mid(d(i, 1), 6, 1)
Dim D6 = Mid(d(i, 1), 7, 1)
Dim D7 = Mid(d(i, 1), 8, 1)
Dim D8 = Mid(d(i, 1), 9, 1)
Dim D9 = Mid(d(i, 1), 10, 1)
Dim y = x1 + 9 * x2 + 8 * D1 + 7 * D2 + 6 * D3 + 5 * D4 + 4 * D5 + 3 * D6 + 2 * D7 + D8 + D9
If y Mod 10 = 0 Then Else d(i, 4) = "CHECK SUM ERROR"
End Sub
Sub wdata()
DGV.columns.add("ID NO", "ID NO")
DGV.Columns.Add("NAME", "NAME")
DGV.Columns.Add("SEX", "SEX")
DGV.Columns.Add("ERROR", "ERROR")
For i = 1 To rno
DGV.Rows.Add(d(i, 1), d(i, 2), d(i, 3), d(i, 4))
Next
DGV.Sort(DGV.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
DGV.Columns(2).Width = 50
DGV.Columns(3).Width = 150
DGV.AllowUserToAddRows = False
End Sub
End Class
2018年1月31日 星期三
求最大公因數的三種表示法
| 一 | Function GCD(ByVal a%, ByVal b%) Do Until a = b If a > b Then a -= b If a < b Then b -= a Loop GCD = a End Function |
| 二 | Function GCD(ByVal a%, ByVal b%) GCD = If(b = 0, a, GCD(b, a Mod b)) End Function |
| 三 | Function GCD(ByVal a%, ByVal b%) If b = 0 Then GCD = a Else GCD = GCD(b, a Mod b) End If End Function |
2017年12月20日 星期三
軟體設計丙級術科程式碼
![]() |
| 1060301至1060305 |
Public Class Form1
'*******************************
'* 11900-1060301 Program Start *
'*******************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n As Long
FileOpen(1, "c:\1060301.txt", OpenMode.Input
)
Input(1, n)
FileClose()
Dim Q, n1 As Long
Q = n
For i = 1 To 9
n1 = n1 * 10 + Q Mod 10
Q = Q \ 10
If Q = 0 Then Exit For
Next
If n = n1 Then
TextBox1.Text = "第一題結果:" & n & " is a palindrome."
Else
TextBox1.Text = "第一題結果:" & n & " is not a palindrome."
End If
End Sub
'*******************************
'* 11900-1060302 Program Start *
'*******************************
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim n As Integer
FileOpen(1, "C:\1060302.txt", OpenMode.Input
)
Input(1, n)
FileClose()
Dim i, j As Integer
Dim ans As String
ans = "第二題結果:" & vbNewLine
For i = 1 To n
For j = 1 To i
ans &= j
Next
ans &= vbNewLine
Next
TextBox2.Text = ans
End Sub
'*******************************
'* 11900-1060303 Program Start *
'*******************************
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim n As Integer
FileOpen(1, "C:\1060303.txt", OpenMode.Input
)
Input(1, n)
FileClose()
Dim c = 0
For i = 2 To n ^ 0.5
If n Mod i = 0 Then c += 1
Next
If c = 0 Then
TextBox3.Text = "第三題結果:" & n & " is a prime number."
Else
TextBox3.Text = "第三題結果:" & n & " is not a prime number."
End If
End Sub
'*******************************
'* 11900-1060304 Program Start *
'*******************************
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim i, h, w As Integer
Dim bmi, min As Integer
min = Integer.MaxValue
FileOpen(1, "C:\1060304.txt", OpenMode.Input
)
For i = 1 To 3
Input(1, h) : Input(1, w)
bmi = w / (h / 100) ^ 2
If bmi < min Then min = bmi
Next
FileClose()
Dim ans As String
If min >= 20 And min <= 25 Then ans = "正常" Else ans = "不正常"
TextBox4.Text = "第四題結果:最小 BMI 值=" & min & "," & ans
End Sub
'*******************************
'* 11900-1060305 Program Start *
'*******************************
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim a(2, 2), b(2, 2), c(2, 2) As Integer
FileOpen(1, "C:\1060305.txt", OpenMode.Input
)
Input(1, a(1, 1)) : Input(1, a(1, 2))
Input(1, a(2, 1)) : Input(1, a(2, 2))
Input(1, b(1, 1)) : Input(1, b(1, 2))
Input(1, b(2, 1)) : Input(1, b(2, 2))
FileClose()
For i = 1 To 2
For j = 1 To 2
c(i, j) = a(i, j) + b(i, j)
Next
Next
TextBox5.Text = "第五題結果:" & vbNewLine & _
"[" & c(1, 1) & vbTab & c(1, 2) & "]" & vbNewLine & _
"[" & c(2, 1) & vbTab & c(2, 2) & "]"
End Sub
End Class
2017年12月13日 星期三
11900-1060302
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim n As Integer
FileOpen(1, "c:\1060302.txt", OpenMode.Input)
Input(1, n)
FileClose()
Dim i, j As Integer
Dim ans As String
ans = "第二題結果:" & vbNewLine
For i = 1 To n
For j = 1 To i
ans &= j
Next
ans &= vbNewLine
Next
TextBox2.Text = ans
End Sub
11900-1060301
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n As Long
FileOpen(1, "C:\1060301.txt", OpenMode.Input)
Input(1, n)
FileClose()
Dim Q, n1 As Long
Q = n
For i = 1 To 9
n1 = n1 * 10 + Q Mod 10
Q = Q \ 10
If Q = 0 Then Exit For
Next
If n = n1 Then
TextBox1.Text = "第一題結果:" & n & " is a palindrome"
Else
TextBox1.Text = "第一題結果:" & n & " is not a palindrome"
End If
End Sub
訂閱:
文章 (Atom)

