Handling a text field that is null on reading

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

Handling a text field that is null on reading

Postby Battwell » Sun May 09, 2021 4:58 pm

If I read a text field string that is Null ( empty)
What is the best way to handle it before trying to convert to double etc?
As this throws an exception
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 827
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Handling a text field that is null on reading

Postby dezsoe » Sun May 09, 2021 11:10 pm

Use TryParse:

Code: Select all
double fieldValue;

if (!Double.TryParse(AS3.Getfield(12345), out fieldValue))
{
  exec.AddStatusmessage("Cannot convert to double");
  return;
}
dezsoe
 
Posts: 2055
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Handling a text field that is null on reading

Postby Battwell » Wed May 12, 2021 4:43 pm

That works well
Thank you
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 827
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk


Return to Macros

Who is online

Users browsing this forum: Bing [Bot] and 0 guests