VB程式設計經典案例

2021-03-04 09:31:19 字數 1868 閱讀 2920

求1+5+10+15+……………..+500的和,並將結果輸出在窗體上,將結果存入變數sum 中

dim sum as long

sum=0

for i=0 to 500 step 5

sum=sum+i

next

print sum

'題目:(事件)單擊窗體。

' (響應)求10~20之間所有素數的乘積並輸出在窗體上。

' 將結果存入變數l中

'注意:請在指定的事件內編寫**。

dim l as long

dim i as integer

dim j as integer

dim b as boolean

l=1b= true

for i =10 to 20

for j =2 to i-2

if i mod j=0 then

b= false

end if

next

if b = true then

l=l*i

end if

b= true

next

print str(1)

'題目::編寫函式fun其功能是:判斷乙個整數w的各位

' 數字平方之和能否被5整除 , 可以被5整除則返

' 回1 , 否則返回0

private function fun(w as integer) as boolean

begin

dim k as integer ,s as integer

dos=s+(w mod 10)*(w mod 10)

w=int(w/10)

loop while w<>0

if s mod 5=0 then

k=1else

k=0end if

fun=k

endend function

題目:編寫函式fun,函式的功能是:根據乙個百分制

'成績mark(整數),顯示對應五級制的評定。條件如下:

'mark大於等於90顯示"優秀"

'mark小於90且大於等於80顯示"良好"

'mark小於80且大於等於70顯示"中等"

'mark小於70且大於等於60顯示"及格"

'mark小於60顯示"不及格"

'要求使用if語句來實現。

private function fun(mark as integer) as string

begin

if mark>=90 then

fun=」優秀「

else if mark>=80 then

fun=」良好「

else if mark>=70 then

fun =」中等「

else if mark>=60 then

fun=」及格」

else

fun=」不及格「

end if

endend function

'題目:(事件)雙擊窗體。

' (響應)求出100~200之間,能被5整除,但不能被3整除的數。

' 並求所有數之和,存入變數中sum中

private sub form_dblclick()

dim sum as integer

sum = 0

dim i as integer

for i =100 to 200

if ((i mod 5)=0) and ((i mod 3)<>0) then

print (cstr(i))

sum=sum+i

end if

next

end sub

VB程式設計試卷

1.儲存新建的工程時,預設的資料夾是 a.my documentb.vb98 cd.windows 2.不是字串常量的是 a.你好b.c.trued.false 3.表示式abs 5 len abcde 的值為 a.5abcdeb.5abcde c.10d.0 4.如果要在文字框中鍵入字元時,只顯示...

VB選擇結構程式設計

阜陽市一職高 尚克震2008年10月15日第一節課 07計 1 教學目標分析 通過教師引導學生去 發現技術背後所蘊含的技術價值和技術思想,使其獲得知識與技能的同時,理解和掌握過程與方法,這樣才能夠學會認知,學會做事,乃至學會生活,提高終生學習的能力 分析解決問題的能力,滿足其終身發展的需要,成為適應...

VB程式設計選擇結構

寧國市三津中學陳輝 一 教材分析 選擇控制結構是程式的三個基本結構中的乙個重要結構,計算機的邏輯判斷能力就是通過選擇結構來完成的。條件語句中的 條件 是用關係表示式 邏輯表示式來描述的。程式中能否實現正確的 選擇 決定於關係表示式或邏輯表示式的正確描述。用選擇結構編寫簡單的程式解決具體問題是在學生已...