Variable already declared

Just starting out? Need help? Post your questions and find answers here.
Sergey
User
User
Posts: 78
Joined: Wed Jan 12, 2022 2:41 pm

Variable already declared

Post by Sergey »

Code: Select all

EnableExplicit
Define abc.q
abc.q = 2
abc = 5
No error

Code: Select all

EnableExplicit
Define abc.q
abc.q = 2
abc.i = 5
[13:40:14] [COMPILER] Line 4: Variable already declared with another type: abc.

With type abc :shock:
Stop, abc - variable's name, not variable type


// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)
Little John
Addict
Addict
Posts: 4830
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Variable already declared

Post by Little John »

Sergey wrote: Tue Jan 13, 2026 10:39 am

Code: Select all

EnableExplicit
Define abc.q
abc.q = 2
abc.i = 5
[13:40:14] [COMPILER] Line 4: Variable already declared with another type: abc.
This is short for: “The following variable is already declared with another type: abc.”
Sergey wrote: Tue Jan 13, 2026 10:39 am With type abc :shock:
Stop, abc - variable's name, not variable type
The message does not write that abc is the variable's type.
Sergey
User
User
Posts: 78
Joined: Wed Jan 12, 2022 2:41 pm

Re: Variable already declared

Post by Sergey »

Оh, that's for sure
I read it as if it was a different type
Sorry, topic can be deleted
Fred
Administrator
Administrator
Posts: 18453
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Variable already declared

Post by Fred »

I will try to make the message clearer
Sergey
User
User
Posts: 78
Joined: Wed Jan 12, 2022 2:41 pm

Re: Variable already declared

Post by Sergey »

Maybe... Variable abc already declared with type quad
User avatar
TI-994A
Addict
Addict
Posts: 2791
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Variable already declared

Post by TI-994A »

Sergey wrote: Tue Jan 13, 2026 2:05 pm Maybe... Variable abc already declared with type quad
Technically, this should be sufficient:

Code: Select all

Line 4: Variable already declared: abc

More succinct, less confusion. IMHO. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Fred
Administrator
Administrator
Posts: 18453
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Variable already declared

Post by Fred »

Changed into:
Variable 'abc' already declared with another type.
Little John
Addict
Addict
Posts: 4830
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Variable already declared

Post by Little John »

Fred wrote: Wed Jan 14, 2026 9:54 am Changed into:
Variable 'abc' already declared with another type.
That is more clear. :thumbsup:
User avatar
charvista
Addict
Addict
Posts: 967
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Variable already declared

Post by charvista »

EnableExplicit
Define abc.q
abc.q = 2
abc = 5
When you use a variable without extension, it is the extension type that was used when you defined it that will be used; you defined it as .q so the abc (without .q) is the same as abc.q, and if you run it with Debug abc and Debug abc.q you will see that you have the same result: 5
EnableExplicit
Define abc.q
abc.q = 2
abc.i = 5
Here you have an error, because you have already defined abc as type .q so trying to define abc as type .i is a name mismatching: you cannot change the type of variable on the fly.

One thing to keep in mind: when a variable is defined without type, then the .i type will be the default.
Define abc
is the same as
Define abc.i
(in the case you have not already defined it as a .q, of course: it is the first definition that will given to a variable that counts)
- Windows 11 Home 64-bit
- PureBasic 6.30 (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 8K monitor with DPI @ 300%
User avatar
charvista
Addict
Addict
Posts: 967
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Variable already declared

Post by charvista »

Little John wrote: Wed Jan 14, 2026 11:28 am
Fred wrote: Wed Jan 14, 2026 9:54 am Changed into:
Variable 'abc' already declared with another type.
That is more clear. :thumbsup:
When speaking about the error message, yes, that is more clear, but "Variable 'abc' already declared as type .q' is more precise...
- Windows 11 Home 64-bit
- PureBasic 6.30 (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 8K monitor with DPI @ 300%
Sergey
User
User
Posts: 78
Joined: Wed Jan 12, 2022 2:41 pm

Re: Variable already declared

Post by Sergey »

charvista wrote: Wed Jan 14, 2026 8:53 pm When speaking about the error message, yes, that is more clear, but "Variable 'abc' already declared as type .q' is more precise...
I'm agree with you 100%
The user sees the specified type and can easily correct the error
Post Reply