Static Variable (VB) 
Author Message
 Static Variable (VB)

Quote:


>Subject: Static Variable (VB)
>Date: Sun, 23 Jun 1996 01:22:31 -0700
>O.k my turn to plead for help ....
> A .BAS module contains something like .....
>  Type Person
>        Name as String
> etc etc etc snipped ..
>End type
>Global People() as Person    - obviously refers to an array -
>  etc etc etc
>.... A form containing .....
>Dim Bytes to read As Integer
>'... then does some  CMDialog stuff to get filename and Open it ...
> Open fileToOpen for Binary as #1
> X = 0
>  Do
>      Get #1, ,Bytes to read
> IF EOF(1) then exit Do
> Pepole(X).Name  = Input$(bytestoread, #1)
>     As far as I can see there is not a great deal wrong with this
>concept, we have defined an array, defined the source / target
>for the data that will be read in (BytesToRead)
> tells us how many bytes to expect etc etc etc ...
> NOW even if I place the   Dim   and Bytestoread etc etc in the .BAS
>module file, I am unable to use the function from other then the form
>upon which the data appears.
> Adding   STATIC .... etc  does not appear to solve the problem.
> I simply want to open a binary file, read the data (in Byte chunks)
>into each relevant part of the array, and then be able to call up the
>array elements from other forms within the project.
> So why can I not do this ?
> (  I tried the    frmForm3!  construct in front of the array statements
>but this was also to no avail.
> If you have a snip of a binary file reader / writer  or a solution then
>I would certainly like to hear from you.
> (Probably a "Glen" error )    :)  :(
> Thank you
>            Glenville.


Glen,
            You've got everything right, except you need to REDIM the global
array prior to using it. Somewhere at the beginning of your program try this...

ReDim People(1) 'or however many records you anticipate on using

of course, if you're using VB (looks like it), you can redimension your array
on the fly with..

ReDim Preserve People(3) 'keeps record 1 if something in it

if you want to blank out all records

ReDim People(3)

For your file I/O, would recommend making the record fixed length and opening
using RANDOM LEN=LEN(People(1)) then reading as records.

Hope this helps..

-DT-



Wed, 09 Dec 1998 03:00:00 GMT  
 Static Variable (VB)


Quote:

>O.k my turn to plead for help ....

> A .BAS module contains something like .....
>  Type Person
>        Name as String

> etc etc etc snipped ..

>End type
>Global People() as Person    - obviously refers to an array -
>  etc etc etc

>.... A form containing .....

>Dim Bytes to read As Integer
>'... then does some  CMDialog stuff to get filename and Open it ...

> Open fileToOpen for Binary as #1
> X = 0
>  Do
>      Get #1, ,Bytes to read
> IF EOF(1) then exit Do
> Pepole(X).Name  = Input$(bytestoread, #1)

>     As far as I can see there is not a great deal wrong with this
>concept, we have defined an array, defined the source / target
>for the data that will be read in (BytesToRead)
> tells us how many bytes to expect etc etc etc ...

> NOW even if I place the   Dim   and Bytestoread etc etc in the .BAS
>module file, I am unable to use the function from other then the form
>upon which the data appears.

> Adding   STATIC .... etc  does not appear to solve the problem.

> I simply want to open a binary file, read the data (in Byte chunks)
>into each relevant part of the array, and then be able to call up the
>array elements from other forms within the project.

> So why can I not do this ?

> (  I tried the    frmForm3!  construct in front of the array statemen
>ts
>but this was also to no avail.

> If you have a snip of a binary file reader / writer  or a solution th
>en
>I would certainly like to hear from you.

> (Probably a "Glen" error )    :)  :(

> Thank you
>            Glenville.



I am not sure exactly what your problem is, but it sounds

like you need to also include the command...

COMMON SHARED {variable1},{variable2},...{variableN}

...in the main module, or the command...

SHARED {variable1},{variable2},...{variableN}

...within the sub-modules.  Decaring a TYPE doesn't
always imply that it can be used in global fashion.

Check out the "HELP" under these commands,... I know

VB's help can be vague, but I think it might be enough

to get you started.

Beau Schwabe



Wed, 09 Dec 1998 03:00:00 GMT  
 Static Variable (VB)

O.k my turn to plead for help ....

 A .BAS module contains something like .....
  Type Person
        Name as String

 etc etc etc snipped ..

End type
Global People() as Person    - obviously refers to an array -
  etc etc etc

.... A form containing .....

Dim Bytes to read As Integer
'... then does some  CMDialog stuff to get filename and Open it ...

 Open fileToOpen for Binary as #1
 X = 0
  Do
      Get #1, ,Bytes to read
 IF EOF(1) then exit Do
 Pepole(X).Name  = Input$(bytestoread, #1)

     As far as I can see there is not a great deal wrong with this
concept, we have defined an array, defined the source / target
for the data that will be read in (BytesToRead)
 tells us how many bytes to expect etc etc etc ...

 NOW even if I place the   Dim   and Bytestoread etc etc in the .BAS
module file, I am unable to use the function from other then the form
upon which the data appears.

 Adding   STATIC .... etc  does not appear to solve the problem.

 I simply want to open a binary file, read the data (in Byte chunks)
into each relevant part of the array, and then be able to call up the
array elements from other forms within the project.

 So why can I not do this ?

 (  I tried the    frmForm3!  construct in front of the array statements
but this was also to no avail.

 If you have a snip of a binary file reader / writer  or a solution then
I would certainly like to hear from you.

 (Probably a "Glen" error )    :)  :(

 Thank you
            Glenville.




Thu, 10 Dec 1998 03:00:00 GMT  
 Static Variable (VB)



Quote:
>O.k my turn to plead for help ....

> A .BAS module contains something like .....
>  Type Person
>        Name as String

> etc etc etc snipped ..

>End type
>Global People() as Person    - obviously refers to an array -
>  etc etc etc

>...... A form containing .....

>Dim Bytes to read As Integer
>'... then does some  CMDialog stuff to get filename and Open it ...

> Open fileToOpen for Binary as #1
> X = 0
>  Do
>      Get #1, ,Bytes to read
> IF EOF(1) then exit Do
> Pepole(X).Name  = Input$(bytestoread, #1)

>     As far as I can see there is not a great deal wrong with this
>concept, we have defined an array, defined the source / target
>for the data that will be read in (BytesToRead)
> tells us how many bytes to expect etc etc etc ...

> NOW even if I place the   Dim   and Bytestoread etc etc in the .BAS
>module file, I am unable to use the function from other then the form
>upon which the data appears.

> Adding   STATIC .... etc  does not appear to solve the problem.

> I simply want to open a binary file, read the data (in Byte chunks)
>into each relevant part of the array, and then be able to call up the
>array elements from other forms within the project.

> So why can I not do this ?

> (  I tried the    frmForm3!  construct in front of the array statements
>but this was also to no avail.

Looks like you need to add the $INCLUDE and/or $FORM  metacommands to
module-level code in each program module that will call for the array
elements.


DynaCad Design Services (503)642-4040



Fri, 11 Dec 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Static variable not static enough ???

2. How do I declare a static global variable ?

3. Static Class and Variable

4. Declaring variables as Static vs Private/Public -- XML

5. Static variables are not supported...

6. Static variables in VBS?

7. Static variables...when to use?

8. Too many local, non-static variables

9. "Permanently" static variables

10. static variables

11. Would like to get value from local static variable

 

 
Powered by phpBB® Forum Software