2008年8月27日 星期三

大量作業2

最大公因數

Public Class Form1
Dim a, b, c As Int64
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
If a > b Then
c = a - 1
Else
c = b - 1
End If
Do Until a Mod c = 0 And b Mod c = 0
c = c - 1
Loop

Label2.Text = "最大公因數為" & c
End Sub
End Class

考古題1

Public Class Form1

Private Sub B0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B0.Click
If bit0.Text = 0 Then
bit0.Text = 1
Else
bit0.Text = 0
End If
End Sub
End Class

考古題2

Public Class Form1

Dim 方向 As Integer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'原來的跑馬噔程式
'Label1.Left = Label1.Left - 1
'If Label1.Left < -Label1.Width Then Label1.Left = Me.ClientSize.Width

Label1.Left = Label1.Left + 方向
If Label1.Left = 0 Then


方向 = +1
ElseIf Label1.Right = Me.ClientSize.Width Then
方向 = -1
End If
'在此加入您的程式


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
方向 = -1
End Sub
End Class

考古題3

Public Class Form1

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Button1.Text = Int(Rnd() * 10)
Timer1.Interval = Timer1.Interval ^ 1.01
If Timer1.Interval > 500 Then Timer1.Enabled = False
'請在此加入您的程式
If Timer1.Enabled = False And Timer2.Enabled = False And Timer3.Enabled = False Then
Label1.Text = "開獎完畢你中獎了嗎"
End If


End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Button2.Text = Int(Rnd() * 10)
Timer2.Interval = Timer2.Interval ^ 1.01
If Timer2.Interval > 500 Then Timer2.Enabled = False
'請在此加入您的程式
If Timer1.Enabled = False And Timer2.Enabled = False And Timer3.Enabled = False Then
Label1.Text = "開獎完畢你中獎了嗎"
End If


End Sub

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Button3.Text = Int(Rnd() * 10)
Timer3.Interval = Timer3.Interval ^ 1.01
If Timer3.Interval > 500 Then Timer3.Enabled = False
'請在此加入您的程式
If Timer1.Enabled = False And Timer2.Enabled = False And Timer3.Enabled = False Then
Label1.Text = "開獎完畢你中獎了嗎"
End If


End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Randomize()
Timer1.Interval = Rnd() * 200 + 20
Timer2.Interval = Rnd() * 200 + 20
Timer3.Interval = Rnd() * 200 + 20
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = True
Label1.Text = "開獎中,請稍候..."
End Sub
End Class

考古題4

Public Class Form1

Dim 方向 As Integer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value = ProgressBar1.Value + 方向
'請在此加入你的程式
'記得如果程式執行到一半發生錯誤時,修改後要先停止再重新執行哦!
If ProgressBar1.Value = 100 Then
方向 = -1
ElseIf ProgressBar1.Value = 0 Then
方向 = 1

End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
方向 = 1
End Sub
End Class

考題5

Public Class Form1

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Button1.Text = Int(Rnd() * 10)
Timer1.Interval = Timer1.Interval ^ 1.01
If Timer1.Interval > 500 And Button1.Text = "7" Then Timer1.Enabled = False
If Timer1.Enabled = False And Timer2.Enabled = False And Timer3.Enabled = False Then
Label1.Text = "開獎完畢,恭喜您中大獎!"
End If

End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Button2.Text = Int(Rnd() * 10)
Timer2.Interval = Timer2.Interval ^ 1.01
If Timer2.Interval > 500 And Button2.Text = "7" Then Timer2.Enabled = False
If Timer1.Enabled = False And Timer2.Enabled = False And Timer3.Enabled = False Then
Label1.Text = "開獎完畢,恭喜您中大獎!"
End If

End Sub

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Button3.Text = Int(Rnd() * 10)
Timer3.Interval = Timer3.Interval ^ 1.01
If Timer3.Interval > 500 And Button3.Text = "7" Then Timer3.Enabled = False
If Timer1.Enabled = False And Timer2.Enabled = False And Timer3.Enabled = False Then
Label1.Text = "開獎完畢,恭喜您中大獎!"
End If

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Randomize()
Timer1.Interval = Rnd() * 200 + 20
Timer2.Interval = Rnd() * 200 + 20
Timer3.Interval = Rnd() * 200 + 20
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = True
Label1.Text = "開獎中,請稍候...."
End Sub
End Class

考古題6

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 確定.Click

If 輸入.Text > 3 Or 輸入.Text < 1 Then
輸入.Text = 0
Else



玩家.Text = 輸入.Text



剩餘.Text = 剩餘.Text - 玩家.Text
If 剩餘.Text = 0 Then
結果.Text = "你輸了!"
確定.Enabled = False
Button1.Visible = True
Me.AcceptButton = Button1
Else
If 剩餘.Text Mod 4 = 1 Then
電腦.Text = 1
Else
電腦.Text = (剩餘.Text - 1) Mod 4
End If
剩餘.Text = 剩餘.Text - 電腦.Text
If 剩餘.Text = 0 Then
結果.Text = "你贏了!"
確定.Enabled = False
Button1.Visible = True
Me.AcceptButton = Button1
End If
End If
End If
輸入.Text = ""
輸入.Focus()


End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
確定.Enabled = True
Button1.Visible = False
剩餘.Text = 21
玩家.Text = ""
電腦.Text = ""
輸入.Focus()
Me.AcceptButton = 確定
End Sub
End Class

考古題7

Public Class Form1

Dim 密碼 As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If 輸入.Text = 密碼 Then
Label2.Text = "歡迎光臨"
Else
If 輸入.Text > 密碼 Then
Label2.Text = "太大了,請重新輸入"
大.Text = 輸入.Text - 1
Else
Label2.Text = "太小了,請重新輸入"
小.Text = 輸入.Text + 1
End If
輸入.Text = ""
輸入.Focus()
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
密碼 = Int(Rnd() * 9000 + 1000)
End Sub
End Class

考古題9

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
結果.Text = "不是三角形"
If CInt(a.Text) + b.Text > c.Text And CInt(a.Text) + c.Text > b.Text And CInt(b.Text) + c.Text > a.Text Then
結果.Text = "是三角形"
End If



a.SelectAll()
b.SelectAll()
c.SelectAll()
a.Focus()
End Sub
End Class

考古題10

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

最大.Text = a.Text
最小.Text = a.Text
If CInt(b.Text) > 最大.Text Then 最大.Text = b.Text
If CInt(b.Text) < 最小.Text Then 最小.Text = b.Text
If CInt(c.Text) > 最大.Text Then 最大.Text = c.Text
If CInt(c.Text) < 最小.Text Then 最小.Text = c.Text


a.SelectAll()
b.SelectAll()
c.SelectAll()
a.Focus()
End Sub


End Class

考題11



Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim d As Integer
Randomize()
TextBox1.Text = ""
Do



d = Int(Rnd() * 6) + 1
TextBox1.Text = TextBox1.Text & d & vbNewLine
Loop Until (d = 6)
End Sub
End Class

考古題12

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, gcd As Integer
a = TextBox1.Text
b = TextBox2.Text
gcd = a
Do Until a Mod gcd = 0 And b Mod gcd = 0
gcd = gcd - 1
Loop


Label4.Text = gcd
End Sub
End Class

考古題13

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim d1 As Integer, d2 As Integer
Randomize()
TextBox1.Text = ""
d1 = 0

Do
d2 = d1
d1 = Int(Rnd() * 6) + 1
TextBox1.Text = TextBox1.Text & d1 & vbNewLine
Loop Until d2 = d1


End Sub
End Class

考古題19


考古題20


考古題21


考古題23

沒有留言:

張貼留言