Android Question Would appreciate help to know why global variables ae not global

aedwall

Active Member
Licensed User
Longtime User
Attached is a test project in which the global variables I define in "Class_Globals" or "Process_Globals" are not being recognized as global variables. If I do not set the same definitions in both "B4XMainPage.bas" and "Module1.bas", then I cannot compile the project because it tells me various variables have not yet been defined. In my world, I thought you could define your global variables in one place, then everything in the project knows what the global variables are. But not here. It makes no sense to me. If anyone can help, I would appreciate your comments. The final output desired is the display (among other things) of the position of Saturn as ~162.1072, but the "Display_output_data_2a" routine is not treating cs1 as a global and therefore does not return its value to the calling routine in "B4XMainPage.bas".

The project requires the "SE_v201" library files, which are attached.

Thank you for your help.
 

Attachments

  • Test_project.zip
    28.1 KB · Views: 85
  • SE_v201_xml.zip
    29.2 KB · Views: 86
  • SE_v201_jar.zip
    464.3 KB · Views: 78

Cableguy

Expert
Licensed User
Longtime User
I just took a look at your code... I think you are confusing "Main" with "B4XMainPage"
Main is an activity module, and in B4XPages, the only activity
B4XMainPage is a Special Class Module that solves a few problems related to multi activity projects
So, B4XMainPage does NOT have a "Process Globals" sub, on the Activity "Main" does
so you should start by firstly understand what that means!
Also, using 10+ years old libs, when more recent and versatile options exist, like in your case the "Dialogs" and "ClipBoard" libs, is something I recomend you to avoid.
I for one, will not add such libs to my additional libs folder
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
This will also make for interesting reading:

so you can understand the major differences
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
and to finish, I CAN acces Module1 's variables! This screenshot is from B4XMainPage

1746989102228.png
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
I just took a look at your code... I think you are confusing "Main" with "B4XMainPage"
Main is an activity module, and in B4XPages, the only activity
B4XMainPage is a Special Class Module that solves a few problems related to multi activity projects
So, B4XMainPage does NOT have a "Process Globals" sub, on the Activity "Main" does
so you should start by firstly understand what that means!
Also, using 10+ years old libs, when more recent and versatile options exist, like in your case the "Dialogs" and "ClipBoard" libs, is something I recomend you to avoid.
I for one, will not add such libs to my additional libs folder
Makes no difference if I move the globals to "Main". "Sub Process_Globals". Then it doesn't compile.

Error parsing program.
Error description: Undeclared variable 'vrs' is used before it was assigned any value.
Error occurred on line: 75 (B4XMainPage)
t = vrs & " - " & month_names(9) & " " & NumberFormat(22, 2, 0) & " " & "1949" & " at " & "16" & ":" & NumberFormat(43, 2, 1) & " TZ =" & NumberFormat2(0, 1, 1, 1, False) & CRLF

Nor does the attached work properly either.

I appreciate the fact that I do not fully understand all the terminology. I appreciate your suggestions, but I'm not sure I understand exactly what to do as the fix. Yes, I know that old libraries may be an issue at times. But it is not my current issue. And the old stuff does work. What doesn't work are the global variables - b4X just doesn't recognize them as global variables. And until I get that fixed, then I have nothing.
 

Attachments

  • Project.zip
    10 KB · Views: 87
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Test2 compiles just fine!!!

1746995643947.png
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
and to finish, I CAN acces Module1 's variables! This screenshot is from B4XMainPage

View attachment 163994
But do they have any value? When I look at them, yes the variables are there, but their values are blank. Why? I set them, but in another module, they lose their original values and I see either blanks for strings or "0.0" for array values.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
wow!!!!! of course they are empty! You declare p_names in Main, and then AGAIN in sub_routines module... by doing that, you null them!
give me a few minutes!
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
wow!!!!! of course they are empty! You declare p_names in Main, and then AGAIN in sub_routines module... by doing that, you null them!
give me a few minutes!
But if I don't declare them in both places, then the project does not compile. Try it on your end. Comment one out and see.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
wow!!!!! of course they are empty! You declare p_names in Main, and then AGAIN in sub_routines module... by doing that, you null them!
give me a few minutes!
When I comment out the define in sub_routines.bas ( 'Public p_names(9) As String ), then I get this:

Error parsing program.
Error description: Undeclared variable 'p_names' is used before it was assigned any value.
Error occurred on line: 14 (sub_routines)
t = p_names(6)
 
Upvote 0
Top