下列各題a)、b)、c)、d)四個選項中,只有一個選項是正確的,請將正確選項涂
在答題卡的相應位置上,答在試卷上不得分。
(1)以下不能在“工程資源管理器”窗口中列出的文件類型是
a).bas b).res c).fnn d).ocx
(2)以下關于窗體的描述中,錯誤的是
a)執(zhí)行unloadfoml語句后,窗體fonnl消失,但仍在內(nèi)存中
b)窗體的ioad事件在加載窗體時發(fā)生
c)當窗體的enabled屬性為false時,通過鼠標和鍵盤對窗體的操作都被禁止
d)窗體的height、width屬性用于設置窗體的高和寬
(3)下列可作為v2sualbasic變量名的是
a)a#a b)4a c)? xy d)consta
(4)設有如下的記錄類型
type student
numberas string
name as string
age as integer
end type
則正確引用該記錄類型變量的代碼是
a) student.name=”張紅” b) dim as student
s.name=”張紅”
c) dim s as type student d) dim s as type
s.name=”張紅” s.dame=”張紅”
(5)函數(shù)string(n,“str”)的功能是
a)把數(shù)值型數(shù)據(jù)轉(zhuǎn)換為字符串
b)返回由n個字符組成的字符串
c)從字符串中取出n個字符
d)從字符串中第n個字符的位置開始取子字符串
(6)將數(shù)學表達式cos2(a+b)+5e2寫成visual basic的表達式,其正確的形式是
a)cos(a+b)a2十5。exp(2) b)cos^2(a+b)+5*exp(2)
c)cos(a+b)^2十5*ln(2) d)cos^2(a+b)+5*ln(2)
(7)在窗體上畫一個命令按鈕,名稱為commandl。單擊命令按鈕時,執(zhí)行如下事件過
程:
prlvate sub commandl—c1icko
a$="software and hardware"
b(a$,8)
c$=mid(a$,1,8)
msgbox a$,,b$,c$,1
end sub
則在彈出的信息框的標題欄中顯示的信息是
a)software and hardware b)software c)hardwafe d)1
(8)執(zhí)行如下語句:
a=inutbox(”today”,”tomorrow,”yesterday”,,,"day before yesterday",5)
將顯示一個輸入對話框,在對話框的輸入?yún)^(qū)中顯示的信息是
a)today b)tomorrow c)yesterday d)day before yesterday
(9)表示滾動條控件取值范圍最大值的屬性是
a)max b)largechange c)value d)max—min
(10)在窗體上畫一個名稱為listl的列表框,一個名稱為labell的標簽。列表框中顯示
若干城市的名稱。當單擊列表框中的某個城市名時,在標簽中顯示選中城市的名稱。
下列能正確實現(xiàn)上述功能的程序是
a) private sub listl_click() b)private sub listl_c1ick()
labell.caption=list1.listlndex labell.nanle=listl.listindex
end sub .end sub
程序運行后,如果單擊命令按鈕,則在窗體上顯示的內(nèi)容是
a)空白 b)錯誤提示 c)北京 d)上海
11、在窗體上畫一個名稱為command1的命令按鈕,然后編寫如下事件過程:
private sub command1click()
x=0
n=inputbox(″″)
for i=1 to n
for j=1 to i
x=x+1
next j
next i
print x
end sub
程序運行后,單擊命令按鈕,如果輸入3,則在窗體上顯示的內(nèi)容是()
a、3 b、4 c、5 d、6
12、以下關于菜單的敘述中,錯誤的是()
a、在程序運行過程中可以增加或減少菜單項
b、如果把一個菜單項的enabled屬性設置為false,則可刪除該菜單項
c、彈出式菜單在菜單編輯器中設計
d、利用控件數(shù)組可以實現(xiàn)菜單項的增加或減少
13在窗體上畫三個單選按鈕,組成一個名為chkoption的控件數(shù)組。用于標識各個控件數(shù)組元素的參數(shù)是()
a、tag b、index c、listindex d、name
14在窗體上畫一個命令按鈕,名稱為command1,然后編寫如下事件過程:
option base 0
private sub command1click()
dim city as variant
city=array(″北京″,″上!澹逄旖颉,″重慶″)
print city1
end sub
程序運行后,如果單擊命令按鈕,則在窗體上顯示的內(nèi)容是()
a、空白 b、錯誤提示 c、北京 d、上海
15、假定有以下函數(shù)過程:
function fun(s as string) as string
dim s1 as string
for i=1 to len(s)
s1=ucase(mid(s,i,1))+s1
next i
fun=s1
end function
在窗體上畫一個命令按鈕,然后編寫如下事件過程:
private sub command1click()
dim str1 as string,str2 as string
str1=inputbox(″請輸入一個字符串″)
str2=fun(str1)
print str2
end sub
程序運行后,單擊命令按鈕,如果在輸入對話框中輸入字符串“abcdefg”,則單擊“確定”按鈕后在窗體上的輸出結(jié)果為()
a、abcdefg b、abcdefg c、gfedcba d、gfedcba
(16)設有語句
open "c:\test.dat" for output as#1
則以下錯誤的敘述是
a)該語句打開c盤根目錄下一個己存在的文件test.dat
b)該語句在c盤根目錄下建立一個名為test.dat的文件
c)該語句建立的文件的文件號為1
d)執(zhí)行該語句后,就可以通過print#語句向文件test.dat中寫入信息
(17)以下敘述中錯誤的是
a)用shell函數(shù)可以調(diào)用能夠在windows下運行的應用程序
b)用shell函數(shù)可以調(diào)用可執(zhí)行文件,也可以調(diào)用visualbasic的內(nèi)部函數(shù)
c)調(diào)用shell函數(shù)的格式應為:<變量名>=shell(……)
d)用shell函數(shù)不能執(zhí)行dos命令
(18)以下關于過程及過程參數(shù)的描述中,錯誤的是
a)過程的參數(shù)可以是控件名稱
b)用數(shù)組作為過程的參數(shù)時,使用的是“傳地址”方式
c)只有函數(shù)過程能夠?qū)⑦^程中處理的信息傳回到調(diào)用的程序中
d)窗體可以作為過程的參數(shù)
(19)在窗體上畫一個名稱為txta的文本框,然后編寫如下的事件過程:
private sub txta_keypress(keyascii as integer)
end sub
若焦點位于文本框中,則能夠觸發(fā)keypress事件的操作是
a)單擊鼠標 b)雙擊文本框
c)鼠標滑過文本框 d)按下鍵盤上的某個鍵
(20)目錄列表框的path屬性的作用是
a)顯示當前驅(qū)動器或指定驅(qū)動器上的路徑
b)顯示當前驅(qū)動器或指定驅(qū)動器上的某目錄下的文件名
c)顯示根目錄下的文件名
d)只顯示當前路徑下的文件
(21)假定有如下事件過程:
private sub form_mousedown(button as integer,shift as integer, x as single,y as
single)
if button=2 then
popupmenu popform
end if
end sub
則以下描述中錯誤的是
a)該過程的功能是彈出一個菜單
b)popform 是在菜單編輯器中定義的彈出式菜單的名稱
c)參數(shù)x、y指明鼠標的當前位置
d)button=2 表示按下的是鼠標左鍵
(22)以下能夠正確計算n!的程序是
a) private sub commandl_click()
n=5:x=1
do
x=x*1
i=i十1
loop while i<n
print x
end sub
b) private sub commandl_click()
n=5: x=1:i=1
do
x=x*1
i=i十1
loop while i<n
print x
end sub
c)private sub commandl_click()
n=5:x=1:i=1
do
x=x*1
i=i十1
loop while i<=n
print x
end sub
d)private sub commandl_c1ick()
n=5:x=1:i=1
do
x=l
i=i十1
loop while i>n
print x
end sub
(23)在窗體上畫一個名稱為commandl的命令按鈕,再畫兩個名稱分別為labell、label2
的標簽,然后編寫如下程序代碼:
private x as integer
private sub commandl—click()
x=5:y=3
call proc(x,y)
labell.caption=x
label2.caption=y(tǒng)
end sub
private sub proc(byval a as integer,byval b as hteger)
x=a* a
y=b十b
end sub
程序運行后,單擊命令按鈕,則兩個標簽中顯示的內(nèi)容分別是
a)5和3 b)25和3 c)25和6 d)5和6
(24)在窗體上畫一個名稱為commandl的命令按鈕,一個名稱為labell的標簽,然后
編寫如下事件過程:
private sub commandl_c1ick()
s=0
for i=1 t0 15
x=2*i一1
1f x mod 3=0 then s=s十1
nexti
labell.caption=s
end sub
程序運行后,單擊命令按鈕,則標簽中顯示的內(nèi)容是
a)1 b)5 c)27 d)45
(25)在窗體上畫一個名稱為commandl的命令按鈕和三個名稱分別為labell、label2、
label3的標簽,然后編寫如下代碼:
private x as integer
private sub command1_c1ick()
static y as integer
dimz as integer
n=10
z=n十z
y=y(tǒng)十z
x=x十z
labell.caption=x
label2.caption=y
label3.caption=z
end sub
運行程序,連續(xù)三次單擊命令按鈕后,則三個標簽中顯示的內(nèi)容分別是
a)10 10 10 b)30 30 30 c)30 30 10 d)10 30 30
(26)設在窗體上有一個名稱為commandl的命令按鈕,并有以下事件過程:
private sub commandl_c1ick()
static b as variant
b=array(1,3,5,7,9)
end sub
此過程的功能是把數(shù)組b中的5個數(shù)逆序存放(即排列為9,7,5,3,1)。為實現(xiàn)此功
能,省略號處的程序段應該是
a)for i=0 to 5-1\2
tmp=b(i)
b(i)=b(5-i-1)
b(5-i-1)=tmp
next
b)for i=0 to 5
tmp=b(i)
b(i)=b(5-i-1)
b(5-i-1)=tmp
next
c) for i=0 t0 5\2
tmp=b(i)
b(i)=b(5-i-1)
b(5-i-1);tmp
next
d)for i=1 t0 5\2
tmp=b(i)
b(i)=b(5一i一1)
b(5—i—1)=tmp
next
(27)在窗體上畫一個名稱為drivel的驅(qū)動器列表框,一個名稱為dirl的目錄列表框,
一個名稱為filel的文件列表框,兩個名稱分別為labell、label2,標題分別為空白
和“共有文件”的標簽。編寫程序,使得驅(qū)動器列表框與目錄列表框、目錄列表框
與文件列表框同步變化,并且在標簽labell中顯示當前文件夾中文件的數(shù)量。如圖
所示。
能夠正確實現(xiàn)上述功能的程序是
a) private sub dirl_change() b)private sub dir1_change()
filel.path=dir1.path filel.path=dir1.path
end sub end sub
private sub drivel_change() private sub drive1_change()
dirl.path=drivel.drive dirl.path=drivel.drive
labell.caption=filel.listcount labell.captlon=file1.list
end sub end sub
c)private sub dirl_change() d) private sub dirl_change()
filel.path=dirl.path filel.path=dir1.path
labell.caption=filel.listcount labell.caption=filel.list
end sub end sub
private sub drivel_change() private sub drivel_change()
dirl.path=drivel.drlve dir1.path=drivel.drlve
labell.caption=filel.listcount labell.caption=filel.list
end sub end sub
(28)一個工程中包含兩個名稱分別為forml、form2的窗體,一個名稱為mdlfunc的標準
模塊。假定在forml、form2和mdlfunc中分別建立了自定義過程,其定義格式為:
forml中定義的過程:
private sub frmfunctionl()
end sub
form2中定義的過程:
public sub frmffunction2()
end sub
mdlfunc中定義的過程:
public sub mdlfunction()
end sub
在調(diào)用上述過程的程序中,如果不指明窗體或模塊的名稱,則以下敘述中正確的是
a)上述三個過程都可以在工程中的任何窗體或模塊中被調(diào)用
b)frmfunction2和mdlfunction過程能夠在工程中各個窗體或模塊中被調(diào)用
c)上述三個過程都只能在各自被定義的模塊中調(diào)用
d)只有mdlfunction過程能夠被工程中各個窗體或模塊調(diào)用
(29)窗體上有兩個名稱分別為textl、text2的文本框,一個名稱為commandl的命令
按鈕。運行后的窗體外觀如圖所示。
設有如下的類型聲明
type person
name as string*8
major as string*20
end type
當單擊“保存”按鈕時,將兩個文本框中的內(nèi)容寫入一個隨機文件test29.dat中。設
文本框中的數(shù)據(jù)已正確地賦值給person類型的變量p。則能夠正確地把數(shù)據(jù)寫入文件
的程序段是
a)0pen”c:\test29.dat" for random as#1
put #1,1,p
close #1
b)open "c:\test29.dat" for random as #1
get#1,1,p
c10se #1
c)open "c\test29.dat" for random as #1 len=len(p)
put #1,1,p
close #1
d)open "c:\test29.dat " for random as #1=len(p)
get #1,1,p
close #1
(30)在窗體上畫一個名稱為commondialogl的通用對話框,一個名稱為commandl的
命令按鈕。要求單擊命令按鈕時,打開一個保存文件的通用對話框。該窗口的標題
為"save",缺省文件名為“savefile”,在“文件類型”欄中顯示*.txt。則能夠滿足
上述要求的程序是
a)private sub command_c1ick()
commondialogl.filename=“savefile”
commondialogl.filter="all files|*.*|(*.txt)|*.txt|(*.doc).|*.doc"
commondialogl.filterindex=2
commondialogl.dial0g.title="save"
commondialogl.action=2
end sub
b)private sub commandl_click()
commondialogl.filename="savefile"
commondialogl.filter="a11 files|*.*|(*.txt)|*.txt|*.doc|*.doc"
c0mmondialogl.filterindex=1
commondialogl.dialogtitle="save"
commondialogl.action=2
end sub
c)private sub cmmandl_c1ick()
commondialogl.filename="save"
commondialogl.filter="a11files|*.*|(*.txt)|*.txt|(*.doc)|*.doc"
commondialogl.filterindex=2
c0mmondialogl.dialogtitle="savefile"
commondialogl.action=2
end sub
d)private sub commandl_c1ick()
commondialogl.filename="savefile"
commondialogl.filter="all files|*.*|(*.txt)|*.txt|(*.doc)|*.doc"
commondialogl.filterindex=1
commondialogl.dialogtitle=“save”
commondialogl.action=1
end sub
二、填空題(每空2分,共30分)
請將每空的正確答案寫在答題卡[1]一[15序號的橫線上,答在試卷上不得分。
(1)visual basic中有一種控件組合了文本框和列表框的特性,這種控件是________
(2)visual basic提供的對數(shù)據(jù)文件的三種訪問方式為隨機訪問方式_____和二進制訪問
方式。
(3)執(zhí)行下面的程序段后,變量s的值為_______。
s=5
for i =2.6 to 4.9 step 0.6
s=s十1
next i
(4)為了在運行時把d:\pic文件夾下的圖形文件a.jpg裝入圖片框picturel,所使用的語
句為_______。
(5)計時器控件能有規(guī)律的以一定時間間隔觸發(fā)_______事件,并執(zhí)行該事件過程中的
程序代碼。
(6)以下程序的功能是:生成20個200到300之間的隨機整數(shù),輸出其中能被5整除的
數(shù)并求出它們的和。請?zhí)羁铡?br> private sub commandl_c1ick()
fori=1to 20
x=int(____________*200+100)
if_______[7] =0 then
print x
s=s+_________ [8]
end if
next i
print “sum=”:s
end sub
(7)設有如下程序
private sub form_click()
dim a as integer,b as integer
a=20:b=50
pla,b
p2a,b
p3a,b
print"a=";a,"b=";b
end sub
sub pl(x as integer,byval y as integer)
x=x+10
v=v+20
end sub
sub p2(byval x as integer, y as integer)
x=x+10
y=y(tǒng)+20
end sub
sub p3(byvalx as integer, byval y as integer)
x=x+10
y=y+20
end sub
該程序運行后,單擊窗體,則在窗體上顯示的內(nèi)容是:a=______和b=______。
(8)在窗體上畫一個名稱為commandl的命令按鈕,編寫如下事件過程
private sub commandl_c1ick()
dim as string
a=_____[11]
for i =1 to 5
print space(6—i);mid$3(a,6—i,2*i—1)
nexti
end sub
程序運行后,單擊命令按鈕,要求窗體上顯示的輸出結(jié)果為
456
34567
2345678
123456789
請?zhí)羁铡?/p>
(9)在窗體上畫一個名稱為combo1的組合框,畫兩個名稱分別label1和label2及caption
屬性分別為“城市名稱”和空白的標簽。程序運行后,當在組合框中輸入一個新項
后按回車鍵(ascii碼為13)時,如果輸入的項在組合框的列表中不存在,則自動
添加到組合框的列表中,并在label2中給出提示“已成功添加輸入項”如圖所示;
如果存在,則在label2中給出提示“輸入項已在組合框中”。請在[12]、[13]和
[14]處將程序補充完整。
private sub combol_________<12> (keyascii as integer)
1f keyascii=13 then
fori=0 to combo1.listcount—1
1f combo1.text=______ [13] ihen
label2.caption=”輸入項己在組合框中”
exit sub
end lf
next i
label2.caption=“已成功添加輸入項”
combo1.______ [14] combo1.text
end lf
end sub
(10)設有如下程序
private sub search(a()as variant,byval key as variant,index%)
dim i%
fori=lbound(a)to ubound(a)
if key=a(i) then
index=i
exit sub
end if
next i
index=-1
end sub
private sub form_load()
show
dtm b() as variant
dim n as integer
b=array(1,3,5,7,9,11,13,15)
call search(b,11,n)
printt n
end sub
程序運行后,輸出結(jié)果是________。