loop with enumerators In VBA

Programming and macros
User avatar
mp3-250
Posts: 630
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 702
x 347

loop with enumerators In VBA

Unread post 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
User avatar
gupta9665
Posts: 410
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 433
x 447

Re: loop with enumerators In VBA

Unread post 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.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
JSculley
Posts: 643
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 877

Re: loop with enumerators In VBA

Unread post 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));
}
User avatar
mp3-250
Posts: 630
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 702
x 347

Re: loop with enumerators In VBA

Unread post 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...
User avatar
gupta9665
Posts: 410
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 433
x 447

Re: loop with enumerators In VBA

Unread post 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.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
Post Reply