• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

macro vba - separatore decimale

  • Thread starter Thread starter Mithas
  • Start date Start date

Mithas

Guest
Good day to all.
I have a problem that's making me waste a lot of time.

I created a solid parametric model that can be governed by a vba macro through userforms with text boxes to be filled out. the macro function and does its work but from problems with decimal separators that just do not like them.

in the system (windows) is set the comma as a separator, in solid is set the use of the system separator, then the comma. in the macro in vba you can write decimal values only with the point, the comma from compilation error.

changing the system setting works everything. or see the decimals after the point as it does vba.
I therefore gave my problem solved.

At work however, we have an external pdm and a management that mess with the point. example: now I have some bushings that weigh 600kg and not 600g.

Do you have any idea how to do this? Is there a way to tell vba, in the macro, to format the numbers sent to the model with the comma and not with the point?
 
Hi.
is a common problem (I will use the point as a decimal separator of windows).
I think you have more roads:
- try to change the decimal separator in solidworks settings (see attached image
- in case this is not okay you could use the replace cover function by stringing your double and replacing the decimal separator as you want and then revert it in double
- if you have to turn into different pcs where it is not said that the decimal separator is set equal for everyone,
You could change point 1 by code depending on what you need and then reset it.

dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
sub main()
set swapp = application.sldworks
Start code
swapp.setuserpreferencetoggle swuserpreferencetoggle_e.swusesystemseparatorfordims, false
boolstatus = swapp.setuserpreferencestringvalue(swuserpreferencestringvalue_e.swseparatorcharacterfordims, ",")
''''' my code
''
''
'Then end code
swapp.setuserpreferencetoggle swuserpreferencetoggle_e.swusesystemseparatorfordims, true
boolstatus = swapp.setuserpreferencestringvalue(swuserpreferencestringvalue_e.swseparatorcharacterfordims, ".")

end


Try as soon as possible, in case you need I am there until tomorrow, then if God wants me to go to vacation too.

Cattura.webp)
 
Hi, jenuary.

Thank you very much for the immediate answer.
Now I try your advice and I can tell you.

the problem I think is in the passage of data from vba to solid.

I use the equation manger to pass data encapsulated from textboxes by string type:

swem = swmodel.getequationmgr()


If the mspi1 variable has decimals, it cannot write it.

The thing I can't understand is:

- in the management of solid equations the values have the point
- within the vba code the values of the memorrized "freedoms" to which I refer have the point
- in the textbox values are displayed with commas

in fact if I try to rewrite in the textbox the values with the point and pass them to solid it all works.
 
done. . .

mspi1 = replace(mspi1, ",", ".")

being values stored as string that are then passed to the equation manager just replace the comma with the point, before writing in solid.

looks like the best solution.

Thanks for the advice. I had something harder in mind.
 
Hi.
Actually, when you pass a number from a textbox (so a string) you should pass it this way if it has commas:

dim number_decimal as double
number_decimal= textbox .value

where textbox is the box where you wrote the number
 
I can't do that because of how I built the model.

in practice the macro works like this:

- reads the values of the global variables of the sw model, with a function similar to what you wrote but connected to the value of the global equation.
- assigns the values to the textboxes of the appropriate name and shows them in the userform.
- replaces global sw variables with new ones, as written above.

solid then accepts only full string values (formed as above) as global equation.

we say however that I can go on holiday happy now that I managed to make it work. . .

:
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top