温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,汇文网负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
网站客服:3074922707
2023
程序
VB
趣味
【小程序】VB趣味小程序
VB 趣味小程序
1. 空心三角形
Dim i%, j%
Print Space(20); "x"
For i = 2 To 9
Print Space(21 - i); "x"; Space(2 x i - 3); "x"
Next
Print Space(10);
For i = 1 To 10
Print Space(1); "x";
Next
扩展程序
Const n = 15
Dim a(1 To n) As Integer
Dim i%, j%, t%
Randomize
For i = 1 To n
a(i) = Int(100 x Rnd)
'生成 15 个 0~100 的随机整数存入
数组
Next
Print "排序前:"
For i = 1 To n
Print a(i);
Next
Print
For i = 1 To n - 1
For j = i + 1 To n
If a(j) < a(i) Then t = a(j): a(j) = a(i): a(i) = t
Next
Next
Print "排序后:"
For i = 1 To n
Print a(i);
Next
2. 六角星
Dim i%, j%, k%
For i = 1 To 10
If i < 4 Or i > 6 Then
Print Space(20 - i);
For j = 1 To i
Print "○";
Next j
Else
Print Space(6 + i);
For k = 14 - i To 1 Step -1
Print "○";
Next k
End If
Print
Next i
For i = 3 To 1 Step -1
Print Space(20 - i);
For j = 1 To i
Print "○";
Next j
Print
Next i
3. 球来回弹
在窗体上添加一 shape 空间,shape 为 circle,计时器空间 inteval=10
通用
Dim bz
Private Sub Timer1_Timer()
If Shape1.Left >= Form1.ScaleWidth - Shape1.Width Then bz = 1
If Shape1.Left <= 0 Then bz = 0
If bz = 0 Then Shape1.Left = Shape1.Left + 10
If bz = 1 Then Shape1.Left = Shape1.Left - 10
End Sub
注意:bz 的使用〔bz 为一临时标志,用于判断移动方向〕
4. 从大到小再从小到大变化
在窗体添加一标签 label1,autosize=true,caption="★",添加一计时器
空间 timer1,inteval=100
通用:
Dim bz
Private Sub Timer1_Timer()
If Label1.FontSize >= 72 Then bz = 1
If Label1.FontSize <= 8 Then bz = 0
If bz = 0 Then Label1.FontSize = Label1.FontSize + 2
If bz = 1 Then Label1.FontSize = Label1.FontSize - 2
End Sub
5. 在 VB 中用画圆
Dim x, y, i As Single
Cls
Scale (-15, 15)-(15, -15)
'定义笛卡儿坐标系
For i = 0 To 6.28 Step 0.05
y = 10 x Sin(i)
x = 10 x Cos(i)
CurrentX = x
CurrentY = y
Print "x"
Next
6. 四周循环移动
创立一个窗体,在上面添加“开始〞和“停止〞两个按钮,添加一个
计时器控件 timer1
在窗体上添加一个 shape 控件,设置背景不透明,红色,调整大小
程序代码如下:
Option Explicit
Dim bz%
Private Sub Command1_Click() '开始按钮
Timer1 = True
End Sub
Private Sub Command2_Click() '停止按钮
Timer1 = False
End Sub
Private Sub Form_Load()
Shape1.Left = 0
Shape1.Top = 0
Timer1 = False
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
If Shape1.Left >= Form1.ScaleWidth - Shape1.Width And
Shape1.Top <= 0 Then bz = 1
If Shape1.Top >= Form1.ScaleHeight - Shape1.Height Then
bz = 2
If Shape1.Left <= 0 Then bz = 3
If Shape1.Top <= 0 And Shape1.Left <= 0 Then bz = 0
Select Case bz
Case 0
Shape1.Left = Shape1.Left + 10
Case 1
Shape1.Top = Shape1.Top + 10
Case 2
Shape1.Left = Shape1.Left - 10
Case 3
Shape1.Top = Shape1.Top - 10
End Select
End Sub