"
ทำให้ผมนั่งยิ้มอยู่คนเดียวตอนสอบเลยคับ (ประทับใจมีคนส่ง ข้อความมาให้กำลังใจ)
จำได้ด้วยว่าตอนสอบ ผมใส่ end for แทนที่จะเป็น next (หลงไปได้ไงอีกหล่ะหนอ)
อาจเป็นเพราะเวลาพิมพ์ for เสร็จ มันก็มี next ให้เลย พอไปเขียนก็เลยไม่คุ้นเคยกับคำนี้
ยังไงก็ถ้ารู้คะแนนสอบจะมาบอกอีกทีแล้วกัน
Public Class Form1
Dim i, j, k, first, last, sum, numint As Integer
Dim linelimit As Integer = 8
Dim maxvalue As Integer = 25
Dim strname, strint, strsum As String
Dim check As Boolean
Dim bypass As Boolean = False
Sub warning()
If bypass Then
bypass = False
Else
MsgBox("โปรแกรมไม่สามารถคำนวณค่าที่ระบุได้")
bypass = True
End If
btnSingle.Text = "แสดง"
btnMulti.Text = "แสดง"
txtint.Clear()
txtShow.Clear()
End Sub
Sub conStruct()
check = False
Try
numint = CInt(txtint.Text)
check = True
Catch ex As Exception
warning()
End Try
End Sub
Sub addZero()
If i.ToString.Length = 1 Then
strint = "0" & i
Else
strint = i
End If
End Sub
Sub addZero2()
If sum.ToString.Length = 1 Then
strsum = "00" & sum
ElseIf sum.ToString.Length = 2 Then
strsum = "0" & sum
Else
strsum = sum
End If
End Sub
Private Sub btnSingle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSingle.Click
conStruct()
If check Then
txtShow.Clear()
For i = 1 To 12
Try
sum = numint * i
addZero()
addZero2()
txtShow.Text &= numint & " x " & strint & " = " & strsum & vbCrLf
Catch ex As Exception
i = 12
warning()
End Try
Next
End If
End Sub
Private Sub btnMulti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMulti.Click
conStruct()
If check Then
check = False
Select Case numint
Case 2 To maxvalue
first = 2
last = numint
txtShow.Clear()
check = True
Case maxvalue + 1 To 83
first = numint - (maxvalue - 2)
last = numint
txtShow.Clear()
check = True
Case Else
warning()
End Select
If check Then
For k = first To last Step linelimit
last = k + linelimit - 1
For i = 1 To 12
addZero()
If numint <= last Then
last = numint
End If
For j = k To last
Try
sum = i * j
addZero2()
txtShow.Text &= j & " x " & strint & " = " & strsum & " "
Catch ex As Exception
j = last
warning()
End Try
Next
txtShow.Text &= vbCrLf
Next
txtShow.Text &= vbCrLf
Next
End If
End If
End Sub
Private Sub txtint_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtint.TextChanged
Try
numint = CInt(txtint.Text)
Select Case numint
Case 2 To maxvalue
first = numint
btnMulti.Text = "แม่ 2 - " & numint
Case maxvalue + 1 To 83
first = numint - (maxvalue - 2)
btnMulti.Text = "แม่ " & first & " - " & numint
Case Else
btnMulti.Text = "Not Work"
End Select
btnSingle.Text = "แม่ " & numint
Catch ex As Exception
warning()
End Try
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class