declaring a variable 2x should be an error with EnableExplicit

Just starting out? Need help? Post your questions and find answers here.
normeus
Enthusiast
Enthusiast
Posts: 472
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

declaring a variable 2x should be an error with EnableExplicit

Post 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
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: declaring a variable 2x should be an error with EnableExplicit

Post 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.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: declaring a variable 2x should be an error with EnableExplicit

Post by Quin »

Good catch!
I fully agree, +1
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: declaring a variable 2x should be an error with EnableExplicit

Post 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$
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: declaring a variable 2x should be an error with EnableExplicit

Post 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.
Image
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: declaring a variable 2x should be an error with EnableExplicit

Post 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.
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: declaring a variable 2x should be an error with EnableExplicit

Post by Piero »

Well, x.s and x$ MAY be considered as "two ways to declare x as string"

Code: Select all

x$=1 ; error
x$ is kinda like: "you always must be explicit and use $"
normeus
Enthusiast
Enthusiast
Posts: 472
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: declaring a variable 2x should be an error with EnableExplicit

Post 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
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
AZJIO
Addict
Addict
Posts: 2183
Joined: Sun May 14, 2017 1:48 am

Re: declaring a variable 2x should be an error with EnableExplicit

Post 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.
Post Reply