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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 dlgfile i/o

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
gzforever Posted - 12/05/2016 : 3:40:14 PM
Hello,

1)
I want to create a script,which shows the message
type -b File not chosen

in case the user press "cancel" button in dlgfile dialogbox.
Is this possible ?

2)Is there any command, which can finish the script immediately from any place ? (i mean something like exit() in C/C++)

I want to create coditional instruction which shows the message i mentioned above and then finish the script.

Regards,



8   L A T E S T    R E P L I E S    (Newest First)
Chris D Posted - 12/16/2016 : 4:31:12 PM
Hi gzforever and others,

For a good example of how to use the dlgFile X-Function in a robust manner, see the Example section on the dlgFile documentation page:
http://www.originlab.com/doc/X-Function/ref/dlgFile

If you have selected multiple files and need to extract each individual file name, you can use two methods of LabTalk string variables: GetNumTokens() and GetToken(). More information about those methods are available on this page:
http://www.originlab.com/doc/LabTalk/ref/String-obj#GetNumTokens
http://www.originlab.com/doc/LabTalk/ref/String-obj#GetToken


Thanks,
Chris Drozdowski
Originlab Technical Support
gzforever Posted - 12/16/2016 : 05:25:42 AM
Hi CP,

Thank you so much, you really helped me !
cpyang Posted - 12/15/2016 : 8:45:58 PM
This should work, try it. Run.section can return an integer value, so you don't need to use a variable.



[Main]

for(i=1;i<5;i++)
{
	if(run.section(,cfile)==1)
		break 1;
	type "File$(i): %(fname$)";
}

[cfile]
fname$="";//need to empty it so later can test length
{dlgfile m:=1;}
int z=fname.GetLength();
if (z==0)
{
	type "User Cancel";
	return 1;
}
return 0;//file chosen



CP
gzforever Posted - 12/15/2016 : 2:56:47 PM
Hi,

I still have problem. I prepared example code to make it more simple:

int l=1;
for(i;i<5;i++)
{
	run.section(,cfile)
	if (l==0)
		break 1;
        del -vs fname;
}

[cfile]
{dlgfile m:=1;}
int z=fname.GetLength();
if (z==0)
{
	type -b "File not chosen";
	l=0;
	break 1;
}
type -b "File chosen"


My goal is to detect, whether user pressed cancel button in dlgfile window. This code works well, except the 1st iteration.

When user press cancel button in 1st iteration i receive the following message in command window (it doesn't happen during next iterations) :
Mismatch double quote: FNAME.GETLENGTH()


It doesn't stop the script, it still plots "file not chosen", however i want to fix this somehow.

Regards,
JZ
gzforever Posted - 12/06/2016 : 5:58:56 PM
Ok guys, i figured out how to solve the main problem, but still have no idea how to terminate entire script.

Here is solution (maybe in the future someone will look for this) :

To choose file script runs this section :

[choosefile]
{
dlgfile;
}
int z=fname.GetLength();
z=; // used during testing
if (z==0)
{
	if(l>1)
		run.section(,format); // format graph if exist
	type -b "File not chosen. Script will be closed";
	break 1; // i want to end entire script, but it doesn't work
}
strn$ = fname.GetFileName(1)$; // used in other section (global var) 
strn$=; // used during testing
l=l+1; // counts how many times dlgfile was opened (global var)


at the end of every iteration of the loop following command is executed:

del -vs fname;// clears the path of imported file


Everything works fine, but i still have problem with closing the script immediately. In the line where break 1; is, i should put the command which closes the entire script, not only the section. I really tried to find it, but in the Help are only break instructions which allows to leave from the loop or brackets.

EDIT
Problem fixed by adding l=0; before break 1; in [choosefile] section and conditional instruction if(l==0) break 1; in the loop. (in my script it had to be nasty nested, but works )

Anyway if there is any command which terminates the whole script i will enjoy it .

Best Regards,


gzforever Posted - 12/06/2016 : 1:03:36 PM
Hi,

Thank you for your efforts guys, i really appreciate it. Unfortunately both solutions has disadvenatages and i cannot apply them

My script works in the loop. In every iteration user adds one file.

1) In yuki's solution i can't excute any section from my code (in newdlgfile), before showing the message. I also share my scripts as .ogs files, and i assume that newly created newdlgfile works only in origin on my computer.


2) Chris solution looks nice for me, because sometimes i want my script to do more than only show the message ( for instance execute some section and then show the message and close the script ). However it doesn't work in the loop. I created simple testing code:

for(i=1;i<6;i++)
{
{dlgfile fname:=strFile$;}
int a =strFile.GetLength();
a=;
a=0;
}


Even if user doesn't choose file, origin counts the last chosen file lenght.

EDIT:
Last thought. Perhabs there is a manner to make origin forget the last chosen file ? The script could do it after every iteration.

Kind Regards,


Chris D Posted - 12/06/2016 : 10:23:56 AM
Hi,

You can also find out if user clicked Cancel button directly in LabTalk without modifying the X-function as per the example below.


string strFile$;
{
dlgfile group:="*.csv" fname:=strFile$;
}
if (0 == strFile.GetLength())
{
	type -b "File not chosen";
	return;
}
type -b "File Chosen";

The brackets around the dlgfile call serve to trap error output if user clicks cancel.

Thanks,
Chris Drozdowski
Originlab Technical Support
yuki_wu Posted - 12/05/2016 : 10:01:15 PM
Hi JZ,

To question 1:
1.Press F10 to open X-Function Builder
2.Click Open button to find out <Program folder>\X-Function\Utilities\File\dlgFile.OXF
3.Click File: Save as to save the OXF file to NewdlgFile
4.Click Code Builder button to open Code Builder
5.Add “type -b” in code, just like below:

type -b File not chosen
XF_THROW(XFERR_UI_USER_CANCEL);

6.Click Compile button in the top of the Code Builder
7.Click Save button and close X-Funtion Builder dialog
8.Replace dlgFile in your code with NewdlgFile



To question 2:
Break can be used to exit from a loop, a script, or a progress dialog box. Please read the following page:
http://www.originlab.com/doc/LabTalk/ref/Break-cmd

Hope it helps.

Regards,
Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000