BBC BASIC for Windows
Programming >> Graphics and Games >> Oz Stocks banner
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1246519071

Oz Stocks banner
Post by Michael Hutton on Jul 2nd, 2009, 07:17am

Using Richards Banner_array program I have modified it to show a banner at the top of the desktop which will disappear when the mouse is nearby.

http://tech.groups.yahoo.com/group/bb4w/files/%22Temp%20Folder%22/MDCH/banner_MDCH.bbc

Obviously, it's not perfect but people may like use it in their own code.

It uses a BBC Basic timer (ON TIME) to test the fullscreen mouse Y coordinate. This is a fudge factor and really should be calculated from the BannerHeight% variable but it will Hide and Show the window if need be.

Michael

PS At the moment to close it press the window in the taskbar and press Alt-f4.
Re: Oz Stocks banner
Post by admin on Jul 2nd, 2009, 08:15am

Minor bug report. The first time I ran it I got a 'No such variable' error. The second time it was OK. Probably a timing thing - perhaps you do some initialisation that needs to take place before the first timer interrupt but isn't guaranteed to?

Richard.
Re: Oz Stocks banner
Post by admin on Jul 2nd, 2009, 08:28am

...more seriously, if I download it and run it under the IDE it always fails with a 'No such variable' error and if I keep running it it eventually crashes BB4W and DrWatson! There is something seriously wrong!!

A quick look shows one problem immediately: you test variable MY% in PROCmousetest and you set that variable in PROCtimer. Since these are asynchronous interrupts, sometimes a PROCtimer will occur first (which is OK) and sometimes a PROCmousetest will occur first (which will cause an error).

I'm not too sure why the program then crashes so seriously that it kills both BB4W and Doctor Watson, but in the circumstances I would suggest you withdraw it until it is fixed. For expediency, I will delete the file from the group.

Richard.

Re: Oz Stocks banner
Post by Michael Hutton on Jul 2nd, 2009, 08:37am

I'm pretty sure it was the MX%, MY%, MB% problem. I have now fixed that. Thanks for deleting the other file.

Michael
Re: Oz Stocks banner
Post by Michael Hutton on Jul 2nd, 2009, 08:53am

on Jul 2nd, 2009, 08:28am, Richard Russell wrote:
...more seriously, if I download it and run it under the IDE it always fails with a 'No such variable' error and if I keep running it it eventually crashes BB4W and DrWatson! There is something seriously wrong!!

...

I'm not too sure why the program then crashes so seriously that it kills both BB4W and Doctor Watson, but in the circumstances I would suggest you withdraw it until it is fixed. For expediency, I will delete the file from the group.

Richard.


Although fixing the MX% variable issue, I have just thought that the bigger crash maybe what I have been experiencing all along. (I did report it in the Yahoo! group). I have found that running an unmodified banner program from the IDE it will crash more often that not when pressing the CLOSE or STOP button in the IDE. Hence, I was trying to release DirectDraw, and you added the clearing up of the other GDI objects. I have added freeing up of the other dll's installed but that seems to make no difference, but I wouldn't expect it to. It seemed 'a bit' better when adding a wait to the PROCcleanup routine although I know we have discussed this before. It has never crashed when not trying to close it though.

interestingly, I can't profile it because the banner program must hijack the TimerProc variable for it's own timer!!!! Oh well!

Michael
Re: Oz Stocks banner
Post by Michael Hutton on Jul 2nd, 2009, 09:06am

Just a thought but does the IDE "SendMessage" or "PostMessage" WM_CLOSE when the user presses the close button. could it be a 'lock' caused within a message loop?

I haven't tried to look at the Dr Watson but then again I crash BB4W so many times I tend to ignore it anyway. Please don't comment on this, I know it's bad. embarassed

Michael
Re: Oz Stocks banner
Post by admin on Jul 2nd, 2009, 09:09am

Quote:
I have found that running an unmodified banner program from the IDE it will crash more often that not when pressing the CLOSE or STOP button in the IDE.

Crashing (perhaps catastrophically) when pressing the Stop button in the IDE (or the equivalent menu selection) is to be expected; it bypasses any ON CLOSE processing. That's nothing to worry about.

Quote:
interestingly, I can't profile it because the banner program must hijack the TimerProc variable for it's own timer!!!!

I don't see how that follows. The profiler (mine, at least) uses a multimedia timer; you can have several of those, and there's no reason why the timer in the banner program should interfere with the timer used by the profiler.

Richard.
Re: Oz Stocks banner
Post by Michael Hutton on Jul 2nd, 2009, 10:30am

> Crashing (perhaps catastrophically) when pressing the Stop button in the IDE (or the equivalent menu selection) is to be expected; it bypasses any ON CLOSE processing.

Well, that stands up here. My program reliably exists when pressing the CLOSE button on the window, pressing Alt-F4, or causing an error within the program but crashes catastrophically when pressing the STOP button in the IDE. It must bypass the releasing of DirectDraw, or the multimedia timer, but I remember reading somewhere that multimedia timers are automatically exited when shutting down a window. So I would suspect DirectDraw. Still, I have never had it crash when just running. I'm going out soon so I'll leave it on and see if it is still going when I get back!

There are some 'sneaky tricks' going on in your assembly code so surely this could also be a cause of crashing the IDE when pressing STOP? But IMHO it's got to be the DirectDraw.

> That's nothing to worry about.
Just for the sake of a thought terminating cliche - "We'll just have to agree to disagree" wink But I think I see that it is a useful function to bypass the ON CLOSE if there is an error in the cleanup routine or the user has programmed an infinite loop in ASM or similar.

> I don't see how that follows. The profiler (mine, at least) uses a multimedia timer; you can have several of those, and there's no reason why the timer in the banner program should interfere with the timer used by the profiler.

Although I haven't looked closely both mine, and yours, seem to fail to profile this program. I was thinking that *maybe* the TimerProc variable, or a similarly named variable had been 'hijacked' as both use similar ones. I haven't investigated any further.

Unfortunately/fortunately I am running this on Vista and I haven't really got to grips with the 'Problems and Solutions center' yet and haven't found the dump file. I'm looking.

Michael


Re: Oz Stocks banner
Post by admin on Jul 2nd, 2009, 5:51pm

Quote:
does the IDE "SendMessage" or "PostMessage" WM_CLOSE when the user presses the close button

No. That's an 'internal' operation in Windows, and does not require 'user' code.

Quote:
There are some 'sneaky tricks' going on in your assembly code so surely this could also be a cause of crashing the IDE

Where? I've looked at the code and I can't see anything remotely "sneaky" going on; in fact much of the code is an almost exact copy of code within the BB4W run-time engine itself. If you can see anything which you believe might result in a crash, please let me know urgently because it's possible that the same problem could affect all BB4W programs!

Quote:
Just for the sake of a thought terminating cliche - "We'll just have to agree to disagree"

The BB4W documentation clearly indicates that the IDE Stop bypasses any ON CLOSE processing: "Note that any ON CLOSE routine in your program will not be executed. It is therefore better to use the normal methods of ending your program (e.g. clicking on the Close button) when possible and to use the Stop command only as a last resort". If Stop did the same thing as clicking on the Close button (or, equivalently, Alt-F4) there would be little point in having it at all!

As you've admitted having an ambition to replace the BB4W IDE with your own product, you'll have an opportunity then to put right the shortcomings that you perceive in the current BBC BASIC for Windows.

Quote:
I was thinking that *maybe* the TimerProc variable, or a similarly named variable had been 'hijacked' as both use similar ones.

The profiler shouldn't be 'sharing' any variables with the program being profiled; indeed in my version it isn't possible since the program being profiled is started using the RUN statement, which as a side effect CLEARs any variables (apart from 'static' variables).

Richard.
Re: Oz Stocks banner
Post by Michael Hutton on Jul 3rd, 2009, 05:52am

Quote:
Where? I've looked at the code and I can't see anything remotely "sneaky" going on; in fact much of the code is an almost exact copy of code within the BB4W run-time engine itself.

sneaky for me in that it goes right over my head!

Quote:
As you've admitted having an ambition to replace the BB4W IDE with your own product

Well, my idea was to get tabbed browsing going. It's not intended as a replacement more of a 'if you've got BB4W installed then you might like this....". My idea stemmed from my wish to be able to subclass the IDE but it seems this will introduce instability for the user, which is not something I would like.

Anyway, I've uploaded a new banner.
http://tech.groups.yahoo.com/group/bb4w/files/%22Temp%20Folder%22/MDCH/banner_oz_stocks_MDCH.bbc

The reason for doing this is that I 'discovered' an error which I can't explain:

I was lucky enough to find a link which, I think, contains the most recent Oz stock quote for a ticker as a short (56 bytes) csv style quote from the finance page. This precludes the need to parse a xml download and also drastically reduces the amount of downloaded data.

In the program above if you change

server$ = "au.finance.yahoo.com"

to

server$ = "http://au.rd.yahoo.com/finance/quotes/internal/summary/download/*http://au.finance.yahoo.com"

when in PROCAssemble it gives 'Muliple label' error, highlighing ".Timerproc".

I don't know why this should be but I find it perplexing. (I also don't actually know whether I need to use this link or the original one to get the most up to date data, but I'm looking into this.) It's bizarre (for me).

Just for interest the quote you get is for example,

"AAX.AX",4.040,"7/3/2009","1:20am",+0.030,3.870,4.050,3.850,310847

much shorter than the full http page.

You can then just parse this and put it into the banner.

Michael
Re: Oz Stocks banner
Post by admin on Jul 3rd, 2009, 08:58am

Quote:
sneaky for me in that it goes right over my head!

Certainly I would not expect you to understand the code (it accesses some BB4W internal variables which are completely undocumented) but don't you think it's rather a big leap from that to saying "surely this could also be a cause of crashing"? Is it your contention that any code which you don't understand is necessarily 'dangerous'?

Quote:
I don't know why this should be but I find it perplexing.

The explanation is very simple. Within your program is this function:

Code:
      DEF FNstripquotes(A$)
      IF LEFT$(A$,1)="""" AND MID$(A$,LENA$)="""" THEN =MID$(A$,2,LENA$-2) 

You will observe that if the conditional test fails the function never returns: it simply falls through to the code below it! Since the immediately following code is the definition of PROCbanner, if you pass a string to FNstripquotes which doesn't both start and end with a quotation mark (") you cause PROCbanner to be executed a second time. The way this happens to manifest itself is the 'Multiple label' error when PROCassemble is also called for a second time.

It's for this kind of reason that I sometimes separate procedures (and functions) with a line consisting of a semicolon (;), that way if execution ever accidentally 'falls through' from one procedure to the next you will get a 'Syntax error' when the interpreter encounters the semicolon.

If I replace the definition of FNstripquotes with the following, I don't get an error (but the banner doesn't display valid data):

Code:
      DEF FNstripquotes(A$)
      IF LEFT$(A$,1)="""" AND MID$(A$,LENA$)="""" THEN =MID$(A$,2,LENA$-2)
      = A$ 

I am surprised that you didn't manage to locate the error (I found it very quickly). I wonder whether describing it as "very odd" and saying "I cannot explain this" led to a mind-set that failed to consider a 'simple' explanation.

Richard.
Re: Oz Stocks banner
Post by Michael Hutton on Jul 3rd, 2009, 09:33am

Aaaaaaaaaaaaaaarrrrrrrrrrrrgggggggggghhhhhhhh! Ok, I'm off to eat humble pie!

Michael