《VB趣味小程序(共3页).doc》由会员分享,可在线阅读,更多相关《VB趣味小程序(共3页).doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上VB趣味小程序1. 空心三角形Dim i%, j%Print Space(20); *For i = 2 To 9 Print Space(21 - i); *; Space(2 * i - 3); *NextPrint Space(10);For i = 1 To 10 Print Space(1); *;Next扩展程序Const n = 15Dim a(1 To n) As IntegerDim i%, j%, t%RandomizeFor i = 1 To n a(i) = Int(100 * Rnd) 生成15个0100的随机整数存入数组NextPrint
2、排序前:For i = 1 To n Print a(i);NextPrintFor 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 NextNextPrint 排序后:For i = 1 To n Print a(i);Next2. 六角星Dim i%, j%, k%For i = 1 To 10 If i 6 Then Print Space(20 - i); For j = 1 To i Print ; Next j Else Print Space(6 + i); F
3、or k = 14 - i To 1 Step -1 Print ; Next k End If PrintNext iFor i = 3 To 1 Step -1Print Space(20 - i);For j = 1 To iPrint ;Next jPrintNext i3. 球来回弹在窗体上添加一shape空间,shape为circle,计时器空间inteval=10通用Dim bzPrivate Sub Timer1_Timer() If Shape1.Left = Form1.ScaleWidth - Shape1.Width Then bz = 1 If Shape1.Left
4、 = 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 - 2End Sub5. 在VB中用画圆Dim x, y, i As SingleClsScale (-15, 15)-(15, -15) 定义笛卡儿坐标系For i = 0 To 6.28 Step 0.05 y = 10 * Sin(i) x = 10 * Cos(i) Current
5、X = x CurrentY = y Print *Next6. 四周循环移动创建一个窗体,在上面添加“开始”和“停止”两个按钮,添加一个计时器控件timer1在窗体上添加一个shape控件,设置背景不透明,红色,调整大小程序代码如下:Option ExplicitDim bz%Private Sub Command1_Click() 开始按钮 Timer1 = TrueEnd SubPrivate Sub Command2_Click() 停止按钮 Timer1 = FalseEnd SubPrivate Sub Form_Load() Shape1.Left = 0 Shape1.Top
6、= 0 Timer1 = False Timer1.Interval = 10End SubPrivate 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 SelectEnd Sub专心-专注-专业