Dim StrNameArray() As String
Private Sub Command1_Click(Index As Integer)
If Command1(Index).Caption <> "收起" Then
For i = 0 To Command1.Count - 1
  If Index <> i Then Command1(i).Enabled = False Else Text1.Text = Command1(Index).Caption: Command1(i).Caption = "收起"
Next
Else
For i = 0 To Command1.Count - 1
  Command1(i).Enabled = True: Command1(Index).Caption = Text1.Text
 Next
End If
If Command1(Index).Caption = "收起" Then
i = 0
StrName = Split(FuncCtlName(Text1.Text), ",")
For Each strs In StrName
i = i + 1
Next
ReDim StrNameArray(i)
x = 0
StrName = Split(FuncCtlName(Text1.Text), ",")
For Each strs In StrName
StrNameArray(x) = strs
x = x + 1
Next
For i = 0 To x - 1
 Dim CtlAdd As CommandButton
 Set CtlAdd = Controls.Add("vb.commandbutton", StrNameArray(i))
 CtlAdd.Left = Command1(Index).Left
 CtlAdd.Top = Command1(Index).Top + (Command1(Index).Height * (i + 1)) + 150
 CtlAdd.Caption = StrNameArray(i)
 CtlAdd.Width = Command1(Index).Width
 CtlAdd.Height = Command1(Index).Height
 CtlAdd.Visible = True
Next
Else
i = 0
StrName = Split(FuncCtlName(Text1.Text), ",")
For Each strs In StrName
i = i + 1
Next
ReDim StrNameArray(i)
x = 0
StrName = Split(FuncCtlName(Text1.Text), ",")
For Each strs In StrName
StrNameArray(x) = strs
x = x + 1
Next
For i = 0 To x - 1
Controls.Remove StrNameArray(i)
Next
End If
End Sub
Public Function FuncCtlName(Ctlname As String) As String
Select Case Ctlname
  Case "商品資料管理"
   FuncCtlName = "總公司商品資料,分店商品資料"
  Case "營業資料管理"
   FuncCtlName = "分店營業資料,分店營業報表,分店營業現況,分店營業排名,分店總表"
  Case "分析資料管理"
   FuncCtlName = "商品ABC資料,時段分析資料,綜合營收分析,貢獻比分析"
  Case "資料傳送"
   FuncCtlName = "傳送商品資料,傳送參數資料,取得門市資料"
End Select
End Function
請問要怎麼樣才能更精簡我的程式碼ㄋ
還請高手指點
arrow
arrow
    全站熱搜

    vbqa 發表在 痞客邦 留言(0) 人氣()