Page 1 of 1
declaring a variable 2x should be an error with EnableExplicit
Posted: Tue Jun 17, 2025 8:12 pm
by normeus
I went back to a 10 year old program ( which has run 24/7 for 10 years by the way ). I am using PB 612LTSx64 with a windows 10 pro:
I needed to add a couple of variables and as it turns out they had been declared before.
This is an error if you declare string last. It should also be an error if the string is declared first
Code: Select all
EnableExplicit
NewMap Mbadrecords.s()
Global x.s
NewMap Mbadrecords()
Global x
x="hello"
Debug x
Norm
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Tue Jun 17, 2025 8:46 pm
by infratec
I agree.
And
Code: Select all
EnableExplicit
NewMap Mbadrecords.s()
Global x.s
NewMap Mbadrecords()
Global x.i
x="hello"
Debug x
Rises an error.
But without an explicit type it is .i , so it should rise an error.
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Tue Jun 17, 2025 8:47 pm
by Quin
Good catch!
I fully agree, +1
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Wed Jun 18, 2025 10:04 pm
by Piero
What about x$?
Code: Select all
EnableExplicit
; Global x.i ; Error
; Global x ; Error
Global x.s="hello.s"
; Global x.i ; Error
Global x
Global x$="hello$"
Debug x
Debug x.s
Debug x$
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Thu Jun 19, 2025 7:39 am
by Lord
Aren't x.s and x$ two different variables?
So no error.
If so, it should stay that way.
If a varable is declared by same type a second time, it is no error.
It should yield only a warning.
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Sun Jun 22, 2025 5:07 pm
by Quin
x.s and x$ are two different varialbes, so that should be allowed.
However, declaring a variable without a type and then redeclaring it with one doesn't give you an error, when it should.
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Mon Jun 23, 2025 11:28 am
by Piero
Well, x.s and x$
MAY be considered as "two ways to declare x as string"
x$ is kinda like: "you always must be explicit and use $"
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Mon Jun 23, 2025 7:18 pm
by normeus
Back to my original dilema, let me propose this:
Code: Select all
Even if "EnableExplicit" when you declare an integer make sure you add ".i" to define it
This was me going back to a 10 year old program and typing a random variable which turned out not to be random. ( humans are not so random)
Watch out for Longs and Integers:
Code: Select all
EnableExplicit
Global x.l=92233720368547758070
Global x ; this should be a warning , have fun debugging pointer x now that it is a long
Debug x
Norm
Re: declaring a variable 2x should be an error with EnableExplicit
Posted: Tue Jun 24, 2025 2:27 am
by AZJIO
normeus wrote: Mon Jun 23, 2025 7:18 pm
Watch out for Longs and Integers:
In this case, developers need to set the validation level so that the test compilation is instant, and the final build of the application generates more warnings.