privante sub cmdGet(strText as string)
  select case trim(strText)
     case "text1"
        textme.text=text1.text
     case "text2"
        textme.text=text2.text
     case "txtother"
        textme.text=txtother.text
     case "txtage"
        textme.text=txtage.text
   …………
 end select
end sub
这段程序谁看了都要烦死了,有没有更好的办法
注:strText是字符串型,不可以改成对象型。

解决方案 »

  1.   

    privante sub cmdGet(strText as string)
        Dim ctl As Control,fFound as Boolean
        For Each ctl In Controls
            If ctl.Name=trim(strText) then
                fFound=True
                Exit For 
            end if
        Next ctl
        If fFound then
            textme.text=CallByName(ctl,"Text",vbGet)
        End if
    end sub
      

  2.   

    privante sub cmdGet(strText as string)
         on error resume next
         textMe.Text = Me.Controls(strText).Text
    end sub
      

  3.   

    privante sub cmdGet(strText as textbox)
      select case strText
         case text1
            textme.text=strText.text
         case text2
            textme.text=strText.text
         case txtother
            textme.text=strText.text
         case txtage
            textme.text=strText.text
       …………
     end select
    end sub
    试试
      

  4.   


    参数类型能换吗?
       1.能,我建议你把参数类型改为text
          privante sub cmdGet(strText as text)
              textme.text=strtext.text
          end sub
       2.不能,采用itpao(啊炮)的。
      

  5.   

    吧text 该改成控件数组是个好主意