Author |
Topic: "Open" Window, selecting a file (Read 414 times) |
|
Danny H
Guest
|
 |
"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.
|
|
Logged
|
|
|
|
Michael Hutton
Developer
member is offline


Gender: 
Posts: 248
|
 |
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
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
Danny72
New Member
member is offline


Posts: 20
|
 |
Re: "Open" Window, selecting a file
« Reply #3 on: Nov 10th, 2009, 09:40am » |
|
Thanks very much, got it now. Danny
|
|
Logged
|
|
|
|
Michael Hutton
Developer
member is offline


Gender: 
Posts: 248
|
 |
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
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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: 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.
|
|
Logged
|
|
|
|
|