微信公众号 
图码生活

每天发布有五花八门的文章,各种有趣的知识等,期待您的订阅与参与
电脑报 1992-2001 十年文章全集
电脑报 1992-2001 十年文章全集
包含从 1992 年 - 2001 年间,两万余篇期刊文章,查询最少输入两个字符
随便看看
读取中
读取中
标题菜鸟捉虫(25)
栏目软件世界
发布2001年25期
  上期正确答案:
  做“循环的飞字”关键在于判断飞字的当前位置,从而做出字体是否到达边界的处理。程序中有两处错误。错误1:无时间间隔的设置timer1的timer事件将永远不会执行;错误2:无边界的判定就不会出现循环的效果。
  Private Sub Form_Load()
  Timer1.Interval = 10 '//无此行,错误1
  Label1.Left = -Label1.Width
  End Sub
  Private Sub Timer1_Timer()
  Label1.Left = Label1.Left + 50
  If Label1.Left > Me.Width Then Label1.Left = -Label1.Width '//无此行,错误2
  Label1.Move Label1.Left
  End Sub
  以下是第23期“菜鸟捉虫”幸运读者名单(奖品为2001年《电脑报配套光盘》系列)
   本期题目:
  现有一程序,其主要目的是在一数组中实现从大到小的排序功能,程序在编译后,却不能达到排序的目的,请找出其中的错误。程序中有1个CommandButton按钮和3个Label标签,其中Label1的Caption属性设置为“请输入排序的数字个数:”。
  Dim MyArray() As Long
  Dim Record As Long
  Private Sub Command1_Click()
  Dim i As Long, b As String
  Record = Val(Text1.Text)
  If Record <= 0 Then Exit Sub
  ReDim MyArray(Record - 1)
  '//动态生成数组
  Randomize
  For i = 0 To Record - 1
  '//随机产生数字
  MyArray(i) = Int((1000 * Rnd) + 1)
  b = b & Str(MyArray(i)) & “ | ”
  Next i
  Label2.Caption = “排序前:” + b
  Call Func(1): b = “”
  For i = 0 To Record - 1
  b = b & Str(MyArray(i)) & “ | ”
  Next i
  Label3.Caption = “排序后:” + b
  Erase MyArray '//释放内存
  End Sub
  Private Sub Func(ByVal f As Long)
  Dim a As Long, b As Long, i As Long
  Dim flg As Boolean
  flg = False: a = 0: b = 0
  For i = f To Record - 1
  If a < MyArray(i) Then
  a = MyArray(i): flg = True
  b = I:exit for
  End If
  Next i
  If flg Then
  MyArray(b) = MyArray(f)
  MyArray(f) = a
  f = f + 1
  Call Func(f)
  End If
  End Sub