how to avoid declaring types multiple times?

kanaida

Active Member
Licensed User
Longtime User
I created a module called 'cpu', it has a type called TIME_IN_STATE. It's just 2 integers.

I call cpu.GetStates wich returns TIME_IN_STATE()

from the main module I can't do this:
dim x as cpu.TIME_IN_STATE, I have to copy and paste the type declaration to the main activity to get it to work. Not sure if it's just me but I feel like i'm doing something wrong, maybe I don't know something, by having to declare the same thing twice, possibly more times if I add other activities that use it.

any ideas? since I can't use classes, this is the next best thing to keep this app maintainable and clean. I just want to make a code module that I can easily copy and paste between projects without having to re-declare a bunch of types. Right now I have about 10 subs in that one module, but I'm going to have hundreds after I build the full library.
 

klaus

Expert
Licensed User
Longtime User
I don't know what you have done and how.
Declaring a ProcessGlobal Type in a module and declaring a variable of that type in the main module WORKS !
As already pointed out by r2d4 when declaring the variable in the main module it's
B4X:
    Dim x As TIME_IN_STATE
The attached program proves it !

It would have been more efficient if you had posted your code as a zip file.

Best regards.
 

Attachments

  • ModuleType.zip
    5.8 KB · Views: 138
Upvote 0

kanaida

Active Member
Licensed User
Longtime User
Thanks. Must have been a color highlighting bug.
I had the same code but TIME_IN_STATE was in red, I re-typed the same thing and the colors were correct. Maybe it was because it was an array or something.

Dim States() As TIME_IN_STATE
 
Upvote 0
Top