2017年5月5日 星期五
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim n = 720
Dim ss = "" & n
Dim i = 2
Dim isFirst = True
While i <= n
Dim c = 0
While n Mod i = 0
n = n \ i
c = c + 1
End While
If c > 0 Then
If c = 1 Then
If isFirst Then
ss = ss & "=" & i
isFirst = False
Else
ss = ss & "*" & i
End If
Else
If isFirst Then
ss = ss & "=" & i & "^" & c
isFirst = False
Else
ss = ss & "*" & i & "^" & c
End If
End If
End If
i = i + 1
End While
MsgBox(ss)
End Sub
End Class
2014年3月3日 星期一
自己寫win LineZ 遊戲!
'2014-03-04 練習
'抄下後,鍵入於VB2010中,觀察執行結果。並請下載 linez 遊戲,試玩後比較了解,我們未完成的部份有哪些?
Public Class Form1
Dim p(81) As PictureBox
Dim pcolorMark(81) As Integer
Dim npColorMark(3) As Integer
Dim np(3) As PictureBox
Dim rBlank As Integer
Dim isBlank(81) As Boolean
Dim accScore = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
rBlank = 81
np(1) = PictureBox82
np(2) = PictureBox83
np(3) = PictureBox84
p(1) = PictureBox1
p(2) = PictureBox2
p(3) = PictureBox3
p(4) = PictureBox4
p(5) = PictureBox5
p(6) = PictureBox6
p(7) = PictureBox7
p(8) = PictureBox8
p(9) = PictureBox9
p(10) = PictureBox10
p(11) = PictureBox11
p(12) = PictureBox12
p(13) = PictureBox13
p(14) = PictureBox14
p(15) = PictureBox15
p(16) = PictureBox16
p(17) = PictureBox17
p(18) = PictureBox18
p(19) = PictureBox19
p(20) = PictureBox20
p(21) = PictureBox21
p(22) = PictureBox22
p(23) = PictureBox23
p(24) = PictureBox24
p(25) = PictureBox25
p(26) = PictureBox26
p(27) = PictureBox27
p(28) = PictureBox28
p(29) = PictureBox29
p(30) = PictureBox30
p(31) = PictureBox31
p(32) = PictureBox32
p(33) = PictureBox33
p(34) = PictureBox34
p(35) = PictureBox35
p(36) = PictureBox36
p(37) = PictureBox37
p(38) = PictureBox38
p(39) = PictureBox39
p(40) = PictureBox40
p(41) = PictureBox41
p(42) = PictureBox42
p(43) = PictureBox43
p(44) = PictureBox44
p(45) = PictureBox45
p(46) = PictureBox46
p(47) = PictureBox47
p(48) = PictureBox48
p(49) = PictureBox49
p(50) = PictureBox50
p(51) = PictureBox51
p(52) = PictureBox52
p(53) = PictureBox53
p(54) = PictureBox54
p(55) = PictureBox55
p(56) = PictureBox56
p(57) = PictureBox57
p(58) = PictureBox58
p(59) = PictureBox59
p(60) = PictureBox60
p(61) = PictureBox61
p(62) = PictureBox62
p(63) = PictureBox63
p(64) = PictureBox64
p(65) = PictureBox65
p(66) = PictureBox66
p(67) = PictureBox67
p(68) = PictureBox68
p(69) = PictureBox69
p(70) = PictureBox70
p(71) = PictureBox71
p(72) = PictureBox72
p(73) = PictureBox73
p(74) = PictureBox74
p(75) = PictureBox75
p(76) = PictureBox76
p(77) = PictureBox77
p(78) = PictureBox78
p(79) = PictureBox79
p(80) = PictureBox80
p(81) = PictureBox81
For i = 1 To 81
isBlank(i) = True
p(i).Left = ((i - 1) Mod 9) * 49 + 50
p(i).Top = ((i - 1) \ 9) * 42 + 100
pcolorMark(i) = 0
Next
For i = 1 To 3
np(i).Left = (i - 1 + 3) * 49 + 50
np(i).Top = 50
Next
Call next3colors()
Call computer_do_one_time()
End Sub
Sub next3colors()
For i = 1 To 3
Dim colorN = Int(Rnd() * 7) + 1
Select Case colorN
Case 1
np(i).Image = My.Resources.b1
npColorMark(i) = 1
Case 2
np(i).Image = My.Resources.b2
npColorMark(i) = 2
Case 3
np(i).Image = My.Resources.b3
npColorMark(i) = 3
Case 4
np(i).Image = My.Resources.b4
npColorMark(i) = 4
Case 5
np(i).Image = My.Resources.b5
npColorMark(i) = 5
Case 6
np(i).Image = My.Resources.b6
npColorMark(i) = 6
Case 7
np(i).Image = My.Resources.b7
npColorMark(i) = 7
End Select
Next
End Sub
Sub fillBlank(n As Integer)
Dim locN = Int(Rnd() * rBlank) + 1
Dim j = 1
Dim notBlankN = 0
While notBlankN < locN
If isBlank(j) = True Then notBlankN = notBlankN + 1
j = j + 1
End While
p(j - 1).Image = np(n).Image
isBlank(j - 1) = False
rBlank = rBlank - 1
pcolorMark(j - 1) = npColorMark(n)
End Sub
Sub computer_do_one_time()
Call fillBlank(1)
Call fillBlank(2)
Call fillBlank(3)
Call next3colors()
End Sub
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Call computer_do_one_time()
End Sub
Dim isClickFirst = True
Dim sourceCellN As Integer
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown, PictureBox2.MouseDown, PictureBox3.MouseDown, PictureBox4.MouseDown, PictureBox5.MouseDown,
PictureBox6.MouseDown, PictureBox7.MouseDown, PictureBox8.MouseDown, PictureBox9.MouseDown, PictureBox10.MouseDown,
PictureBox11.MouseDown, PictureBox12.MouseDown, PictureBox13.MouseDown, PictureBox14.MouseDown, PictureBox15.MouseDown,
PictureBox16.MouseDown, PictureBox17.MouseDown, PictureBox18.MouseDown, PictureBox19.MouseDown, PictureBox20.MouseDown,
PictureBox21.MouseDown, PictureBox22.MouseDown, PictureBox23.MouseDown, PictureBox24.MouseDown, PictureBox25.MouseDown,
PictureBox26.MouseDown, PictureBox27.MouseDown, PictureBox28.MouseDown, PictureBox29.MouseDown, PictureBox30.MouseDown,
Picturebox31.MouseDown, Picturebox32.MouseDown, Picturebox33.MouseDown, Picturebox34.MouseDown, Picturebox35.MouseDown,
Picturebox36.MouseDown, Picturebox37.MouseDown, Picturebox38.MouseDown, Picturebox39.MouseDown, PictureBox40.MouseDown,
Picturebox41.MouseDown, Picturebox42.MouseDown, Picturebox43.MouseDown, Picturebox44.MouseDown, Picturebox45.MouseDown,
Picturebox46.MouseDown, Picturebox47.MouseDown, Picturebox48.MouseDown, Picturebox49.MouseDown, PictureBox50.MouseDown,
Picturebox51.MouseDown, Picturebox52.MouseDown, Picturebox53.MouseDown, Picturebox54.MouseDown, Picturebox55.MouseDown,
Picturebox56.MouseDown, Picturebox57.MouseDown, Picturebox58.MouseDown, Picturebox59.MouseDown, PictureBox60.MouseDown,
Picturebox61.MouseDown, Picturebox62.MouseDown, Picturebox63.MouseDown, Picturebox64.MouseDown, Picturebox65.MouseDown,
Picturebox66.MouseDown, Picturebox67.MouseDown, Picturebox68.MouseDown, Picturebox69.MouseDown, PictureBox70.MouseDown,
Picturebox71.MouseDown, Picturebox72.MouseDown, Picturebox73.MouseDown, Picturebox74.MouseDown, Picturebox75.MouseDown,
Picturebox76.MouseDown, Picturebox77.MouseDown, Picturebox78.MouseDown, Picturebox79.MouseDown, PictureBox80.MouseDown,
PictureBox81.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
If isClickFirst = True Then
sourceCellN = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 2))
If sourceCellN = 0 Then sourceCellN = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 1))
p(sourceCellN).Size = New Size(p(sourceCellN).Size.Width + 10, p(sourceCellN).Size.Height + 10)
isClickFirst = False
Else
Dim objectCellN As Integer = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 2))
If objectCellN = 0 Then objectCellN = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 1))
p(sourceCellN).Size = New Size(p(sourceCellN).Size.Width - 10, p(sourceCellN).Size.Height - 10)
If (objectCellN <> sourceCellN) And isBlank(objectCellN) = True Then
p(objectCellN).Image = p(sourceCellN).Image
p(sourceCellN).Image = My.Resources.b0
isBlank(objectCellN) = False
isBlank(sourceCellN) = True
Call computer_do_one_time()
End If
isClickFirst = True
Call score()
End If
End If
End Sub
Sub score()
'
'
End Sub
End Class
'抄下後,鍵入於VB2010中,觀察執行結果。並請下載 linez 遊戲,試玩後比較了解,我們未完成的部份有哪些?
Public Class Form1
Dim p(81) As PictureBox
Dim pcolorMark(81) As Integer
Dim npColorMark(3) As Integer
Dim np(3) As PictureBox
Dim rBlank As Integer
Dim isBlank(81) As Boolean
Dim accScore = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
rBlank = 81
np(1) = PictureBox82
np(2) = PictureBox83
np(3) = PictureBox84
p(1) = PictureBox1
p(2) = PictureBox2
p(3) = PictureBox3
p(4) = PictureBox4
p(5) = PictureBox5
p(6) = PictureBox6
p(7) = PictureBox7
p(8) = PictureBox8
p(9) = PictureBox9
p(10) = PictureBox10
p(11) = PictureBox11
p(12) = PictureBox12
p(13) = PictureBox13
p(14) = PictureBox14
p(15) = PictureBox15
p(16) = PictureBox16
p(17) = PictureBox17
p(18) = PictureBox18
p(19) = PictureBox19
p(20) = PictureBox20
p(21) = PictureBox21
p(22) = PictureBox22
p(23) = PictureBox23
p(24) = PictureBox24
p(25) = PictureBox25
p(26) = PictureBox26
p(27) = PictureBox27
p(28) = PictureBox28
p(29) = PictureBox29
p(30) = PictureBox30
p(31) = PictureBox31
p(32) = PictureBox32
p(33) = PictureBox33
p(34) = PictureBox34
p(35) = PictureBox35
p(36) = PictureBox36
p(37) = PictureBox37
p(38) = PictureBox38
p(39) = PictureBox39
p(40) = PictureBox40
p(41) = PictureBox41
p(42) = PictureBox42
p(43) = PictureBox43
p(44) = PictureBox44
p(45) = PictureBox45
p(46) = PictureBox46
p(47) = PictureBox47
p(48) = PictureBox48
p(49) = PictureBox49
p(50) = PictureBox50
p(51) = PictureBox51
p(52) = PictureBox52
p(53) = PictureBox53
p(54) = PictureBox54
p(55) = PictureBox55
p(56) = PictureBox56
p(57) = PictureBox57
p(58) = PictureBox58
p(59) = PictureBox59
p(60) = PictureBox60
p(61) = PictureBox61
p(62) = PictureBox62
p(63) = PictureBox63
p(64) = PictureBox64
p(65) = PictureBox65
p(66) = PictureBox66
p(67) = PictureBox67
p(68) = PictureBox68
p(69) = PictureBox69
p(70) = PictureBox70
p(71) = PictureBox71
p(72) = PictureBox72
p(73) = PictureBox73
p(74) = PictureBox74
p(75) = PictureBox75
p(76) = PictureBox76
p(77) = PictureBox77
p(78) = PictureBox78
p(79) = PictureBox79
p(80) = PictureBox80
p(81) = PictureBox81
For i = 1 To 81
isBlank(i) = True
p(i).Left = ((i - 1) Mod 9) * 49 + 50
p(i).Top = ((i - 1) \ 9) * 42 + 100
pcolorMark(i) = 0
Next
For i = 1 To 3
np(i).Left = (i - 1 + 3) * 49 + 50
np(i).Top = 50
Next
Call next3colors()
Call computer_do_one_time()
End Sub
Sub next3colors()
For i = 1 To 3
Dim colorN = Int(Rnd() * 7) + 1
Select Case colorN
Case 1
np(i).Image = My.Resources.b1
npColorMark(i) = 1
Case 2
np(i).Image = My.Resources.b2
npColorMark(i) = 2
Case 3
np(i).Image = My.Resources.b3
npColorMark(i) = 3
Case 4
np(i).Image = My.Resources.b4
npColorMark(i) = 4
Case 5
np(i).Image = My.Resources.b5
npColorMark(i) = 5
Case 6
np(i).Image = My.Resources.b6
npColorMark(i) = 6
Case 7
np(i).Image = My.Resources.b7
npColorMark(i) = 7
End Select
Next
End Sub
Sub fillBlank(n As Integer)
Dim locN = Int(Rnd() * rBlank) + 1
Dim j = 1
Dim notBlankN = 0
While notBlankN < locN
If isBlank(j) = True Then notBlankN = notBlankN + 1
j = j + 1
End While
p(j - 1).Image = np(n).Image
isBlank(j - 1) = False
rBlank = rBlank - 1
pcolorMark(j - 1) = npColorMark(n)
End Sub
Sub computer_do_one_time()
Call fillBlank(1)
Call fillBlank(2)
Call fillBlank(3)
Call next3colors()
End Sub
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Call computer_do_one_time()
End Sub
Dim isClickFirst = True
Dim sourceCellN As Integer
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown, PictureBox2.MouseDown, PictureBox3.MouseDown, PictureBox4.MouseDown, PictureBox5.MouseDown,
PictureBox6.MouseDown, PictureBox7.MouseDown, PictureBox8.MouseDown, PictureBox9.MouseDown, PictureBox10.MouseDown,
PictureBox11.MouseDown, PictureBox12.MouseDown, PictureBox13.MouseDown, PictureBox14.MouseDown, PictureBox15.MouseDown,
PictureBox16.MouseDown, PictureBox17.MouseDown, PictureBox18.MouseDown, PictureBox19.MouseDown, PictureBox20.MouseDown,
PictureBox21.MouseDown, PictureBox22.MouseDown, PictureBox23.MouseDown, PictureBox24.MouseDown, PictureBox25.MouseDown,
PictureBox26.MouseDown, PictureBox27.MouseDown, PictureBox28.MouseDown, PictureBox29.MouseDown, PictureBox30.MouseDown,
Picturebox31.MouseDown, Picturebox32.MouseDown, Picturebox33.MouseDown, Picturebox34.MouseDown, Picturebox35.MouseDown,
Picturebox36.MouseDown, Picturebox37.MouseDown, Picturebox38.MouseDown, Picturebox39.MouseDown, PictureBox40.MouseDown,
Picturebox41.MouseDown, Picturebox42.MouseDown, Picturebox43.MouseDown, Picturebox44.MouseDown, Picturebox45.MouseDown,
Picturebox46.MouseDown, Picturebox47.MouseDown, Picturebox48.MouseDown, Picturebox49.MouseDown, PictureBox50.MouseDown,
Picturebox51.MouseDown, Picturebox52.MouseDown, Picturebox53.MouseDown, Picturebox54.MouseDown, Picturebox55.MouseDown,
Picturebox56.MouseDown, Picturebox57.MouseDown, Picturebox58.MouseDown, Picturebox59.MouseDown, PictureBox60.MouseDown,
Picturebox61.MouseDown, Picturebox62.MouseDown, Picturebox63.MouseDown, Picturebox64.MouseDown, Picturebox65.MouseDown,
Picturebox66.MouseDown, Picturebox67.MouseDown, Picturebox68.MouseDown, Picturebox69.MouseDown, PictureBox70.MouseDown,
Picturebox71.MouseDown, Picturebox72.MouseDown, Picturebox73.MouseDown, Picturebox74.MouseDown, Picturebox75.MouseDown,
Picturebox76.MouseDown, Picturebox77.MouseDown, Picturebox78.MouseDown, Picturebox79.MouseDown, PictureBox80.MouseDown,
PictureBox81.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
If isClickFirst = True Then
sourceCellN = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 2))
If sourceCellN = 0 Then sourceCellN = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 1))
p(sourceCellN).Size = New Size(p(sourceCellN).Size.Width + 10, p(sourceCellN).Size.Height + 10)
isClickFirst = False
Else
Dim objectCellN As Integer = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 2))
If objectCellN = 0 Then objectCellN = Val(Microsoft.VisualBasic.Right(CType(sender, PictureBox).Name, 1))
p(sourceCellN).Size = New Size(p(sourceCellN).Size.Width - 10, p(sourceCellN).Size.Height - 10)
If (objectCellN <> sourceCellN) And isBlank(objectCellN) = True Then
p(objectCellN).Image = p(sourceCellN).Image
p(sourceCellN).Image = My.Resources.b0
isBlank(objectCellN) = False
isBlank(sourceCellN) = True
Call computer_do_one_time()
End If
isClickFirst = True
Call score()
End If
End If
End Sub
Sub score()
'
'
End Sub
End Class
2013年12月11日 星期三
Loop_Array Sample
'抄下後,鍵入於VB2010中,觀察執行結果。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim msg = ""
'陣列
Dim na() = {"趙一", "林二", "張三", "李四", "王五", "方六", "白七", "周八", "陳九"}
Dim ch() = {90, 100, 60, 75, 50, 80, 99, 88, 0}
''平均
Dim s = 0
For i = 0 To na.Length - 1
s = s + ch(i)
Next
msg = msg & "平均:" & Int(s / na.Length + 0.5) & "分" & vbNewLine
'最高分
Dim ma = ch(0)
For i = 1 To na.Length - 1
If ch(i) > ma Then ma = ch(i)
Next
msg = msg & "最高:" & ma & "分" & vbNewLine
'最低分
Dim mi = ch(0)
For i = 1 To na.Length - 1
If ch(i) < mi Then mi = ch(i)
Next
msg = msg & "最低:" & mi & "分" & vbNewLine
'李四考?
Dim ss = "李四"
Dim sn = ""
Dim isfound = False
For i = 0 To na.Length - 1
If na(i) = ss Then
sn = ch(i)
isfound = True
Exit For
End If
Next
If isfound = True Then
msg = msg & ss & ":" & sn & "分" & vbNewLine
End If
msg = msg & vbNewLine
'80分以上有多少人?
Dim c = 0
For i = 0 To na.Length - 1
If ch(i) >= 80 Then c = c + 1
Next
msg = msg & "80分以上有" & c & "人" & vbNewLine
'80分以上是那些人?
For i = 0 To na.Length - 1
If ch(i) >= 80 Then msg = msg & na(i) & "考" & ch(i) & "分" & vbNewLine
Next
MsgBox(msg)
End
End Sub
End Class
'如出現雜訊,請改以Chrome 開啓
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim msg = ""
'陣列
Dim na() = {"趙一", "林二", "張三", "李四", "王五", "方六", "白七", "周八", "陳九"}
Dim ch() = {90, 100, 60, 75, 50, 80, 99, 88, 0}
''平均
Dim s = 0
For i = 0 To na.Length - 1
s = s + ch(i)
Next
msg = msg & "平均:" & Int(s / na.Length + 0.5) & "分" & vbNewLine
'最高分
Dim ma = ch(0)
For i = 1 To na.Length - 1
If ch(i) > ma Then ma = ch(i)
Next
msg = msg & "最高:" & ma & "分" & vbNewLine
'最低分
Dim mi = ch(0)
For i = 1 To na.Length - 1
If ch(i) < mi Then mi = ch(i)
Next
msg = msg & "最低:" & mi & "分" & vbNewLine
'李四考?
Dim ss = "李四"
Dim sn = ""
Dim isfound = False
For i = 0 To na.Length - 1
If na(i) = ss Then
sn = ch(i)
isfound = True
Exit For
End If
Next
If isfound = True Then
msg = msg & ss & ":" & sn & "分" & vbNewLine
End If
msg = msg & vbNewLine
'80分以上有多少人?
Dim c = 0
For i = 0 To na.Length - 1
If ch(i) >= 80 Then c = c + 1
Next
msg = msg & "80分以上有" & c & "人" & vbNewLine
'80分以上是那些人?
For i = 0 To na.Length - 1
If ch(i) >= 80 Then msg = msg & na(i) & "考" & ch(i) & "分" & vbNewLine
Next
MsgBox(msg)
End
End Sub
End Class
Loop_Array Sample
'抄下後,鍵入於VB2010中,觀察執行結果。
'如出現雜訊,請改以Chrome 開啓
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim na() = {"趙一", "李四", "張三", "李四", "王五", "方六"}
Dim ch() = {90, 60, 100, 75, 50, 80}
Dim msg = ""
'平均
Dim s = 0
For i = 0 To 5
s = s + ch(i)
Next
msg = msg & "平均:" & Int(s / 6 + 0.5) & "分" & vbNewLine
'最高分
Dim ma = ch(0)
Dim t = ""
For i = 1 To 5
If ch(i) > ma Then
ma = ch(i)
t = na(i)
End If
Next
msg = msg & "最高分:" & ma & "分是" & t & vbNewLine
'最低分
Dim mi = ch(0)
For i = 1 To 5
If ch(i) < mi Then
mi = ch(i)
t = na(i)
End If
Next
msg = msg & "最低分:" & mi & "分是" & t & vbNewLine
'李四考幾分?
For i = 0 To 5
If na(i) = "李四" Then
msg = msg & "李四考" & ch(i) & "分" & vbNewLine
End If
Next
'80分以上有多少人?
msg = msg & vbNewLine
Dim c = 0
For i = 0 To 5
If ch(i) >= 80 Then
c = c + 1
End If
Next
msg = msg & "80分以上有" & c & "人" & vbNewLine
'80分以上有誰?
For i = 0 To 5
If ch(i) >= 80 Then
msg = msg & na(i) & "考" & ch(i) & "分" & vbNewLine
End If
Next
msg = msg & vbNewLine
'國文成績大於平均分數5分以上有誰?
For i = 0 To 5
If ch(i) >= Int(s / 6 + 0.5) + 5 Then
msg = msg & na(i) & "考" & ch(i) & "分-->大於平均(平均:" & Int(s / 6 + 0.5) & ")5分以上" & vbNewLine
End If
Next
MsgBox(msg)
End
End Sub
End Class
'如出現雜訊,請改以Chrome 開啓
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim na() = {"趙一", "李四", "張三", "李四", "王五", "方六"}
Dim ch() = {90, 60, 100, 75, 50, 80}
Dim msg = ""
'平均
Dim s = 0
For i = 0 To 5
s = s + ch(i)
Next
msg = msg & "平均:" & Int(s / 6 + 0.5) & "分" & vbNewLine
'最高分
Dim ma = ch(0)
Dim t = ""
For i = 1 To 5
If ch(i) > ma Then
ma = ch(i)
t = na(i)
End If
Next
msg = msg & "最高分:" & ma & "分是" & t & vbNewLine
'最低分
Dim mi = ch(0)
For i = 1 To 5
If ch(i) < mi Then
mi = ch(i)
t = na(i)
End If
Next
msg = msg & "最低分:" & mi & "分是" & t & vbNewLine
'李四考幾分?
For i = 0 To 5
If na(i) = "李四" Then
msg = msg & "李四考" & ch(i) & "分" & vbNewLine
End If
Next
'80分以上有多少人?
msg = msg & vbNewLine
Dim c = 0
For i = 0 To 5
If ch(i) >= 80 Then
c = c + 1
End If
Next
msg = msg & "80分以上有" & c & "人" & vbNewLine
'80分以上有誰?
For i = 0 To 5
If ch(i) >= 80 Then
msg = msg & na(i) & "考" & ch(i) & "分" & vbNewLine
End If
Next
msg = msg & vbNewLine
'國文成績大於平均分數5分以上有誰?
For i = 0 To 5
If ch(i) >= Int(s / 6 + 0.5) + 5 Then
msg = msg & na(i) & "考" & ch(i) & "分-->大於平均(平均:" & Int(s / 6 + 0.5) & ")5分以上" & vbNewLine
End If
Next
MsgBox(msg)
End
End Sub
End Class
2013年11月25日 星期一
實例演練題
抄下後,鍵入於VB2010中,比較執行結果
1. Msgbox (8*3)
2. Msgbox (8/3)
3. Msgbox (8\3)
4. Msgbox (8 mod 3)
5. Msgbox (3 ^ 5)
6. Msgbox (3/3*3)
7. Msgbox (3\3*3)
8. Msgbox (3+4*5-4)
9. Msgbox (3+4*5^2-4)
10. Msgbox (3+4)*5^2-4)
11. dim a = true :dim b = true
msgbox (a and b)
12. dim a = true :dim b = true
msgbox (a or b)
13. dim a = true :dim b = true
msgbox (a xor b)
14. dim a = true :dim b = true
msgbox (not(a xor b))
15. dim a = true :dim b = false
msgbox (a and b)
16.dim a = true :dim b = false
msgbox (a or b)
17.dim a = true : dim b = false
msgbox (a xor b)
18. dim a = true :dim b = false
msgbox (not(a xor b))
19. dim a = false :dim b = false
msgbox (a and b)
20. dim a = false :dim b = false
msgbox (a or b)
21. dim a = false : dim b = false
msgbox (a xor b)
22. dim a = false : dim b = false
msgbox (not(a or b))
23 dim a = 3:dim b =4 :dim c =5:dim d=6
s = a>b and c>d
msgbox (s)
24 dim a = 3: dim b =4 :dim c =5: dim d=6
s = a>b or (d>c)
msgbox (s)
25 dim a = 3: dim b =4 :dim c =5: dim d=6
s = a>b and not(c>d)
msgbox (s)
26 dim a = 3: dim b =4 :dim c =5: dim d=6
s = a>b xor not(c>d)
msgbox (s)
27 dim a = 3: dim b =4 :dim c =5: dim d=6
s = a>b or not(c>d)
msgbox (s)
28 dim a = 3: dim b =4 :dim c =5: dim d=6
s = not(a>b) xor not(c>d)
msgbox (s)
29 dim a = 3: dim b =4 :dim c =5: dim d=6
s = not(a>b) or not(c>d)
msgbox (s)
30 dim a = 3: dim b =4 :dim c =5: dim d=6
s = a+c-b*d/2^2
msgbox (s)
2013年11月18日 星期一
訂閱:
文章 (Atom)