Read Key Function

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Read Key Function

Postby valhallaCNC » Thu Dec 08, 2022 2:58 am

I have been working on the Offset screen , trying to Incorporate it on the main screen. I can read the .pro file and display the string in my field box. I have this bit of macro that I have been using, it works fine.

Code: Select all
String GetXG54Value = exec.Readkey("Workoffset_G54", "WorkoffsetX", "False");
decimal MyXG54Value = System.Convert.ToDecimal(GetXG54Value);
AS3.Setfieldtext(MyXG54Value.ToString("F4"), 3502);

My question. Is there a better way to show only 4 decimal places such as x.xxxx the value in the .pro file has more decimal places then I want to display . My way works, but it seems like there could be a simpler way.
Any input would be great. Thanks
valhallaCNC
 
Posts: 65
Joined: Wed Jun 30, 2021 8:04 pm

Re: Read Key Function

Postby dezsoe » Thu Dec 08, 2022 6:34 am

I'm sure that this is the way to do it. (I'd use double instead of decimal, but that's another question.)
dezsoe
 
Posts: 2055
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Read Key Function

Postby fsli » Thu Dec 08, 2022 11:52 am

valhallaCNC wrote:Is there a better way to show only 4 decimal places such as x.xxxx the value in the .pro file has more decimal places then I want to display.

I use a similar technique. The only difference is I'll reference the configured number of digits, in case it is not the default four positions.

int droDigits = AS3.Getfieldint(195); // PositionDROdigits

decimal textDecimal = Convert.ToDecimal(unformattedText);

string formattedText = textDecimal.ToString(String.Format("f{0}", droDigits));


If I'm using the numeric value for purposes other than displaying the text, then I will also use Decimal values and Math.Round(textDecimal, droDigits) to enforce the scale.
Frank
fsli
 
Posts: 93
Joined: Mon Jul 11, 2022 12:36 am

Re: Read Key Function

Postby valhallaCNC » Thu Dec 08, 2022 2:27 pm

Thanks... I did see the Convert.ToDouble method after I posted the question.
valhallaCNC
 
Posts: 65
Joined: Wed Jun 30, 2021 8:04 pm


Return to Macros

Who is online

Users browsing this forum: No registered users and 4 guests

cron