0

I am working with multiple userforms in vbscript.

I am creating an object in a userform and trying to call it in another userform. I tried declaring the object as Public in both the userforms but still I am not able to acess the object from another userform.

Look Forward for your help.

Thanks in advance.

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   

Here, Inner_V1 is the object which i Need to use from Userform1.

user3714887
  • 77
  • 3
  • 16

2 Answers2

0

Add a Property to the form containing the object.

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
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • UserForm2 is just a UserForm, If its a VBA environment hosting Microsoft Forms (as it presumably is) then its fine. – Alex K. Jul 01 '15 at 12:53
  • Alex Thank you for your reply. But i could not understand your code. In the Userform1: I am declaring an object as "Public object1 As Object" and settin a value. Which I am not able to get it Userform2: Here I am trying to get the value of the object1. – user3714887 Jul 01 '15 at 13:02
  • My *example* uses a `Collection`, substitute that with your object. – Alex K. Jul 01 '15 at 13:08
  • When i give.... "Set Inner_V11 = New Object" I get a error message "Expected: Identifier" – user3714887 Jul 01 '15 at 13:25
  • You will need to edit your question and add the relevant code – Alex K. Jul 01 '15 at 13:27
0

The answer is simple I just have to call Userform1.Inner_V1

user3714887
  • 77
  • 3
  • 16