vb寫起來又臭又長,請問高手如何以動態方式指定PictureBox,
來簡化以下程式碼‧
1、有十六個Form(依十六個產品大分類),每個Form上面各有
十個大小不同的PictureBox
2、在另外的mainForm有十個textBox,讓User輸入設定Spec.
條件(可更改),依判斷不同的Spec,來顯示該產品的
相關影像資料在十個PictureBox‧
Private Sub cmdStart_click()
Dim Produst as string, Pn as PictureBox
With frmChoice
Product = Trim(.txtProduct.Text)
Select Case Product
Case "Computer" '十六個Form的第一個
Set Pn= frmP1.pic1
Call findLoad(pn, .txtSpecl.Text)
'Load picture1 to Pic1
Set Pn= frmP1.pic2
Call findLoad(pn, .txtSpec2.Text)
'Load picture2 to Pic2
Set Pn= frmP1.pic3
‧
‧
'一共依10個Spec.不同findLoad 10次Picture
Case "Product 2"
‧
‧
'一共依10個Spec.不同findLoad 10 次Picture
Case "Product 16" '直到"Product 16"
Doing the same findLoad 10 次Picture.
End Select
End With
End Sub
Private Sub findLoad(pn as PictureBox, ByVal Spec _
As String)
pn.Cls
Select Case trim(Spec)
Case "A-Type"
If FindFirst(AdoCh.Recordset, "pSpec=Spec") Then
Call goLoad(Spec)
Call askLeaveMessage
Else
'Msg:Asked Spec. not Found. Display Others for choice
Call ListAllotherSpec(Spec)
Exit Sub
End If
Case "B-Type"
‧
共10種Same as above
End Select
End SuB
來簡化以下程式碼‧
1、有十六個Form(依十六個產品大分類),每個Form上面各有
十個大小不同的PictureBox
2、在另外的mainForm有十個textBox,讓User輸入設定Spec.
條件(可更改),依判斷不同的Spec,來顯示該產品的
相關影像資料在十個PictureBox‧
Private Sub cmdStart_click()
Dim Produst as string, Pn as PictureBox
With frmChoice
Product = Trim(.txtProduct.Text)
Select Case Product
Case "Computer" '十六個Form的第一個
Set Pn= frmP1.pic1
Call findLoad(pn, .txtSpecl.Text)
'Load picture1 to Pic1
Set Pn= frmP1.pic2
Call findLoad(pn, .txtSpec2.Text)
'Load picture2 to Pic2
Set Pn= frmP1.pic3
‧
‧
'一共依10個Spec.不同findLoad 10次Picture
Case "Product 2"
‧
‧
'一共依10個Spec.不同findLoad 10 次Picture
Case "Product 16" '直到"Product 16"
Doing the same findLoad 10 次Picture.
End Select
End With
End Sub
Private Sub findLoad(pn as PictureBox, ByVal Spec _
As String)
pn.Cls
Select Case trim(Spec)
Case "A-Type"
If FindFirst(AdoCh.Recordset, "pSpec=Spec") Then
Call goLoad(Spec)
Call askLeaveMessage
Else
'Msg:Asked Spec. not Found. Display Others for choice
Call ListAllotherSpec(Spec)
Exit Sub
End If
Case "B-Type"
‧
共10種Same as above
End Select
End SuB
全站熱搜
留言列表