求几道VB题目的解答

来源:百度知道 编辑:UC知道 时间:2024/06/17 22:43:37
第一题
运行下面程序,单击窗体后第123行分别显示什么(答案15 13 17)
dim i as integer,s as integer
for i =1 to 10
s=s+i
if s>10 then
print s
s=0
end if
next i
end sub
第二题
total =0
for m= 1 to 3
if m>=1 then
part=1
elseif m>=2 then
part=2
elseif m>=3 then
part=3
else
part=4
end if
print part
total=total+part
next m
print total
运行时输出结果(答案1 1 1 3)
第三题
运行下面程序,第13行分别是(答案d dbAeB)
dim mst as string,mst1 as string,mst2 as string
dim i as integer
mst1="CeBbAd"
for i=len(mst1)to 1 step -2
mst2=mid(mst1,i-1,2)
mst=mst&mst2
print mst
next i
end sub
第四题执行下面的command1_click 事件后,text1,text2显示内容为(答案VISUAL 2008.10.11)
private sub command1_click ()
dim s as string,i as integer
const ch as string="0123456789"
s="2L0A08U.1SI0V.11"
text1=""
text2="

dim i as integer,s as integer
for i =1 to 10
s=s+i
if s>10 then
print s
s=0
end if
next i
end sub

当s=1+2+3+4+5=15 s>10 显示15,赋予s=0
当s=6+7=13 s>10 显示13,s=0
当s=8+9=17 s>10 显示17,s=0

total =0
for m= 1 to 3
if m>=1 then
part=1
elseif m>=2 then
part=2
elseif m>=3 then
part=3
else
part=4
end if
print part
total=total+part
next m
print total

i=1 part=1 total=1 显示1
i=2 part=1 total=2 显示1
i=3 part=1 total=3 显示1 循环结束 显示total,3
if语句中其实条件是包含关系,所以满足第一个条件后就结束了
所以一般分支语句的条件应该是互斥的,要不会得到错误的结果

dim mst as string,mst1 as string,mst2 as string
dim i as integer
mst1="CeBbAd"
for i=len(mst1)to 1 step -2
mst2=mid(mst1,i-1,2)
mst=mst&mst2
print mst
next i
end sub

i的取数是6 to 1 -2,循环即为i=6,4,2
i=