课3

 题目:
     设计一个程序: 在对话框中输入数字,当数字小于20,(并且如果小于10,弹出"错误数字小于10"对话框,并且要求重新输入,否则弹出"错误数字要大于20"对话框,并要求重新输入.)否则弹出回答正确对话框
-----------------------------------------------------------------------------------------------------
   dim score
    score=inputBox("请输入数字")
    do while score<20
        if score<10 then
          msgBox "错误数字小于10"
       else
         msgBox "错误数字要大于20"
       end if
       score=inputBox("请重新输入数字")
   loop
     msgBox "回答正确"
---------------------------------------------------------------------------------------------------
    请给数组score(100)全部赋值,取值是索引的2倍. 并将所有值显示出来
----------------------------------------------------------------------------------------------------
      dim score(100)
    for i=0  to 100
      score(i)=i*2
   next
    for each i in score
      msg=msg & i & vbcrlf
   next
    msgBox msg
---------------------------------------------------------------------------------------------------
    设计一个程序,能显示今天是礼拜几(使用weekDay(now)函数),
   dim week
    week=weekDay(now)
    select case week
      case 1
       msg="今天礼拜日"
    case 2
     msg="今天礼拜一"
   case 3
    msg="今天礼拜二"
   case 4
   msg="今天礼拜三"
   case 5
    msg="今天礼拜四"
   case 6
    msg="今天礼拜五"
   case 7
   msg="今天礼拜六"
  end select
  msgBox msg
--------------------------------------------------------------------------------------------------------
   While .........Wend 循环
 
   while  条件
      代码
   wend
  ---------------------------------------------------------------------------------------------------------
      Ans=inputBox("请输入快乐的英文")
   While Ucase(Ans)<>"HAPPY"
       msg="不正确"&vbcrlf &"请重新输入"
      Ans=inputBox("重新输入")
  wend
    msgBox "太棒了"
------------------------------------------------------------------------------------------------------------
  子程序
1 、什么是子程序

 2、格式:
      sub 子程序名称(参数1,参数2,....)
       代码
      end sub
  调用:
   call 子程序名(参数1,......)
   子程序名 参数1,参数2,.......
 3、举例简单的sub 例子(外面和里面)
 4、举例说明单参数的使用方法(运算)
 5、举例说明sub 参数可以是变量也可以是数值  
  -------------------------------------------------------------------------
    sub ChangeF(C)
    DegreeF=C*1.8+32
    MsgBox "摄氏"&C &"度转换为华氏"&DegreeF&"度"
   end sub
   DegreeC=inputBox("请输入摄氏温度")
   ChangeF DegreeC
--------------------------------------------------------------------------------------------
 6、举例说明sub多个参数的使用方法

   sub numb(x,y)
       dim z
        z=x+y
       msgBox "结果是"& z
  end sub
         numb 3,6
   
   多个子程序的互相的调用,说明子程序的作用
-----------------------------------------------------------
  举例:
   sub Ans1()
                 msgBox "你好呀,我是第一个"
            end sub
            sub Ans2()
                 msgBox "你好呀,我是第二个"
           end sub
          sub Ans3()
                msgBox "你好呀,我是第三个"
         end sub
         sub  diao()
             Ans1
             Ans2
            Ans3
           end sub
        diao
-----------------------------------------------------
  举例参数
 sub Ans1(x,y)
        z=x+y
       msgBox z
    end sub
    sub Ans(x,y)
        Ans1 2*x,2*y
   end sub
    dd=inputBox("请输入数字")
    cc=inputBox("请输入数字")
    Ans dd,cc
    

题目:  把我们原来做过的程序包到子程序中来用
   

posted @ 2007-03-10 22:39  蓝魔  阅读(229)  评论(0)    收藏  举报