Userform macro SolidWorks

Hello

I have a whole series of options to set up on SolidWorks using macros such as:

- a Ø2 drilling at such a position of the top of my part

- a screwdriver slot

- a groove for gasket

-etc...

In total I have 20 including the "no options" option

And I wanted to know how to do it, if I have to use the If and ElsIf functions for each option or if there are other methods?

Thank you in advance for your answers

Hello

If I understand correctly, these are checkboxes, so yes, you'll have to deal with if/else or select case (the second one is faster, but for my part, never had any problems with if/else).

After all, it all depends on what you want to do exactly (checking the boxes checked, incompatibility of choice...)

3 Likes

In my Userform I made a Listbox where we have:

U "00" -> no options

U "01" -> drilling Ø2

U "02" -> groove for gasket

... until the 21st

So I note:

"If U = (option number) Then" OR "If U "00" select Then"

I don't know exactly how I should proceed with this function

I prefer Cyril.f, for my use of a Select Case (Equivalent of a Switch in other languages, such as PHP, Java, etc)

Here is a processing example code (I put a full macro for the example as an attached file):

Private Sub BtValid_Click()
    'We do a treatment on the value
    Select Case ComboBox.Value
        Box "U1":
            MsgBox "I'm doing a treatment on U1"
        Box "U2":
            MsgBox "I'm Displaying U2"
        Box "U3":
            MsgBox "I'm U3"
        Case Else
            MsgBox "Default Processing on Value" & ComboBox.Value
    End Select
End Sub

 

Edit: Note that I only do the processing on the U1, U2 and U3 values, all the other values will take the "Case Else".


example.swp
1 Like

That's not exactly what I want to do, I prefer to use the if and else functions.

I would like my macro to have for example:

If the U14 square is selected, then take such and such a plane, make a circle of such and such a Ø, etc etc

I just don't know how to say that in a vba language and that's all I need

>If the U14 square is selected then take such and such a plane make a circle of such and such a Ø etc etc

Well you can do it here:

Box "U1":
     'Here you do your treatment, take this plane make a circle of such and such a Ø
Box "U2":
     Treatment for U2

This is equivalent to:

If ComboBox.Value = "U1" Then
   Treatment for U1
Elseif ComboBox.Value = "U2" Then
  Treatment for U2

Endif

 

The first solution I gave is just shorter.