User Tools

Site Tools


using_20openin_20_28etc._29_20with_20wildcards

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
using_20openin_20_28etc._29_20with_20wildcards [2018/03/31 13:19]
127.0.0.1 external edit
using_20openin_20_28etc._29_20with_20wildcards [2018/04/17 19:19] (current)
tbest3112 Added syntax highlighting
Line 2: Line 2:
  
 //by Richard Russell, June 2010//\\ \\  The BBC BASIC [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​openin|OPENIN]],​ [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​openout|OPENOUT]] and [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​openup|OPENUP]] functions generally take an **unambiguous** filename as their parameter. In //BBC BASIC for Windows// you can instead supply an **ambiguous** filename, that is a filename containing one or more **wildcard** characters: **?** (standing for a single character) or * (standing for any number of characters).\\ \\  In that case, since the supplied parameter doesn'​t specify a unique file, a **file selector** (Open File dialogue) is displayed, allowing the user to select a file. The files listed are filtered according to the supplied parameter, so in the case of the following code:​\\ ​ //by Richard Russell, June 2010//\\ \\  The BBC BASIC [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​openin|OPENIN]],​ [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​openout|OPENOUT]] and [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​openup|OPENUP]] functions generally take an **unambiguous** filename as their parameter. In //BBC BASIC for Windows// you can instead supply an **ambiguous** filename, that is a filename containing one or more **wildcard** characters: **?** (standing for a single character) or * (standing for any number of characters).\\ \\  In that case, since the supplied parameter doesn'​t specify a unique file, a **file selector** (Open File dialogue) is displayed, allowing the user to select a file. The files listed are filtered according to the supplied parameter, so in the case of the following code:​\\ ​
 +<code bb4w>
         file% = OPENIN("​*.ABC"​)         file% = OPENIN("​*.ABC"​)
 +</​code>​
 only files with the extension **ABC** are (initially) displayed for the user to select from.\\ \\  If the user chooses to cancel the operation (by clicking the **Cancel** button in the dialogue box) an **Escape** error is triggered. This happens even if the Escape key has been disabled using ***ESC OFF** (see [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwini.html#​hint1|here]] for a workaround).\\ \\  When a file has been selected by the user the OPENIN (or OPENOUT, OPENUP) function returns a channel number in the usual way, or zero if the file cannot be opened. There is no official way (in **Windows XP** and earlier) for the user's program to discover which file the user selected, but the following code can be used to do so:\\  only files with the extension **ABC** are (initially) displayed for the user to select from.\\ \\  If the user chooses to cancel the operation (by clicking the **Cancel** button in the dialogue box) an **Escape** error is triggered. This happens even if the Escape key has been disabled using ***ESC OFF** (see [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwini.html#​hint1|here]] for a workaround).\\ \\  When a file has been selected by the user the OPENIN (or OPENOUT, OPENUP) function returns a channel number in the usual way, or zero if the file cannot be opened. There is no official way (in **Windows XP** and earlier) for the user's program to discover which file the user selected, but the following code can be used to do so:\\ 
 +<code bb4w>
         file% = OPENIN("​*.*"​)         file% = OPENIN("​*.*"​)
         filename$ = $$!420         filename$ = $$!420
 +</​code>​
 Assuming **file%** is non-zero, the path and filename of the selected file is placed in the variable **filename$**.\\ \\ //addition by Michael Hutton, edited by Richard Russell, June 2012//​\\ ​ The easiest way of discovering the filename is the above method, but it can also be achieved using the code below, which does not require accessing the interpreter'​s internal variables. However the API function used is available only on **Windows Vista** or later, therefore its use will result in your program being incompatible with Windows XP, which is still used in very large numbers:\\ \\  Assuming **file%** is non-zero, the path and filename of the selected file is placed in the variable **filename$**.\\ \\ //addition by Michael Hutton, edited by Richard Russell, June 2012//​\\ ​ The easiest way of discovering the filename is the above method, but it can also be achieved using the code below, which does not require accessing the interpreter'​s internal variables. However the API function used is available only on **Windows Vista** or later, therefore its use will result in your program being incompatible with Windows XP, which is still used in very large numbers:\\ \\ 
 +<code bb4w>
         file% = OPENIN(file$)         file% = OPENIN(file$)
         REM Get the file name if was chosen in dialog         REM Get the file name if was chosen in dialog
Line 22: Line 27:
         IF R%=0 THEN ERROR 100, "Error : GetFinalPathNameByHandle"​         IF R%=0 THEN ERROR 100, "Error : GetFinalPathNameByHandle"​
         = $$(path%+4) : REM excludes the leading //?/      ​         = $$(path%+4) : REM excludes the leading //?/      ​
 +</​code>​
using_20openin_20_28etc._29_20with_20wildcards.txt ยท Last modified: 2018/04/17 19:19 by tbest3112