BBC BASIC for Windows
« "Open" Window, selecting a file »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:49pm



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: "Open" Window, selecting a file  (Read 414 times)
Danny H
Guest
xx "Open" Window, selecting a file
« Thread started on: Nov 9th, 2009, 5:52pm »

Hello
Could someone let me know how I can
get the Open window to appear, then to select a .txt file
and for that filename to be stored as a string.
Many thanks for your help.
User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: "Open" Window, selecting a file
« Reply #1 on: Nov 10th, 2009, 09:17am »

Danny,

The code is in the manual. Look under "Accessing the Windows API - Using dialogue boxes - File Open and file save".

I know the code looks a bit overcomplicated but once you get your head around it it is a very powerful way of interacting with windows.

Michael

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: "Open" Window, selecting a file
« Reply #2 on: Nov 10th, 2009, 09:26am »

Quote:
The code is in the manual.

I'd recommend the code here instead:

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwine.html#opensave

The difference from the code in the 'local' manual is that the filename buffer is allocated differently, eliminating the risk of a memory leak if the code is executed multiple times.

Richard.
User IP Logged

Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx Re: "Open" Window, selecting a file
« Reply #3 on: Nov 10th, 2009, 09:40am »

Thanks very much, got it now.
Danny
User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: "Open" Window, selecting a file
« Reply #4 on: Nov 10th, 2009, 10:13am »

Quote:
eliminating the risk of a memory leak if the code is executed multiple times.


Code:
      DIM A% 259
      PRINT A%
      DIM A% 259
      PRINT A%
      DIM A% 260
      PRINT A%

      DIM fp{t&(260)}
      PRINT fp{}
      DIM fp{t&(260)}
      PRINT fp{}
      DIM fp{t&(261)}
      PRINT fp{}

 


I hadn't thought of that before. Only the last statement gives a 'Bad DIM Statement' Error' As does DIM fp{t&(20)}.

So does BB4W check the heap when DIMing a structure or an array but not a variable?

Michael
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: "Open" Window, selecting a file
« Reply #5 on: Nov 10th, 2009, 11:00am »

Quote:
So does BB4W check the heap when DIMing a structure or an array but not a variable?

I don't entirely understand the question, but maybe the following will help:

Code:
      DIM buf% size% 

This statement allocates a block of memory and assigns its address to the variable buf%. What's important is that buf% is a regular (integer) variable; nothing about the variable or its value records the fact that it points to a memory buffer, nor that its value was assigned in a DIM statement. Only you know that!

So if another similar DIM statement is executed, BBC BASIC can't possibly know to do something different from what it did the previous time. It doesn't even know there was a previous time! Hence each time the statement is executed another block of memory is allocated (potentially a memory leak).

This is fundamentally different from the 'conventional' use of DIM to declare an array or a structure, where the object created itself records the fact that it was created using DIM, how big it is etc. Now, if the statement is repeated, BBC BASIC has the information available to allow it to make different choices (such as re-use the original memory or issue an error message).

Richard.
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