BBC BASIC for Windows
« *CHDIR + OPENIN with wildcard = wrong folder »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:54pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: *CHDIR + OPENIN with wildcard = wrong folder  (Read 537 times)
5against4
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx *CHDIR + OPENIN with wildcard = wrong folder
« Thread started on: Sep 21st, 2015, 2:41pm »

When i change directory using *CHDIR, and then use OPENIN with a wildcard so that the Open File dialogue box is displayed, the folder shown in the dialogue box is not the one i've just changed to but the original one (i.e. the one in which the program itself is stored).

Am i missing something or is this just the way BBC Basic wants to behave? i need the Open File dialogue box to show me the contents of the folder i've changed to, not the default one.
User IP Logged

sveinioslo
Developer

member is offline

Avatar




PM


Posts: 64
xx Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #1 on: Sep 21st, 2015, 5:37pm »

Manual info, at pages:
'Setting the File Open dialogue's initial directory'
and
'Using dialogue boxes'


Replace *CHDIR with this:
Code:
      DIM fs{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \
      \      lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \
      \      lpstrFile%, nMaxFile%, lpstrFileTitle%, \
      \      nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \
      \      flags%, nFileOffset{l&,h&}, nFileExtension{l&,h&}, \
      \      lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%}
      DIM fp% 255
      InitialDir$ = "C:\___SOMEWHERE___"+CHR$0 : REM Change here ...................
      FileFilter$ = "*:*"+CHR$0+CHR$0
      fs.lStructSize% = DIM(fs{})
      fs.hwndOwner% = @hwnd%
      fs.lpstrFilter% = !^FileFilter$
      fs.lpstrFile% = fp%
      fs.nMaxFile% = 256
      fs.lpstrInitialDir% = !^InitialDir$
      fs.flags% = 6
 


Replace OPENIN"*" with this:
Code:
      SYS "GetOpenFileName", fs{} TO result%
      IF result% THEN file$=$$fp% : PRINT file$
 


Hope this helps.
Svein

« Last Edit: Sep 22nd, 2015, 06:06am by sveinioslo » User IP Logged

5against4
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #2 on: Sep 21st, 2015, 8:38pm »

Thanks Svein - it's a shame (and a bit ridiculous) it needs to be as complex as that! But i'm grateful for the help smiley
User IP Logged

hellomike
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #3 on: Sep 21st, 2015, 9:45pm »

Hi,

Probably I don't understand what you want but why use *CHDIR at all?

Whats wrong with this?
Code:
      SearchDir$="C:\Windows\System32\"

      F%=OPENIN(SearchDir$+"*.xml")
      IF F%=0 ERROR 100,"File not found."
      Line1$=GET$#F%
      CLOSE#F%

      PRINT "This program is stored in: "+@dir$
      PRINT "First line in the chosen XML was: '"+Line1$+"'"
      END
 


Cheers,

Mike
User IP Logged

5against4
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #4 on: Sep 22nd, 2015, 09:09am »

That's quite nice Mike, thanks!

However - is it possible to make the search directory relative rather than absolute? i have a subfolder called DATA and want it to look in there, but nothing seems to tell it to look in there unless i specify the full absolute location.

But otherwise your solution is perfect - thank you! laugh
« Last Edit: Sep 22nd, 2015, 09:26am by 5against4 » User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #5 on: Sep 22nd, 2015, 1:24pm »

Hi,

Does @dir$ do what you need? That is set to the directory from which the program was loaded, so if your DATA folder is in there you could refer to it as @dir$+"DATA\*.bbc"

Hope that helps,

D
User IP Logged

hellomike
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #6 on: Sep 22nd, 2015, 4:14pm »

As far as I know, the OPENIN() function either needs an absolute/full path or, if it doesn't have that, e.g. because you are using it like

F% = OPENIN("*.*")

,it will make the Open File dialogue box relative to the content of what's in the @dir$ variable, NOT to the current working folder.

But no worries. You can easily find out the absolute path for the current working folder at any given time and then append "\DATA\*.*" to it as follows:

Code:
      ......
      REM Get absolute path to working folder.
      DIM cd% 255
      SYS "GetCurrentDirectory", 256, cd%
      PRINT $$cd%

      REM Show Open File dialogue box relative to it...
      F% = OPENIN($$cd%+"\DATA\*.*")
      ...... 


This way you provide OPENIN() with an absolute path.

If you need that more often in the source, you better use the function as documented in the Help for the *CHDIR command.

Then the OPENIN() call would be:

Code:
      F% = OPENIN(FNcurrentdirectory+"\DATA\*.*")
 


Happy coding.

Mike
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls