首页 > 解决方案 > 如何根据下拉框动态改变一个形状数据

问题描述

我有一个用户表单,当电缆形状掉到工作表上时运行:该表单询问用户电缆分类是主要的还是次要的,以及托盘类型是主要的还是次要的。例如,如果选择了主电缆和桥架,则电缆类型+桥架形状数据将更改为仅包含主电缆和桥架的下拉列表。

Public shp3 As Shape
Private Sub CommandButton1_Click()
   Dim CableClass As String
   Dim TrayClass As String
   Dim pg2 As Page

   CableClass = ComboBox1.Value
   TrayClass = ComboBox2.Value
   Set shp3 = ActivePage.Shapes.ItemFromID(cID)

   If CableClass = "Primary" Then
        shp3.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
        shp3.Cells("Prop.Row_CableType.Format").FormulaU = """Cable 1;Cable 
        2;Cable 3;Cable 4"""
   ElseIf CableClass = "Secondary" Then
       shp3.Cells("Prop.Row_CableClass.Value").FormulaU = """Secondary"""
       shp3.Cells("Prop.Row_CableType.Format").FormulaU = """Cable 1;Cable 
       2;Cable 3;Cable 4"""
   End If

   If TrayClass = "Primary" Then
       shp3.Cells("Prop.Row_TrayClass.Value").FormulaU = """Primary"""
       shp3.Cells("Prop.Row_TrayType.Format").FormulaU = """cable tray 
       1;cable tray 2;cable tray 3;cable tray 4"""
   ElseIf TrayClass = "Secondary" Then
       shp3.Cells("Prop.Row_TrayClass.Value").FormulaU = """Secondary"""
       shp3.Cells("Prop.Row_TrayType.Format").FormulaU = """cable tray 
       1;cable tray 2;cable tray 3;cable tray 4"""
   End If
   Unload Me
End Sub

从形状数据中选择特定类型的电缆或托盘后,我希望成本会根据所选内容自动更改。换句话说,我希望根据从下拉框中选择的电缆类型动态更改一个形状数据(成本)。

标签: vbavisio

解决方案


不是一个完整的答案,但对于评论来说太长/太复杂了:

在您的用户表单代码后面:

Private Sub CableClass_Change() 
  SetCableClassValues CableClass, shape
End Sub

Private Sub TrayClass_Change() 
  SetTrayClassValues TrayClass, shape
End Sub

在单独的标准模块中:

Public Sub SetCableClassValues (ByVal cableClass as ComboBox, ByVal theShape as Visio.Shape)
  theShape.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
  theShape.... 'set the appropriate cost value here
End Sub

Public Sub SetTrayClassValues (ByVal trayClass as ComboBox, ByVal theShape as Visio.Shape)
  theShape.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
  theShape.... 'set the appropriate cost value here
End Sub

请注意,这都是“空气编码”,因此它不会完全按照所写的那样工作。但是,一旦您进入SetCableClassValues例程,您就可以访问cableClass组合框中的所有内容,就像您直接在代码隐藏中一样。您还可以访问- 您在现有代码中theShape拥有的任何一个,您将作为参数传入。shp3shape

如果您需要这两种信息来确定成本,那么您将有 1 个例程将组合框和形状作为参数,确保两者都选择了有效值,然后进行所有更新。

我对 Visio 对象模型一点也不熟悉,所以你必须弄清楚如何设置成本,但看起来你已经有足够的理解来处理这部分了。


推荐阅读