Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Global Variables

Author
Message
Eckie Thump
20
Years of Service
User Offline
Joined: 15th Oct 2003
Location:
Posted: 28th Oct 2003 17:26
I have declared some variables global so I don't have to keep remembering colours used in certain functions:

Global LYellow,gold,burgundy,gyellow

All worked fine until I then decided to make some string variables global

I added Name$ to the global list and when I ran the example I got
"Quiz has caused an error in <unknown>
Quiz will now close."
error message.

I've tried using a seperate global line for the strings but that doesn't work either.

Are $ type variables not supported is there something I'm missing?
Cheers for any help.
skovron
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 28th Oct 2003 18:04
could you show piece of code.
maybe try declare like this

global Name as string
Name = "Something"
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 28th Oct 2003 18:18
if all of your code is in one module there is really no need for the "global" declaration you can simply put at the top of your code...

intMyVariable as integer
strName as string

etc etc

these decares will be "seen" by the entire code module including inside of subs and functions. I haven't had to use global yet. I suspect it's to make a variable's scope program-wide, so it can be seen by other code modules.

-RUST-
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Oct 2003 20:39 Edited at: 28th Oct 2003 20:39
Hmmm, a correction is needed ...

Variables declared outside of a function are not available to any function without the global command.



Now try it again after adding GLOBAL to the start of the first line.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 28th Oct 2003 20:56
I stand correct regarding functions. global not necessary regarding subs. And for good measure shouldn't

Print i

be

Print str$(i)

(sorry - my brain has built in Option Strict)
I know dbp won't throw the cast exception on the implicit conversion, just trying to keep good habits


Thanks Ian

-RUST-
Eckie Thump
20
Years of Service
User Offline
Joined: 15th Oct 2003
Location:
Posted: 28th Oct 2003 21:19
OK, thanks for the replies.
Have tried to declare as string but I still get errors.

This code returns the same error.

Anyway other way to do it?

Cheers,
Eckie
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 28th Oct 2003 21:34
that peice of code works fine for me in dbpro fully patched, are you using dbc maybe?
@CattleRustler, 'print' can print anything it doesn't have to be a string its only 'text' and 'center text' that require a string.


Go on, click on my signature image, you know you want to
Favourite smiley>>>
Eckie Thump
20
Years of Service
User Offline
Joined: 15th Oct 2003
Location:
Posted: 28th Oct 2003 21:57
Hmmm?
I'm using DBPro, shall look for a patch and try again.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 28th Oct 2003 23:42 Edited at: 28th Oct 2003 23:43
Red eye, yes thanks. I tend to put it in always, as my brain is molded to vb.net where I always use Option Strict which doesn't allow implicit type conversions, so every thing has to be explicitly converted - it's a great thing (much better for debugging later), and a by-product of doing away with the very idiotic "Variant" variable type from earlier versions of vb! Bring on the true OO!

-RUST-
Eckie Thump
20
Years of Service
User Offline
Joined: 15th Oct 2003
Location:
Posted: 29th Oct 2003 22:40
Ok all patched up and the variables problems have disappeared. Cheers all.
Not sure I like the new version, seems a bit slower.
The main problem I now have is with images.
An image (jpg) pasted to the screen which originally looked fine at 158x158 pixels now looks all slightly pixalated (as if I'd tried to enlarge it slightly) though I haven't and the image is still 158x158.

Any ideas what has changed?

Login to post a reply

Server time is: 2024-09-21 07:40:37
Your offset time is: 2024-09-21 07:40:37