有一问题请教
dim a as long
dim lRet as long
lRet=ActLLT1.GetDevice("D0",a)   'a为从D0取得的数值,比如1,2,3,........
假如我新建了N个窗体,分别命名为P1,P2,P3.....
如果a=1时则显示P1窗体,如果a=2时则显示P2窗体,依次类推,根据a的值显示相应的窗体,我是这样写的
"P" & a.Show
但会报语法错误,请教给位前辈们怎样写啊????

解决方案 »

  1.   

    把你创建的N个窗体管理起来,和名称做个映射,然后通过a的返回值查找得到对应的窗体,然后把找到的窗体显示出来。已经不用VB 6了,写个伪代码:rem 创建完成映射的字典 dic,字符串"Pn"为Key
       for i = 1 to N
         dic.Add("P" & i, PN)
       next
      ...
      lRet=ActLLT1.GetDevice("D0",a)
    rem 通过"Pa"这个Key查找对应Form并显示
       dim frm
       frm = dic.Item("P" & a)
       frm.Show  
      

  2.   

    窗体的名称是不能使用字符串合成的
    可以使用下面的方法dim a as long
    dim lRet as long
    lRet=ActLLT1.GetDevice("D0",a)   'a为从D0取得的数值,比如1,2,3,........select case a 
    case 1
      p1.show
    case 2
      p2.showcase ...
      pn.show
    end select
      

  3.   

    也可以这样使用:
    dim F(n) as form '或者定义为你窗口类型,n为你预设的窗口类型的个数sub form_load
     set f(0)=P0
     set f(1)=p1
     ....
     set f(n)=pn   
    end subsub yoursub
    dim a as long
    dim lRet as long
    lRet=ActLLT1.GetDevice("D0",a)   'a为从D0取得的数值,比如1,2,3,........
    if a 在允许的数值范围 then
      f(a).show
    end if
    end sub
      

  4.   

    不好意思,好像把set给忘记了: set frm = dic.Item("P" & a)这是VBA的参考代码,用CommandButton举例了:Sub Test()
        Dim col As New Collection
        Dim i As Integer
        Dim cmd As CommandButton
        
        For i = 1 To 5
            Set cmd = CreateObject("Forms.CommandButton.1")
            
            cmd.Caption = "Button " & i
            
            col.Add cmd, "C" & i
            'Debug.Print col("C" & i).Caption
        Next
        
        Dim a As Integer
        
        a = 2
        
        Set cmd = col("C" & a)
        
        Debug.Print cmd.Caption
        
    End Sub