0% found this document useful (0 votes)
60 views6 pages

Label3.Text Val (Textbox1.Text) - Val (Textbox2.Text)

The document contains code snippets in Visual Basic programming language across multiple chapters. The code covers topics such as: 1) If/Else conditional statements to check values in text boxes and assign outputs 2) Calculations using values from text boxes and assigning results to other text boxes 3) Select Case statements to check values and assign outputs based on conditions 4) For loops to iterate from 1 to a number and perform calculations on each iteration 5) Random number generation and checking for a target number with MsgBox output

Uploaded by

劉又齊
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views6 pages

Label3.Text Val (Textbox1.Text) - Val (Textbox2.Text)

The document contains code snippets in Visual Basic programming language across multiple chapters. The code covers topics such as: 1) If/Else conditional statements to check values in text boxes and assign outputs 2) Calculations using values from text boxes and assigning results to other text boxes 3) Select Case statements to check values and assign outputs based on conditions 4) For loops to iterate from 1 to a number and perform calculations on each iteration 5) Random number generation and checking for a target number with MsgBox output

Uploaded by

劉又齊
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CH1 If (Val(TextBox1.Text) < 0.

8) Then
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBox2.Text = "近視"
Label3.Text = Val(TextBox1.Text) - Val(TextBox2.Text) Else
End Sub TextBox2.Text = "視力正常"
CH2 End If
Module Module1 3.
Dim name As String Dim a As Integer = Val(TextBox1.Text)
Sub Main() Dim b As Integer = Val(TextBox2.Text)
name = InputBox("請輸入名字?") Dim c As Integer = Val(TextBox3.Text)
MsgBox("Hello," & name) If (((a + b) > c) And ((b + c) > a) And ((a + c) > b)) Then
End Sub TextBox4.Text = "可以構成三角形"
End Module Else
CH3 TextBox4.Text = "無法構成三角形"
1. End If
Dim sum As Integer CH5
Dim average As Single 1.Dim X As Double = Val(TextBox1.Text)
sum = Val(TextBox1.Text) + Val(TextBox2.Text) + Val(TextBox3.Text) If X < 36 Then
average = sum / 3 TextBox2.Text = "體溫過低"
TextBox4.Text = sum ElseIf (X >= 36 And X < 38) Then
TextBox5.Text = average TextBox2.Text = "體溫正常"
2. ElseIf (X >= 38 And X < 39) Then
TextBox3.Text = (Val(TextBox1.Text) * 12 + Val(TextBox2.Text)) * 2.54 TextBox2.Text = "體溫有點燒"
3. Else
Dim dblX As Double TextBox2.Text = "體溫很燒"
Dim intM As Integer End If
dblX = Val(TextBox1.Text) 2. Dim X As Double = Val(TextBox1.Text)
intM = (Int((dblX - 1.25) / 0.25)) * 5 + 70 If X < 36 Then
TextBox2.Text = intM TextBox2.Text = "體溫過低"
4. ElseIf (X >= 36 And X < 38) Then
TextBox2.Text = Int((Val(TextBox1.Text) - 1) / 5) + 1 TextBox2.Text = "體溫正常"
5. ElseIf (X >= 38 And X < 39) Then
Dim intX As Integer, intY As Integer TextBox2.Text = "體溫有點燒"
intX = Val(TextBox1.Text) \ 12 Else
intY = Val(TextBox1.Text) Mod 12 TextBox2.Text = "體溫很燒"
TextBox2.Text = intX * 200 + intY * 20 End If
CH4 3. Dim A As Double = Val(TextBox1.Text)
1. Dim B As Double = Val(TextBox2.Text)
If (Val(TextBox1.Text) < 0) Then Dim C As Double = Val(TextBox3.Text)
TextBox2.Text = -Val(TextBox1.Text) If A > B Then
Else If A > C Then
TextBox2.Text = Val(TextBox1.Text) TextBox4.Text = "A 為最大值"
End If Else
2. TextBox4.Text = "C 為最大值"
End If TextBox2.Text = "丙等"
Else Case Else
If B > C Then TextBox2.Text = "丁等"
TextBox4.Text = "B 為最大值" End Select
Else 7. Dim X As Double = Val(TextBox1.Text)
TextBox4.Text = "C 為最大值" Select Case X
End If Case Is >= 90
End If TextBox2.Text = "優等"
4. Dim X As Integer = Val(TextBox1.Text) Case Is >= 80
Select Case Val(TextBox1.Text) TextBox2.Text = "甲等"
Case Is = 1 Case Is >= 70
TextBox2.Text = 100 TextBox2.Text = "乙等"
Case 2 To 5 Case Is >= 60
TextBox2.Text = X * 100 * 0.9 TextBox2.Text = "丙等"
Case 6 To 10 Case Else
TextBox2.Text = X * 100 * 0.8 TextBox2.Text = "丁等"
Case 11 To 20 End Select
TextBox2.Text = X * 100 * 0.7
Case Else
TextBox2.Text = X * 100 * 0.6 CH6
End Select 1. Dim n As Integer = Val(TextBox1.Text)
5. Dim X As Integer = Val(TextBox1.Text) Dim result As Integer = 1
Select Case Val(TextBox1.Text) For i As Integer = 1 To n
Case Is = 1 result = result * i
TextBox2.Text = 100 Next
Case 2 To 5 TextBox2.Text = result
TextBox2.Text = X * 100 * 0.9 2. Dim n As Integer = Val(TextBox1.Text)
Case 6 To 10 Dim sum As Integer = 0
TextBox2.Text = X * 100 * 0.8 For i As Integer = 1 To n
Case 11 To 20 sum = sum + i ^ 2
TextBox2.Text = X * 100 * 0.7 Next
Case Else 3. Dim n As Integer = Val(TextBox1.Text)
TextBox2.Text = X * 100 * 0.6 Dim sum As Integer = 0
End Select For i As Integer = 1 To n
6. Dim X As Double = Val(TextBox1.Text) sum = sum + i ^ 2
Select Case X Next
Case Is >= 90 4. Dim n As Integer = Val(TextBox1.Text)
TextBox2.Text = "優等" Dim sum As Integer = 0
Case Is >= 80 For i As Integer = 1 To n
TextBox2.Text = "甲等" sum = sum + i ^ 2
Case Is >= 70 Next
TextBox2.Text = "乙等" 5. Dim sum As Integer = 0
Case Is >= 60 Dim i As Integer = 0
Do While (sum <= 10000) TextBox1.Text = TextBox1.Text & vbNewLine
i=i+1 i=i+1
sum = sum + i ^ 3 Loop
TextBox1.Text = TextBox1.Text & "i=" & i & ",sum=" & sum & vbNewLine 5. Randomize()
Loop Dim n As Integer
TextBox1.Text = TextBox1.Text & "最小值為" & i Do
n = CInt(Int(6 * Rnd())) + 1
CH7 MsgBox("點數為" & n)
1. For i As Integer = 1 To 19 If (n = 6) Then
For j As Integer = 1 To 19 Exit Do
TextBox1.Text = TextBox1.Text & i & "*" & j & "=" & i * j & " " End If
Next Loop While (1)
TextBox1.Text = TextBox1.Text & vbNewLine CH8
Next 1. Public Class Form1
2. For i As Integer = 1 To 19 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For j As Integer = 1 To 19 Randomize()
TextBox1.Text = TextBox1.Text & i & "*" & j & "=" & i * j & " " Dim score(9) As Integer
Next Dim max As Integer = 0
TextBox1.Text = TextBox1.Text & vbNewLine For i As Integer = 0 To 9
Next score(i) = CInt(Int(101 * Rnd()))
3. Dim i As Integer = 1 TextBox1.Text = TextBox1.Text & score(i) & ","
Do While (i <= 5) If max < score(i) Then
For j As Integer = (5 - i) To 1 Step -1 max = score(i)
TextBox1.Text = TextBox1.Text & " " End If
Next Next
For j As Integer = 1 To i TextBox1.Text = TextBox1.Text & "max=" & max
TextBox1.Text = TextBox1.Text & "*" End Sub
Next End Class
TextBox1.Text = TextBox1.Text & vbNewLine 2. Public Class Form1
i=i+1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Loop Randomize()
4. Dim i As Integer = 1 Dim score(9) As Integer
Dim j As Integer Dim max As Integer = 0
Do While (i <= 4) For i As Integer = 0 To 9
j=1 score(i) = CInt(Int(101 * Rnd()))
Do While (j <= 4) TextBox1.Text = TextBox1.Text & score(i) & ","
If (i = j) Then If max < score(i) Then
TextBox1.Text = TextBox1.Text & "1" max = score(i)
Else End If
TextBox1.Text = TextBox1.Text & "0" Next
End If TextBox1.Text = TextBox1.Text & "max=" & max
j=j+1 End Sub
Loop End Class
End If
CH9 TextBox1.Text = TextBox1.Text & "score(" & i & ")=" & score(i) & vbNewLine
1. Public Class Form1 Next
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBox1.Text = TextBox1.Text & "min=" & min
Randomize() End Sub
Dim score(9) As Integer End Class
Dim max As Integer = 0 2. Public Class Form1
For i As Integer = 0 To 9 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
score(i) = CInt(Int(101 * Rnd())) Dim score() = {60, 90, 44, 98, 50}
TextBox1.Text = TextBox1.Text & score(i) & "," Dim max As Integer = score(0)
If max < score(i) Then Dim max_index As Integer
max = score(i) TextBox1.Text = TextBox1.Text & "score(0)=" & score(0) & vbNewLine
End If For i = 1 To 4
Next If (max < score(i)) Then
TextBox1.Text = TextBox1.Text & "max=" & max max = score(i)
End Sub max_index = i
End Class End If
2. Public Class Form1 TextBox1.Text = TextBox1.Text & "score(" & i & ")=" & score(i) & vbNewLine
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Next
Randomize() TextBox1.Text = TextBox1.Text & "陣列 score 第" & max_index + 1 & "元素為最大值,
Dim score(9) As Integer A 其值為" & max
Dim max As Integer = 0 End Sub
For i As Integer = 0 To 9 End Class
score(i) = CInt(Int(101 * Rnd())) 3.
TextBox1.Text = TextBox1.Text & score(i) & "," CH11
If max < score(i) Then 1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
max = score(i) For i As Integer = 10 To 99
End If Dim sum As Integer = 0
Next For j As Integer = 1 To i - 1
TextBox1.Text = TextBox1.Text & "max=" & max If (i Mod j) = 0 Then
End Sub sum = sum + j
End Class End If
Next
If sum > i Then
CH10 TextBox1.Text = TextBox1.Text & i & "為盈數" & vbNewLine
1. Public Class Form1 ElseIf sum < i Then
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBox1.Text = TextBox1.Text & i & "為虧數" & vbNewLine
Dim score() = {60, 90, 44, 98, 50} Else
Dim min As Integer = score(0) TextBox1.Text = TextBox1.Text & i & "為完全數" & vbNewLine
TextBox1.Text = TextBox1.Text & "score(0)=" & score(0) & vbNewLine End If
For i = 1 To 4 Next
If (min > score(i)) Then End Sub
min = score(i) End Class
2. Public Class Form1 Dim sex As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click sex = Val(Mid(TextBox1.Text, 2, 1))
For i As Integer = 1000 To 9999 If sex = 1 Then
Dim a As Integer = Int(i / 1000) TextBox2.Text = "是男生"
Dim b As Integer = Int((i Mod 1000) / 100) Else
Dim c As Integer = Int((i Mod 100) / 10) TextBox2.Text = "是女生"
Dim d As Integer = Int(i Mod 10) End If
Dim sum As Integer = a ^ 4 + b ^ 4 + c ^ 4 + d ^ 4 End Sub
If sum = i Then End Class
TextBox1.Text = TextBox1.Text & i & "為阿姆斯壯數" & vbNewLine 4. Public Class Form1
End If Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Next Dim sum As Integer = 0
End Sub For i As Integer = 1 To TextBox1.Text.Length
End Class sum = sum + Val(Mid(TextBox1.Text, i, 1))
CH12 Next
1. Public Class Form1 If sum Mod 3 = 0 Then
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBox2.Text = "是 3 的倍數"
TextBox2.Text = Fac(Val(TextBox1.Text)) Else
End Sub TextBox2.Text = "不是 3 的倍數"
Function Fac(ByVal n As Integer) As Integer End If
Dim result As Integer = 1 End Sub
For i As Integer = 2 To n End Class
result = result * i 5. Public Class Form1
Next Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Return result Dim A As Integer = Val(TextBox1.Text)
End Function Dim B As Integer = Val(TextBox2.Text)
End Class Dim C As Integer = Val(TextBox3.Text)
2. Public Class Form1 TextBox4.Text = Math.Max(Math.Max(A, B), C)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click End Sub
TextBox3.Text = GCD(Val(TextBox1.Text), Val(TextBox2.Text)) End Class
End Sub CH13
Function GCD(ByVal A As Integer, ByVal B As Integer) As Integer 1. Public Class Form1
Dim R As Integer Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Do Dim x As Integer
R = A Mod B x = sum(Val(TextBox1.Text))
A=B TextBox2.Text = TextBox2.Text & x & vbNewLine
B=R End Sub
Loop While (B <> 0) Function sum(ByVal n As Integer) As Integer
Return A Dim result As Integer
End Function If n = 1 Then
End Class result = 1
3. Public Class Form1 Else
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click result = sum(n - 1) + n
End If Dim score As Integer = 10000
TextBox2.Text = TextBox2.Text & "sum(" & n & ")=" & result & vbNewLine Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Return result Dim x(3) As Integer
End Function Dim num As Integer = 0
End Class score = score - 200
2. Public Class Form1 Randomize()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click For i As Integer = 1 To 3
Dim m As Integer x(i) = CInt(Int(Rnd() * 7) + 1)
Dim n As Integer If i = 1 Then
Dim x As Integer Select Case (x(i))
m = Val(TextBox1.Text) Case Is = 1 到 7
n = Val(TextBox2.Text) PictureBox1.Image = My.Resources._1 到 7
x = A(m, n) End Select
TextBox3.Text = TextBox3.Text & x & vbNewLine End If
End Sub If i = 2 Then
Function A(ByVal m As Integer, ByVal n As Integer) As Integer Select Case (x(i))
If m = 0 Then 同粗體
Return n + 1 If i = 3 Then
ElseIf (m > 0 And n = 0) Then Select Case (x(i))
Return A(m - 1, 1) 同粗體
ElseIf (m > 0 And n > 0) Then Next
Return A(m - 1, A(m, n - 1)) For i As Integer = 1 To 3
End If If x(i) = 7 Then
End Function num = num + 1
End Class End If
CH14 Next
1. Public Class Form1 If num = 1 Then
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click score = score + 200
TextBox4.Text = TextBox4.Text & TextBox1.Text & vbNewLine ElseIf num = 2 Then
TextBox4.Text = TextBox4.Text & ComboBox1.SelectedItem & "年" & score = score + 500
ComboBox2.SelectedItem & "月" & ComboBox3.SelectedItem & "日" & vbNewLine ElseIf num = 3 Then
If RadioButton1.Checked = True Then score = score + 1000
TextBox4.Text = TextBox4.Text & "女生" & vbNewLine End If
End If TextBox1.Text = score
If RadioButton2.Checked = True Then End Sub
TextBox4.Text = TextBox4.Text & "男生" & vbNewLine End Class
End If
TextBox4.Text = TextBox4.Text & TextBox2.Text & vbNewLine
TextBox4.Text = TextBox4.Text & TextBox3.Text & vbNewLine
End Sub
End Class
CH15
1. Public Class Form1

You might also like