Discussion:
Use of .bas file
(too old to reply)
Dan Shelby
2003-10-13 16:55:09 UTC
Permalink
I am writing a system which includes several diverse utilities and which
includes several forms. Since it would be nice to use some of the more
common variables throughout the system, it would likewise be nice to only
have to dim these variables once. From what I read, the way to go about
doing this is to insert the common variables into a named public type object
and all of this within a .bas file. In my system I chose to set this up as:
public type menudata.
this is followed by listing each common variable followed by a
characteristic (string, single, etc). Then all of this is followed by an
end type line.
Finally, it was my understanding that this would allow these variable names
to be used throughout the system. When I tried to run it, each usage of one
of these variables caused a 'variable not existent' or some such error.
Then I went to the form load and inserted the statement dim xyz as menudata
and then added xyz. in front of the variables thinking that this would make
the variables 'known' to all of the subroutines called from withing that
form. This, likewise, resulted in the "variable not existent" error. To
make things work I had to include the statement "dim xyz as menudata" in
each subroutine. The system works fine this way but it just doesn't seem to
be what I had thought setting up the .bas file was supposed to do for me.
What am I missing or doing wrong?
the Wiz
2003-10-13 18:13:16 UTC
Permalink
Post by Dan Shelby
I am writing a system which includes several diverse utilities and which
includes several forms. Since it would be nice to use some of the more
common variables throughout the system, it would likewise be nice to only
have to dim these variables once. From what I read, the way to go about
doing this is to insert the common variables into a named public type object
public type menudata.
this is followed by listing each common variable followed by a
characteristic (string, single, etc). Then all of this is followed by an
end type line.
Finally, it was my understanding that this would allow these variable names
to be used throughout the system. When I tried to run it, each usage of one
of these variables caused a 'variable not existent' or some such error.
Then I went to the form load and inserted the statement dim xyz as menudata
and then added xyz. in front of the variables thinking that this would make
the variables 'known' to all of the subroutines called from withing that
form. This, likewise, resulted in the "variable not existent" error. To
make things work I had to include the statement "dim xyz as menudata" in
each subroutine. The system works fine this way but it just doesn't seem to
be what I had thought setting up the .bas file was supposed to do for me.
What am I missing or doing wrong?
Dim XYZ as Integer
available where defined

Global XYZ as integer
available in entire project

There are good reasons for limiting the scope of variables. Be certain that you
need a Global variable before defining it.

More about me: http://www.jecarter.com/
VB3/VB6/NSBasic Palm/C/PowerBasic source code: http://www.jecarter.com/programs.html
Drivers for Pablo graphics tablet and JamCam cameras: http://home.earthlink.net/~mwbt/
johnecarter ***@at mindspring dot.dot com. Fix the obvious to reply by email.
Dan Shelby
2003-10-14 03:16:28 UTC
Permalink
There must be a misunderstanding or something on my part. First of all, the
.bas file doesn't include the dim or global prefix; when I try to include it
I get the error "Statement invalid inside type block". e.g., the first three
and last line of my .bas file is:

Public Type Menudata

work1 as single

work2 as single

........

end type

Attempting to place either dim or global in front of work1 causes the
abovementioned error.

I then attempted to eliminate the .bas file and, under GENERAL of the menu
program, I inserted the following:

option explicit

global work1 as single

As soon as I hit the enter key, the error: "constants, fixed-length strings,
arrays, user-defined types and declare statements

not allowed as public members of object module." This same error resulted
when I tried to enter global work1 as single inside a private sub.

So, I am back to where I was at the beginning.

Appreciate your reply. Thanks
Post by the Wiz
Post by Dan Shelby
I am writing a system which includes several diverse utilities and which
includes several forms. Since it would be nice to use some of the more
common variables throughout the system, it would likewise be nice to only
have to dim these variables once. From what I read, the way to go about
doing this is to insert the common variables into a named public type object
public type menudata.
this is followed by listing each common variable followed by a
characteristic (string, single, etc). Then all of this is followed by an
end type line.
Finally, it was my understanding that this would allow these variable names
to be used throughout the system. When I tried to run it, each usage of one
of these variables caused a 'variable not existent' or some such error.
Then I went to the form load and inserted the statement dim xyz as menudata
and then added xyz. in front of the variables thinking that this would make
the variables 'known' to all of the subroutines called from withing that
form. This, likewise, resulted in the "variable not existent" error. To
make things work I had to include the statement "dim xyz as menudata" in
each subroutine. The system works fine this way but it just doesn't seem to
be what I had thought setting up the .bas file was supposed to do for me.
What am I missing or doing wrong?
Dim XYZ as Integer
available where defined
Global XYZ as integer
available in entire project
There are good reasons for limiting the scope of variables. Be certain that you
need a Global variable before defining it.
More about me: http://www.jecarter.com/
http://www.jecarter.com/programs.html
http://home.earthlink.net/~mwbt/
Dr Hangman
2003-10-14 05:50:57 UTC
Permalink
Public Type Menudata
work1 as single
work2 as single
...
End Type

The above is a user-defined type....

I have used cards with different variables to each card...

Type CardRecord
Name As String
Group As String
Type As String
Level As Integer
Icon As String
ATK As Integer
DEF As Integer
Desc As String
Fusion As Boolean
End Type

Global LoadedCard As CardRecord

now during my subs I can load and store variables using this type...

Public Sub LoadCard(CardName As String, CardType As String, IsFusion As
Boolean)
LoadedCard.Name = CardName
LoadedCard.Type = CardType
LoadedCard.Fusion = IsFusion
End Sub

This is what my type is...

your Module (.bas) is like this...

'<====START TEST.BAS====>

'User-defined type here...
Public Type Menudata
work1 as single
work2 as single
...
End Type

'Declared Variables here...
Global XYZ As Menudata

'Sub routines here if needed...
'none yet

'<====END TEST.BAS====>

try simply adding "Global XYZ As Menudata" to the bottom of the module and
removing it from all the subs..

let me know if it works or not and what error you might be getting...

Dr Hangman
Post by Dan Shelby
There must be a misunderstanding or something on my part. First of all, the
.bas file doesn't include the dim or global prefix; when I try to include it
I get the error "Statement invalid inside type block". e.g., the first three
Public Type Menudata
work1 as single
work2 as single
........
end type
Attempting to place either dim or global in front of work1 causes the
abovementioned error.
I then attempted to eliminate the .bas file and, under GENERAL of the menu
option explicit
global work1 as single
As soon as I hit the enter key, the error: "constants, fixed-length strings,
arrays, user-defined types and declare statements
not allowed as public members of object module." This same error resulted
when I tried to enter global work1 as single inside a private sub.
So, I am back to where I was at the beginning.
Appreciate your reply. Thanks
Post by the Wiz
Post by Dan Shelby
I am writing a system which includes several diverse utilities and which
includes several forms. Since it would be nice to use some of the more
common variables throughout the system, it would likewise be nice to only
have to dim these variables once. From what I read, the way to go about
doing this is to insert the common variables into a named public type
object
Post by the Wiz
Post by Dan Shelby
and all of this within a .bas file. In my system I chose to set this
up
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
public type menudata.
this is followed by listing each common variable followed by a
characteristic (string, single, etc). Then all of this is followed by an
end type line.
Finally, it was my understanding that this would allow these variable
names
Post by the Wiz
Post by Dan Shelby
to be used throughout the system. When I tried to run it, each usage
of
Post by Dan Shelby
one
Post by the Wiz
Post by Dan Shelby
of these variables caused a 'variable not existent' or some such error.
Then I went to the form load and inserted the statement dim xyz as
menudata
Post by the Wiz
Post by Dan Shelby
and then added xyz. in front of the variables thinking that this would
make
Post by the Wiz
Post by Dan Shelby
the variables 'known' to all of the subroutines called from withing that
form. This, likewise, resulted in the "variable not existent" error.
To
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
make things work I had to include the statement "dim xyz as menudata" in
each subroutine. The system works fine this way but it just doesn't
seem
Post by Dan Shelby
to
Post by the Wiz
Post by Dan Shelby
be what I had thought setting up the .bas file was supposed to do for me.
What am I missing or doing wrong?
Dim XYZ as Integer
available where defined
Global XYZ as integer
available in entire project
There are good reasons for limiting the scope of variables. Be certain
that you
Post by the Wiz
need a Global variable before defining it.
More about me: http://www.jecarter.com/
http://www.jecarter.com/programs.html
http://home.earthlink.net/~mwbt/
email.
Dan Shelby
2003-10-14 19:40:09 UTC
Permalink
Thanks a lot, Doc. It worked fine. Appreciate the help!
Post by Dan Shelby
Public Type Menudata
work1 as single
work2 as single
...
End Type
The above is a user-defined type....
I have used cards with different variables to each card...
Type CardRecord
Name As String
Group As String
Type As String
Level As Integer
Icon As String
ATK As Integer
DEF As Integer
Desc As String
Fusion As Boolean
End Type
Global LoadedCard As CardRecord
now during my subs I can load and store variables using this type...
Public Sub LoadCard(CardName As String, CardType As String, IsFusion As
Boolean)
LoadedCard.Name = CardName
LoadedCard.Type = CardType
LoadedCard.Fusion = IsFusion
End Sub
This is what my type is...
your Module (.bas) is like this...
'<====START TEST.BAS====>
'User-defined type here...
Public Type Menudata
work1 as single
work2 as single
...
End Type
'Declared Variables here...
Global XYZ As Menudata
'Sub routines here if needed...
'none yet
'<====END TEST.BAS====>
try simply adding "Global XYZ As Menudata" to the bottom of the module and
removing it from all the subs..
let me know if it works or not and what error you might be getting...
Dr Hangman
Post by Dan Shelby
There must be a misunderstanding or something on my part. First of all,
the
Post by Dan Shelby
.bas file doesn't include the dim or global prefix; when I try to
include
Post by Dan Shelby
it
Post by Dan Shelby
I get the error "Statement invalid inside type block". e.g., the first
three
Post by Dan Shelby
Public Type Menudata
work1 as single
work2 as single
........
end type
Attempting to place either dim or global in front of work1 causes the
abovementioned error.
I then attempted to eliminate the .bas file and, under GENERAL of the menu
option explicit
global work1 as single
As soon as I hit the enter key, the error: "constants, fixed-length
strings,
Post by Dan Shelby
arrays, user-defined types and declare statements
not allowed as public members of object module." This same error resulted
when I tried to enter global work1 as single inside a private sub.
So, I am back to where I was at the beginning.
Appreciate your reply. Thanks
Post by the Wiz
Post by Dan Shelby
I am writing a system which includes several diverse utilities and
which
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
includes several forms. Since it would be nice to use some of the more
common variables throughout the system, it would likewise be nice to
only
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
have to dim these variables once. From what I read, the way to go
about
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
doing this is to insert the common variables into a named public type
object
Post by the Wiz
Post by Dan Shelby
and all of this within a .bas file. In my system I chose to set this
up
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
public type menudata.
this is followed by listing each common variable followed by a
characteristic (string, single, etc). Then all of this is followed
by
Post by Dan Shelby
an
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
end type line.
Finally, it was my understanding that this would allow these variable
names
Post by the Wiz
Post by Dan Shelby
to be used throughout the system. When I tried to run it, each usage
of
Post by Dan Shelby
one
Post by the Wiz
Post by Dan Shelby
of these variables caused a 'variable not existent' or some such error.
Then I went to the form load and inserted the statement dim xyz as
menudata
Post by the Wiz
Post by Dan Shelby
and then added xyz. in front of the variables thinking that this would
make
Post by the Wiz
Post by Dan Shelby
the variables 'known' to all of the subroutines called from withing
that
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
form. This, likewise, resulted in the "variable not existent" error.
To
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
make things work I had to include the statement "dim xyz as menudata"
in
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
each subroutine. The system works fine this way but it just doesn't
seem
Post by Dan Shelby
to
Post by the Wiz
Post by Dan Shelby
be what I had thought setting up the .bas file was supposed to do for
me.
Post by Dan Shelby
Post by the Wiz
Post by Dan Shelby
What am I missing or doing wrong?
Dim XYZ as Integer
available where defined
Global XYZ as integer
available in entire project
There are good reasons for limiting the scope of variables. Be certain
that you
Post by the Wiz
need a Global variable before defining it.
More about me: http://www.jecarter.com/
http://www.jecarter.com/programs.html
http://home.earthlink.net/~mwbt/
email.
Loading...