我正在使用vbscript中的多个用户表单。
我在userform中创建一个对象,并尝试在另一个userform中调用它。 我尝试在两个用户表单中将对象声明为Public,但我仍然无法从另一个用户表单中获取对象。
期待您的帮助。
提前致谢。
Userform1:
Public Inner_V1 As Object
Private Sub Inner_V1_CD_Click()
'Auswahlfenster ausblenden
Input_selection2.Hide
'Dim myDoc As Document
Set myDoc = CATIA.ActiveDocument
On Error Resume Next
Set ActivePart = CATIA.ActiveDocument.Part
If Err.Number <> 0 Then
On Error GoTo 0
Box = MsgBox("Das geöffnete Dokument ist kein CATPart!" + Chr(10) + "Das Makro wird beendet", vbExclamation, "Falscher Dateityp")
Unload Input_selection2
Exit Sub
End If
' Selektion definieren und leeren ----
Dim UserSel As Object
Set UserSel = myDoc.Selection
UserSel.Clear
'-------------------------------------
' User wählt die Fläche aus #############################################################################
' Auswahl festlegen -------------------
Dim Was1(0)
Was1(0) = "HybridShape"
'--------------------------------------
Dim Auswahl 'Wird für die SelectElement2 Methode benötigt (Auswahl durch User)
Auswahl = UserSel.SelectElement2(Was1, "Bitte die Fläche auswählen.", False)
If Auswahl = "Normal" Then
Set Inner_V1 = UserSel.Item(1).Value
Inner_V1.Value = Inner_V1.Name
Else
Unload Input_selection2
Exit Sub
End If
' Selektion freigeben -----------------------------------------------------
UserSel.Clear 'User-Auswahl löschen
'Auswahlfenster anzeigen
Input_selection2.Show
End Sub
Userform2:
Private Sub Weiter_Click()
Set hybridBodies1 = part1.HybridBodies
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "test"
Set reference1 = part1.CreateReferenceFromObject(Inner_V1)
Set reference2 = part1.CreateReferenceFromObject(Guide_curve)
Set sweep_v1 = hybridShapeFactory1.AddNewSweepExplicit(reference1, reference2)
Set reference3 = part1.CreateReferenceFromObject(Support_V)
hybridBody1.AppendHybridShape sweep_v1
End Sub
这里,Inner_V1是我需要在Userform1中使用的对象。
答案 0 :(得分:0)
将属性添加到包含该对象的表单中。
E.g。
<强> UserForm1 强>
Private Sub UserForm_Click()
Dim uf2 As UserForm2
Set uf2 = New UserForm2
uf2.Col.Add Now, "K"
uf2.Show
End Sub
<强> UserForm2 强>
Private mCol As Collection
Private Sub UserForm_Initialize()
Set mCol = New Collection
End Sub
Public Property Get Col() As Collection
Set Col = mCol
End Property
Private Sub UserForm_Activate()
MsgBox mCol("K")
End Sub
答案 1 :(得分:0)
答案很简单我只需要调用Userform1.Inner_V1