Page 1 of 1

Constant visibility.

Posted: Thu Mar 21, 2024 3:26 am
by jphoarau
Good morning,

I have a question about a problem with the visibility of variables and in my case, of a constant.

I have two windows that I write to two separate files. In file1.sb there is:

Code: Select all

IncludeFile "file2.sb"

Enumeration FormWindow
  #Window_1
EndEnumeration

OpenWindow(#Window_1, 0, 0, ww, hh, "Window1", #PB_Window_ScreenCentered | #PB_Window_TitleBar)

etc...
And in file2.sb there is:

Code: Select all

Enumeration FormWindow
  #Window_2
EndEnumeration

OpenWindow(#Window_2, 0, 0, 300, 560, "Window2", #PB_Window_ScreenCentered)

if (condition)
	SetActiveWindow(#Window_1); This is where I got the error: "Constant not found #Window_1"
EndIf
The compiler gives me an error: Constant not found #Window_1, in file2. I don't understand why the constant #Window_1 is not visible in file2 even though I have done an Include of this file in file1. Can anyone enlighten me? Thanks in advance.

Re: Constant visibility.

Posted: Thu Mar 21, 2024 12:47 pm
by hoerbie
I think the include of file2 has to be below of the enumeration (declaration) of the constant for window 1

Re: Constant visibility.

Posted: Thu Mar 21, 2024 1:52 pm
by Paul
hoerbie is correct, your include file creates Window2 first then you try to activate Window1 before the constant or Window has been created.
Also your enumeration is giving both Windows the exact same value so after Window1 is created, Window2 will no longer be valid.

Re: Constant visibility.

Posted: Thu Mar 21, 2024 3:36 pm
by jphoarau
Thanks to you two. I will correct my code and review my logic.:)