The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Code Builder window activates during script run
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

theBestestClaudi

Germany
2 Posts

Posted - 04/28/2021 :  04:38:44 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi!
I am curious about a problem that I've encountered several times now. For context, I'm writing my script in LabTalk and have integrated it into a button in Origin, so I can quickly save and run the project to see, if the code works as expected or not.

Now the problem: Usually, the script runs or fails, all within the Origin project-window. But sometimes, it just switches to the Code Builder window. It will still run the script as before, but to see the result, I have to switch into the Origin window again.

I could pinpoint the code section that seems to be responsible for this phenomenon (see code at the end). But I've experienced this behaviour in other scripts as well.

Does anyone have an idea, what this window-switch indicates or how it can be explained? Did I make an obvious mistake or does it have to do with something deeper, like run times or memory? Or is it just an annoying glitch that I shouldn't worry about? I'm curious for your ideas!



Example code section:

//geht durch alle cycles und kopiert die cyce-infozeile
for (cycle = 1; cycle <= cyclestotal; cycle++)		//geht duch alle cycles
{
	wrcopy iw := [%B]Rohdaten! r1 := $(cyclerow) r2 := $(cyclerow) ow := [%B]Bericht_cycle! dr1 := $(cycle);	//kopiert cycle daten
	stepinforow = cyclerow + 1;	//zeile, in der die step-info steht

//geht im cycle durch alle steps	
	for (cycleend = 0; cycleend < 1;)				//step-bedingung während eines cycles. ACHTUNG! das ist ein infinite loop! loopt so lange, bis die variable verändert wird.
	{
		
//kopiert die step-infos ins bericht-wks und findet den nächsten step
		wrcopy iw := [%B]Rohdaten! r1 := ($(stepinforow)) r2 := ($(stepinforow)) ow := [%B]Bericht_steps! dr1 := $(step);	//kopiert die step infos

//sucht alle datenpunkte dieses steps
		stependtime$ = col(4)[stepinforow]$;			//merkt sich die endzeit des steps aus der step-info-zeile
		stepfirstrow = stepinforow + 1;				//das ist die erste datenzeile dieses steps
		steplastrow = 1;					//letzte zeile des steps. die 1 ist wilkürlich, wert wird erst im folgenden loop zugewiesen
		for (ii = 1; ii <= rowstotal; ii++)			//geht durch alle zeilen (bis zum ende, bzw. bis break kommt). das rowstotal ist hier nur eine beliebige zahl, damit es kein endelss loop ist.
		{
			checkrow = stepinforow + ii;			//das ist die gerade betrachtete zeile
			currenttime$ = col(3)[checkrow]$;		//und der zugehörige zeitstempel
			int islaststeprow = compare(stependtime$, currenttime$);	//hier wird der zeitstempel mit dem letzten zeitstempel aus der step-info-zeile vergleichen. die variable wird 0 wenn ungleich udn 1 wenn gleich.
			if (islaststeprow == 1)				//abbruchbedingung (wir haben den letzten eintrag dieses steps gefunden)
			{
				steplastrow = checkrow;
				break;
			}
		}
//kopiert die messdaten ins Messdaten-wks
		wrcopy iw := [%B]Rohdaten! r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]Messdaten! dr1 := $(recordid);	//kopiert die messdaten alle zusammen
		recordid = recordid + (steplastrow - stepfirstrow) + 1;		//das wird die erste zeilte für die daten des nächsten steps

//kopiert ausgewählte werte nach key_data
		wrcopy iw := [%B]Rohdaten! c1:=8 c2:=8 r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]key_data! dc1 := <new>;
		wrcopy iw := [%B]Rohdaten! c1:=4 c2:=4 r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]key_data! dc1 := <new>;
		wrcopy iw := [%B]Rohdaten! c1:=3 c2:=3 r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]key_data! dc1 := <new>;		//kopiert die daten aus den gewählten columns in neue spalten des key_data-wks
		page.active$ = key_data;						//aktiviert das key_data-wks
		col($((3 * step - 2)))[L]$ = "Capacity Density";
		col($((3 * step - 2)))[U]$ = "mAh/g";
		wks.col$($(3 * step - 2)).type = 4;					//ändern den plot designator (machen eine X-Spalte aus den Spalten)
		col($((3 * step - 2)))[C]$ = step $(step);				//fügt ein comment der form "step 1" etc. hinzu
		col($((3 * step - 2) + 1))[L]$ = "Voltage";
		col($((3 * step - 2) + 1))[U]$ = "V";
		col($((3 * step - 2) + 1))[C]$ = step $(step);
		col($((3 * step - 2) + 2))[L]$ = "Time";
		col($((3 * step - 2) + 2))[U]$ = "h:mm:s.ms";
		col($((3 * step - 2) + 2))[C]$ = step $(step);
		page.active$ = Rohdaten;						//zurück zum wks damit es weiter gehen kann	
		step = step + 1;							//zählt die steps hoch
	
//prüfen, ob schon alle daten verarbeitet wurden
		if (steplastrow >= rowstotal)
		{
			type -a "alle daten sind verarbeitet";		//#DEBUGGING
			break;
		}
	
//prüfen nach abbruchbedingung, um in den nächsten cylcle zu kommen (andernfalls gebinnt ein neuer step)
		%Z = col(1)[steplastrow + 1]$; //steplastrow + 1
		if (%Z >= 1)
		{
			cycleend = 1;					//abbruchbedingung für den cycle-loop
			cyclerow = steplastrow + 1;			//das setzt die nächste cycle info zeile fest für den nächsten loop
		}
		else
		{
			stepinforow = steplastrow + 1;
		}
	}		//ende step
}			//ende cycle

Chris D

428 Posts

Posted - 04/29/2021 :  12:32:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you narrow down a bit more where the problem lies or perhaps simplify it?

We can't run your script because we don't have the "context" in which to run it.



Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

theBestestClaudi

Germany
2 Posts

Posted - 05/14/2021 :  07:32:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry, can't narrow it down. It's an interconnected logic that fails when I remove part of it. I'm not an IT-person and this is the best I can do...

However, I have now noticed this behaviour with another script, too. While the script is running, another window is activated. I think it switches between the last two active windows, so if I had the code builder open, it will activate that, or if I was looking something up in the browser, it will activate that. Anyway, the script will finish in the back. I thought it might be because I code somehow...funny? Not efficient? Too many comments? Too much memory needed? I don't know. At this point I kinda gave up trying to understand what Labtalk is doing...
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000