Page 1 of 1

loop with enumerators In VBA

Posted: Tue Feb 06, 2024 5:47 am
by mp3-250
I would like to read all those properties. is it possible to use a loop to get them or do i have to read themone by one with a separate call?

something more elegant than copy and paste in excel 100s of lInes, put some code before and after the enumerators and pasting back on the VBA IDE...

https://help.solidworks.com/2018/englis ... lue_e.html

Re: loop with enumerators In VBA

Posted: Tue Feb 06, 2024 7:19 am
by gupta9665
I do not think that you can loop through them and will have to read them one by one only with separate line of code.

Re: loop with enumerators In VBA

Posted: Tue Feb 06, 2024 8:08 am
by JSculley
mp3-250 wrote: Tue Feb 06, 2024 5:47 am I would like to read all those properties. is it possible to use a loop to get them or do i have to read themone by one with a separate call?

something more elegant than copy and paste in excel 100s of lInes, put some code before and after the enumerators and pasting back on the VBA IDE...

https://help.solidworks.com/2018/englis ... lue_e.html
One more reason to abandon VBA and use VB.NET or C#. It's a two liner in those languages:

Code: Select all

foreach (swUserPreferenceDoubleValue_e val in Enum.GetValues(typeof(swUserPreferenceDoubleValue_e)))
{
    Debug.Print(val.ToString() + " = " + swApp.GetUserPreferenceDoubleValue((int)val));
}

Re: loop with enumerators In VBA

Posted: Tue Feb 06, 2024 2:58 pm
by mp3-250
JSculley wrote: Tue Feb 06, 2024 8:08 am One more reason to abandon VBA and use VB.NET or C#. It's a two liner in those languages:

Code: Select all

foreach (swUserPreferenceDoubleValue_e val in Enum.GetValues(typeof(swUserPreferenceDoubleValue_e)))
{
    Debug.Print(val.ToString() + " = " + swApp.GetUserPreferenceDoubleValue((int)val));
}
codestack has something similar in VB.NET unfortunately I am not a programmer and my company would need to buy a visual studio license for me to "play" with this.

I was hoping at least for something like a numerical "alias" for the enumerators to invoke them with for loop. like having them in an array and loop with the index to read the property.

I probably end up with 100 lines anyway but one the loop code, making a bit more readable and flexible for other kind of properties.

well it was for my personal understanding as I still struggle to grasp many concepts with VBA.
my code works, but sometimes more than intuition I would like to know why...

Re: loop with enumerators In VBA

Posted: Thu Feb 08, 2024 12:12 am
by gupta9665
mp3-250 wrote: Tue Feb 06, 2024 2:58 pm codestack has something similar in VB.NET unfortunately I am not a programmer and my company would need to buy a visual studio license for me to "play" with this.
You can install the free community license at home to play with.