File loading problem

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

File loading problem

Postby MrCactus1 » Sun Nov 13, 2022 10:17 pm

I'm sure it's me but I have two fields that I compare the values of. One field is a spot to make an offset to the program. The other field takes the value and holds onto it to see if a large offset is made outside a set tolerance on the next updated value.
The program runs fine and does what it is supposed to. Until you load a new file. Then it stops working and has the following error - see attached Doc1.pdf.
After I start the program with cycle start or single line. Then the program works again.
Any ideas?
Attachments
M801.txt
Program
(2.91 KiB) Downloaded 255 times
Doc1.pdf
Error
(186.07 KiB) Downloaded 284 times
MrCactus1
 
Posts: 10
Joined: Thu Oct 27, 2022 9:04 pm

Re: File loading problem

Postby MrCactus1 » Mon Nov 14, 2022 1:11 am

It appears that the problem is surrounding this statement - double pal = exec.Question("Which Work Offset to Update?" + "\n" + "54, 56 - 59");
double valu = pal;

Is the double declaration for pal correct? One would think that this should be a string. Since it is asking a question.
I am now getting this error -

UCCNC macro compiler error log file
--------------------------------------
Last error dated: 11/13/2022 7:58:22 PM
In macro: M801
--------------------------------------
CS0103 | in line: 44 | error text: The name 'pal' does not exist in the current context
--------------------------------------

line 44 is this statement - double valu = pal; SInce these are both declared as double there should be no problems.

Am I missing something here????


Also while I am talking about - Example: double val = exec.Question("What X position to move?");
When the question form opens up, the red X at the top right of the window does nothing. Should close the form.
MrCactus1
 
Posts: 10
Joined: Thu Oct 27, 2022 9:04 pm

Re: File loading problem

Postby betelgueze » Mon Nov 14, 2022 9:16 am

I opened your macro in Notepad++.
And in line 23, you have printed, ov:
I can not se that its declared anyway?
I dont know if it is correct that it should be there, but if it is. I think it should be ov; instead of ov:
Im just an amateur with programing,so im not shure ?

Here is the part:

ov:
if ((current < 53) || (current == 55)){
double val = exec.Question("Which Work Offset to Update?" + "\n" + "54, 56 - 59");
current = val;
}
if (current == 55){
current = 0;
MessageBox.Show("Can not update Work Offset G55","Can not update.",MessageBoxButtons.OK,MessageBoxIcon.Stop);
goto ov;
}

The error probably is about that you have not declared "pal". Like: double pal = 0.0; or something like that.
I dont see a line with "pal" anywer. But you have a line with "val".

Hope this is to any help, and good luck with your macro.
betelgueze
 
Posts: 11
Joined: Thu Apr 08, 2021 5:32 pm
Location: Sweden

Re: File loading problem

Postby fsli » Mon Nov 14, 2022 12:55 pm

The error is at the beginning:
double current = exec.Getvar(6); // Retrieve value in internal macro varaible #6. Work Offset.

Variable #6 hasn't been set, so the return value from Getvar is null, and can't be converted to a double. You'll need to modify the macro to protect against that possibility. I don't see anything in this macro that's updating #6, so I'm guessing it's being done in a different macro or the g code program.

Not related to the error: Where do you define "loop"? At the top of the macro you have:
while(loop)

... I don't see it being defined/declared anywhere.

I'd also question why you'd want to execute the macro body more than once anyway. There's a lot of other things in that macro that I'd change, from an aesthetics perspective. Your use of goto is poor practice, and can easily be converted to a while. You convert to double too often. That is, you convert a string to double and put it into one variable, then you convert the same, unchanged string again and put it into a different variable, or you convert the same string to double as part of an if predicate. You should read about the switch statement in C#, too.
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: File loading problem

Postby dezsoe » Mon Nov 14, 2022 1:37 pm

Frank,

#6 is zero until it gets another value, no problem.

Check the UCCNC manual for macroloops. The loop variable is defined by the system. It is true when you start a macroloop and gets set to false when you press Stop in the macroloop config window.

I agree with you about the goto, however, if you decompile .Net programs then you'll find that the compilers often use it to optimize the code.

betelgueze,

The ov: is a label and the goto jumps there.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: File loading problem

Postby MrCactus1 » Mon Nov 14, 2022 2:35 pm

You are correct I have val and pal. I started switching the words around thinking that val might be a restricted word. Just never got all of them done there was no point. I spent hours on this yesterday.
MrCactus1
 
Posts: 10
Joined: Thu Oct 27, 2022 9:04 pm


Return to Macros

Who is online

Users browsing this forum: Google [Bot] and 7 guests