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
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
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: 1508
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
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk


Return to Macros

Who is online

Users browsing this forum: No registered users and 1 guest