View previous topic :: View next topic |
Author |
Message |
DJ7DA
Joined: 03 May 2006 Posts: 83 Location: Bavaria
|
Posted: Tue May 12, 2015 11:19 am Post subject: DIM roblem |
|
|
Hello dear Reader, in a very small program the line
DIM Key# as Byte, Keynot# as Byte
returns an error message stating "AS" is missing, whereas the line
DIM Key as Byte, Keynot as Byte
compiles without Problems.
In "Language fundamenrtals" I couldn't find anything relating to this problem.
Is there anything I overlooked?
Thank you
Ernst
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue May 12, 2015 1:06 pm Post subject: |
|
|
you should not use # as part of the variable.
But there will be some changes in the next update. One thing is to be able to use a specific type identifier : dim key# this would create a variable of double type. dim key# as byte would be wrong.
The other thing is that you can use a list like : dim a,b,c,d as byte. At the moment however, you need to specify each variable and type : dim a as byte, b as byte,.....
Early basics use &,#,% and ! to identify the data type. Later on, Hungarian notation became practice. It is also better : when you need to change byte to word, you only need to change the code at 1 place. When you use a specific identifier like % you need a search & replace. So my advice ; use Hungarian notation where you prefix each variable with its data type :
dim bKey as byte, dblKey as double, etc. _________________ Mark |
|
Back to top |
|
|
DJ7DA
Joined: 03 May 2006 Posts: 83 Location: Bavaria
|
Posted: Tue May 12, 2015 1:30 pm Post subject: DIM problem |
|
|
Thank you very much Mark, for your prompt and detailed answer.
I was suspecting something like that, however, since earlier BASCOM versions "digested" the # I was a little puzzled.
Thanks again
Ernst |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Wed May 13, 2015 11:45 pm Post subject: |
|
|
Quote: | Later on, Hungarian notation became practice. It is also better : when you need to change byte to word, you only need to change the code at 1 place. When you use a specific identifier like % you need a search & replace. |
When you use Hungarian notation, you also need to do a search and replace to change a variable type, eg
Dim bMyVariable as byte
then when you change the type:
Dim iMyVariable as integer 'then you must change every occurrence, but a search and replace makes this trivial.
Leaving the name as bMyVariable and just doing
Dim bMyVariable as integer
will lead to all sorts of confusion later.
But aside from that, I find Hungarian notation to be the best practice. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri May 15, 2015 9:28 am Post subject: |
|
|
good someone is not sleeping
yes you are right. One always need a S&R.
And just renaming the data type defeats the purpose. So that should never be done.
When you keep the SHIFT key pressed in the IDE you can get info about the variable in a tool tip. _________________ Mark |
|
Back to top |
|
|
|