发信人: skydg(孤龍)
整理人: winsy(2003-03-05 15:06:31), 站内信件
|
'资料整理:飞龙
'我忘了出自那里了,总之不在国内就是了,先对作者说声对不起。
Exam0001
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim I As Integer
For I = 1 To 32768
Me.Caption = I
Next
End Sub
※错误讯息:溢位
●任务题示,请找出这一个程式码的错误!
Exam0002
--------------------------------------------------------------------------------
Private Sub Command1_Click()
A = "123"
B = "456"
C = 789
MsgBox A + B + C
End Sub
※错误讯息:124245
●任务题示,预期字串相加的结果是123456789,但答案却是124245,找出错在那里!
Exam0003
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim MyFirstNumber As Long
Dim MySecondNumber As Long
MyFirstNumber = 9
MySecondNumber = 3
MsgBox MyFirstNumber / MySecondNumbr
End Sub
※错误讯息:除以零
●任务题示,预期分子被分母除→ 9/3 =3,但结果是除以零,找出错在那里!
Exam0004
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim Count As Long
Count = Count + 1
MsgBox "总共按了" & Count & "次"
End Sub
※错误讯息:永远都是1
●任务题示,预期每按一下Count变数就会累加1次,因此答案应该会变成1,2,3,4,5......,请找出错误!
Exam0005
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim Today As Date
Today = Date
MsgBox "今天是 & Today & 时间是 & Time"
End Sub
※错误讯息:今天是 & Today & 时间是 & Time
●任务题示,预期会印出今天的日期→ 『今天是2001-7-16时间是22:26:37 』,却印出 『今天是 & Today & 时间是 & Time』,没把日期与时间印出,请找出错误!
Exam0006
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim Next As Boolean
Dim Last As Boolean
Next = True
Last = False
End Sub
※错误讯息:语法错误
●任务题示,程式码很简单,但为什堋有错误呢?请找出错误!
Exam0007
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Var I:Integer
Sum:Integer
FOR I = 1 TO 10
Sum = Sum + I
NEXT
PRINT "TOTAL=" & Sum
End Sub
※错误讯息:语法错误
●任务题示,程式码很简单,但为什堋有错误呢?请找出错误!
Exam0008
--------------------------------------------------------------------------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
Open "C:\acc.txt" For Output As #1
Print #1, KeyAscii
Close #1
NEXT End Sub
※错误讯息:与遇期结果不符
●任务题示,小民写了一个程式,只要在Text1里输入文字,文字码就会被垒记到 C:\acc.txt,但执行结果却是不管按了多少字,档案内仍只有一个数字?请找出错误!
Exam0009
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Open "C:\test.txt" For Input As #1
While EOF(1)
Line Input #1, Tmp
Text1.Text = Text1.Text & Tmp & vbNewLine
Wend
Close #1
NEXT End Sub
※错误讯息:与遇期结果不符
●任务题示,小民写了一个程式,可以把c:\test.txt内所有文字都读进text1里,但这个程式却没有读进任何资料?请找出错误!
Exam0010
--------------------------------------------------------------------------------
Private Sub Command1_Click()
SendKeys "{capslock}"
End Sub
※错误讯息:与遇期结果不符
●任务题示,小民写了一个程式,这是一个可以开关CapsLock的程式,但事实上这个程式却没有效果?请找出错误!
Exam0011
--------------------------------------------------------------------------------
Private Sub Command1_Click()
MDIForm1.Show
Form1.Show
Form2.Show
Form3.Show
For I = 0 To Forms.Count - 1
Print Forms(I).Name & Forms(I).MDIChild
Next
End Sub
※错误讯息:物件不支援此属性或方法
●任务题示,小聪明利用Forms集合想要知道一个拥有MDIForm1、Form1、Form2及Form3的VB专案,想查看所有Form的MDIChild的属性,但执行结果却发生了错误?请找出错误!
Exam0012
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Me.Move 0, 0, 800, 600
End Sub
※错误讯息:物件不支援此属性或方法
●任务题示,乱马的电脑的解析度是800*600,他想要写一个能将表单放大到整个萤幕的程式,执行後却没有被放大到整个萤幕那堋大?请找出错误!
Exam0013
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim MyShape As Shape
MyShape.Left = 1050
MyShape.Top = 1050
MyShape.Height = 1200
MyShape.Width = 1200
MyShape.FillStyle = 0
MyShape.FillColor = RGB(255, 127, 0)
MyShape.Shape = 3
MyShape.Visible = True
End Sub
※错误讯息:没有设定物件变数或with区块变数
●任务题示,某网友想要产生一个Shape物件,就用了这个方法,事实上这个方法是错的?请找出错误!
Exam0014
--------------------------------------------------------------------------------
Private Sub Command1_Click()
If month = 0 Then
year = year - 1
month = 12
If year Mod 4 = 0 Then arraydates(1) = 29
Else
If dates = 1 Then month = month - 1
dates = arraydates(month - 2)
Else
dates = dates - 1
End If
End If
End Sub
※错误讯息:有Else却没有If
●任务题示,请找出错误!
Exam0015
--------------------------------------------------------------------------------
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case KeyCode
Case vbKeyUp
Label1.Caption = "123"
End Select
End Sub
※错误讯息:与预期结果不同
●任务题示,在Text1上拼命按却没有反应,请找出错误!
Exam0016
--------------------------------------------------------------------------------
Private Sub Command1_Click()
MsgBox "Hi!" & "Hello"
End Sub
※错误讯息:与预期结果不同
●任务题示,老王想写一个由MsgBox输出成两行的程式,但却只在MsgBox里输出一行,请找出错误!
Exam0017
--------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim App As New Word.Application
App.Visible = True
App.Quit
Set App = Nothing
End Sub
※错误讯息:使用者自订型态尚未定义
●任务题示,老王想利用Automation的技术来呼叫MS Word,但执行却失败,请找出原因!
答案:
答:Integer变数整数部份所能达到的最大范围值是32767,超过会产生溢位。
答:C = 789要改成C = "789"才是字串,要不然就是改成MsgBox A + B + C,强迫使用字串加法。
答:MsgBox MyFirstNumber / MySecondNumbr打错了
应该是MsgBox MyFirstNumber / MySecondNumber。
MySecondNumbr被视为一个新的空变数,所以会造成除以零的错误。
答:Dim Count As Long改成Static Count As Long。
答:MsgBox "今天是 & Today &"修正成MsgBox "今天是" & Today & "时间是" & Time
答:Next是VB的叙述,是一个关键字,因此无法命名成其他的变数、物件、事件......等名称来使用
答:Var I:Integer不是VB的宣告法,要改成
Dim I As Integer
Dim Sum As Integer才正确
答:Open "C:\acc.txt" For Output As #1要修正成Open "C:\acc.txt" For Append As #1
答:While EOF(1)要改成While Not EOF(1),While EOF(1)的意思是说,一直做到不符合条件,EOF一开始就是为False,因此While EOF(1)就会连档案都还没有读就停止了!
答:有些按键对SendKeys来说是无效的,capslock正是旗中之一,请参考VB指令函数单元!
答:MDIForm也是Forms集合里的一员,然而MDIForm却没有MDIForm属性,因此当Forms(I)=MDIForm1世就会发生错误,所以在程式码里要判断,要改写成:
Private Sub Command1_Click()
MDIForm1.Show
Form1.Show
Form2.Show
Form3.Show
For I = 0 To Forms.Count - 1
If Forms(I).Name <> "MDIForm1" Then
Print Forms(I).Name & Forms(I).MDIChild
End If
Next
End Sub
答:单位不同,800*600是以像素为单位,但VB表单预设的单位叫作twip,因此800*600的数值不适用,因此要改写成Me.Move 0, 0, Screen.Width, Screen.Height
答:Dim MyShape As Shape只能设定MyShape是一个VB.Shape型态的变数,它只有占了一块记忆体区域,但还没有做初始化的动作,也就是MyShape只是一个空壳啦,因此要用Controls.Add来使他变成一个实体。
Private Sub Command1_Click()
Dim MyShape As Shape
Set MyShape = Controls.Add("VB.Shape", "shapex")
MyShape.Left = 1050
MyShape.Top = 1050
MyShape.Height = 1200
MyShape.Width = 1200
MyShape.FillStyle = 0
MyShape.FillColor = RGB(255, 127, 0)
MyShape.Shape = 3
MyShape.Visible = True
End Sub
答:程式码改成阶层式,很好找出问题所在。
Private Sub Command1_Click()
If month = 0 Then
year = year - 1
month = 12
If year Mod 4 = 0 Then arraydates(1) = 29
Else
If dates = 1 Then month = month - 1
dates = arraydates(month - 2)
Else
dates = dates - 1
End If
End If
End Sub
●修正答案:
Private Sub Command1_Click()
If month = 0 Then
year = year - 1
month = 12
If year Mod 4 = 0 Then arraydates(1) = 29
Else
If dates = 1 Then
month = month - 1
dates = arraydates(month - 2)
Else
dates = dates - 1
End If
End If
End Sub
●理论上上面的程式码没有错啦,事实上上面的成式码仍错误,因为Month与Year是VB里的函数,会产生引数不为选择性的错误。
答:事件写错了。
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
Label1.Caption = "123"
End Select
End Sub
答:忘了换行字元了。
Private Sub Command1_Click()
MsgBox "Hi!" & vbNewLine & "Hello"
End Sub
---- 输了你,赢了全世界又如何? |
|