我有个程序是模仿现在的电视机顶盒的,它目前的功能是可以用软盘来当作用户受权卡,在没有插入软盘时,启动程序会提示:没有放入盘,请放入盘,当放入盘时,提示:用户正确,可以进行的字样.但我的问题是:这个机顶盒程序,当正确进行后,我想让它也实现开关的作用.就是说正常进入后,我点击窗体上的命令按钮后(是关闭的命令),窗体上的显示内容的文本框或列表框中的内容就删除了.当我再次点击窗体上的命令按钮后(是打开的命令),窗体上的显示内容的文本框或列表框中就又有内容了(比如从另一地方读取).和现实生活中的机顶盒一样的.我不知道这个打开/关闭功能如何实现?这个程序里检测软驱的功能我已经实现了(用了个布尔变量的方法),但这个开关按钮的功能我不知道怎么来实现了?
我从书上抄了个小程序,是变换一个命令按钮的caption文字的.我觉得这个程序很像一个机子的打开/关闭按钮的功能.但我应该把这个程序放在我的程序的什么位置呢?请大家指导我.多谢了!
我的机顶盒的进入程序如下:
Private Sub cmdoc_Click()
Dim serialnum_lng As Long
Dim rs As Long
Dim label_str As String
Dim type_str As String
Dim flag As Boolean
label_str = String$(255, Chr$(0))
type_str = String$(255, Chr$(0))rs = GetVolumeInformation("a:\", label_str, Len(label_str), serialnum_lng, 0, 0, type_str, Len(type_str))flag = fun_floppydrive("a:")
If flag = False Or serialnum_lng <> "80644129" Then
Form1.syszt.Caption = "用户卡没有插入或不配对,请正确插入用户卡!"
Form1.volist.Enabled = False
Form1.cmdprev.Enabled = False
Form1.cmdnext.Enabled = False
Form1.cmdplay.Enabled = False
Form1.cmdpause.Enabled = False
Form1.cmdback.Enabled = False
Form1.cmdstep.Enabled = False
Form1.cmdstop.Enabled = False
Form1.cmdrecord.Enabled = False
Else
flag = True
Form1.syszt.Caption = "可以进入"
Form1.volist.Enabled = True
Form1.volist.Enabled = True
Form1.cmdprev.Enabled = True
Form1.cmdnext.Enabled = True
Form1.cmdplay.Enabled = True
Form1.cmdpause.Enabled = True
Form1.cmdback.Enabled = True
Form1.cmdstep.Enabled = True
Form1.cmdstop.Enabled = True
Form1.cmdrecord.Enabled = True
End If
我从书上抄的变换命令按钮的caption文字的程序如下:
private sub command1_click()
static pausetime as integer
pausetime = pausetime + 1
if pausetime mod 2 = 1 then
command1.caption = "暂停"
else
command1.caption = "继续"
end if
mmcontrol1.command = "pause"
end sub
说明一下:这个其实是一个媒体播放器的一块小程序.
请大家帮助指导一下我的问题.多谢!

解决方案 »

  1.   

    比如你那个按钮的名字是command1Private Sub command1_Click() 
      if command1.text="打开" then '打开机顶盒
          ‘打开时进行的一些操作
           command1.text="关闭"
      else'关闭
           '关闭时进行的一些操作
           command1.text="打开"
      end if  
    end sub
      

  2.   

    不明白楼主意思,如果只是要改变button的caption,只需要加入click事件Private Sub command1_Click() 
      if command1.caption="打开" then 
           command1.caption="关闭"
      else
           command1.caption="打开"
      end if  
    end sub