Print \小于0的数据个数为:\ Print \等于0的数据个数为:\ Print \大于0的数据个数为:\End Sub
例2:打印下面的图形:----------------------------- 选讲内容 ********* ******** ******* ****** ***** **** *** ** * * ** *** **** ***** * *** *****
*******
Private Sub Form_click() Dim i As Integer, j As Integer For i = 1 To 9 Print Tab(5); For j = 1 To 10 - i Print \ Next j Print Next i End Sub
Private Sub Form_click()
Dim i As Integer, j As Integer For i = 1 To 5 Print Tab(5); For j = 1 To i Print \
Next j Print Next i End Sub
Private Sub Form_click() Dim i As Integer, j As Integer For i = 1 To 4
Print Tab(9 - i); For j = 1 To 2 * i - 1 Print \ Next j
Print Next i End Sub
例3 从键盘输入任意个数,求出这些数的总和和平均值! Dim a() as integer
Dim I as integer, sum as integer, avg as single, t as integer Do
I=inputbox(―请输入一数!‖) If i=-1 then Exit do Else
T=t+1
Redim preserve a(t) A(t)=i
Sum=sum+i endif
Loop
Avg=sum/ubound(a)
Print ―sum=‖;sum,‖avg=‖+cstr(avg)
例4 编程实现随机生成20个互不相同的两位整数! Dim a() as integer ,I as integer, n as integer,j as integer Redim a(20) as integer For i=1 to 20
k= inputbox(―请输入N的值‖) for j=1 to i-1 if a(j)=k then exit for next j
if j>i-1 then a(i)=k else i=i-1
endif next i
例 5 在一组有序数列中插入一个数,要求插入后的数还是有序数列! Dim a() as integer
Dim I as integer , n as integer, k as integer For i=1 to 10
A(i)=10*i
Next i
N=inputboxa(―请输入要插入的数‖)
以下有两种方案1 前插入 2 后插入(可以用班级中的同学进行示范教学) T=10