Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

an array of values "word"

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Fri Sep 11, 2020 8:30 am    Post subject: an array of values "word" Reply with quote

hi!
-----

Help me read the 1 record "word" from the array.
I only need to read 1 record, but my program reads two records at the same time.


Code:

Dim W1 As Word
Dim temp As Byte

Do
   Restore Tab

  For Temp = 0 To 51
    Read W1
    Print W1 ; ", ";
  Next

Loop


Tab:
  Data 2248 , 2446 , 2641 , 2830 , 3011 , 3184 , 3345 , 3494 , 3629 , 3748 , 3852 , 3938 , 4005 ,
  Data 4054 , 4084 , 4094 , 4084 , 4055 , 4006 , 3939 , 3853 , 3750 , 3631 , 3496 , 3348 , 3186 , 3014 , 2833 , 2644 ,
  Data 2449 , 2251 , 2050 , 1850 , 1651 , 1456 , 1267 , 1085 , 913 , 751 , 602 , 467 , 347 , 244 , 158 , 89 ,
  Data 40 , 10 , 0 , 9 , 38 , 87 , 154 , 239 , 342 , 461 , 596 , 744 , 905 , 1077 , 1258 , 1447 ,
  Data 1641 , 1840 , 2040               '
 


The terminal gives me this data.
that is, the program reads two records at once in the array and puts both records in one variable.

38600, 6225, 31683, 45841, 45613, 28940, 58789, 3572, 59124, 29350, 46349, 46639, 32532, 7366, 39764, 2763, 31290, 63664, 38205, 23791, 23763, 40692, 10329, 10, 9737, 39511, 22255, 21965, 35816, 60981, 28327, 65328, 11918, 11935, 38152, 11752, 11769, 38152, 59040, 57525, 37261, 9096, 61457, 53260, 53243, 38152, 37902, 263, 11648, 61457, 53253, 53242,

(BASCOM-AVR version : 2.0.8.1 , Latest : 2.0.8.3 )


Last edited by Alexander-Dan on Sat Sep 12, 2020 5:03 pm; edited 1 time in total
Back to top
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 299
Location: Berlin

germany.gif
PostPosted: Fri Sep 11, 2020 10:30 am    Post subject: Reply with quote

From Help:

Integer and Word constants must end with the %-sign.

So use

Code:
Tab:
  Data 2248% , 2446% , 2641% , 2830% , 3011% 'etc.
 
[/quote]
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Fri Sep 11, 2020 10:33 am    Post subject: Reply with quote

Quote:
wasted a lot of time due to the peculiarities of the compiler.


Just read the help for DATA. And/or look at the sample.
But to blame the user ignorance and laziness of not consulting/reading the help on the compiler is a shame.
I hope this was just a quote and not your own writing.
The time i wasted in my life on users that never read a thing and then contact support is not to count in hours but years.

Also, if you post for other users here, make sure they have a license. And tell them to read the help. google translate can do a great job.

edit note : i see that after i posted, laborratte was before me. So my reply was for the original poster.[/quote]

_________________
Mark


Last edited by albertsm on Fri Sep 11, 2020 10:50 am; edited 2 times in total
Back to top
View user's profile Visit poster's website
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Fri Sep 11, 2020 10:34 am    Post subject: Reply with quote

According the help file:
Quote:
Integer and Word constants must end with the %-sign.
Long and Dword constants must end with the &-sign.
Single constants must end with the !-sign.
Double constants must end with the #-sign.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Sep 11, 2020 10:34 am    Post subject: Reply with quote

you must add % at the data word
Tab:
Data 2248% , 2446% , 2641% , 2830% , 3011% , 3184% , 3345% , 3494% , 3629% , 3748% , 3852% , 3938% , 4005% ,

i prefer use lookup than read

Code:

Dim W1 As Word
Dim Tbyte As Byte

   Restore Tab
  For Tbyte = 0 To 5
   ' Read W1
    W1 = Lookup(tbyte , Tab)
    Print W1 ;
    Print " tbyte:  " ; Tbyte;
    Print " ";


  Next

End
Tab:
  Data 2248% , 2446% , 2641% , 2830% , 3011% , 3184% , 3345% , 3494% , 3629% , 3748% , 3852% , 3938% , 4005% ,
 ' Data 4054 , 4084 , 4094 , 4084 , 4055 , 4006 , 3939 , 3853 , 3750 , 3631 , 3496 , 3348 , 3186 , 3014 , 2833 , 2644 ,
'  Data 2449 , 2251 , 2050 , 1850 , 1651 , 1456 , 1267 , 1085 , 913 , 751 , 602 , 467 , 347 , 244 , 158 , 89 ,
'  Data 40 , 10 , 0 , 9 , 38 , 87 , 154 , 239 , 342 , 461 , 596 , 744 , 905 , 1077 , 1258 , 1447 ,
'  Data 1641 , 1840 , 2040
 

it works with simulator
JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Fri Sep 11, 2020 2:05 pm    Post subject: Reply with quote

believe me, I've written too many BASIC programs. Therefore, it did not occur to me that the data needed to be additionally marked somehow.

And to be honest, I read the help, but I didn't find it.
On top of that, English is not my first language ...

sorry, I didn't mean to offend anyone ...
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Fri Sep 11, 2020 8:32 pm    Post subject: Reply with quote

both DATA and READ have a sample that show that DATA requires type info.
that you dont read it ok, but when something does not work and you still do not read it, and then blame it on the software, that is not ok.
this data/read/restore is there since 1995 or so. i have seen your amazing projects so i can almost not believe you did not knew about it.

so why does DATA need type info? when you have a PC you can store data with lot of bytes. but storing type info inside the data uses data which is precious on a small micro.
so only the actual data is stored. now if you have a value of 123, how should the compiler know that this is a byte? or a word, or dword, integer, etc. ?
it could figure out that the data would fit into a byte and then just store the byte. but what if you have 123, 1024, that would not work, and requires 3 bytes. these bytes are not aligned anymore.
And then nice routines like lookup() would not work any more. and also code that read data in a loop would not work.
ok, we could store run type info in the data but that would also complicate code like lookup() and even worse it would be slow. Now it is very fast because it can index.

anyway you best check out read/data/restore, lookup, lookupstr, lookdown

_________________
Mark
Back to top
View user's profile Visit poster's website
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Sat Sep 12, 2020 11:42 am    Post subject: Reply with quote

albertsm wrote:
i have seen your amazing projects so i can almost not believe you did not knew about it.

thank. That's right, for all the decades I have never used Data of type "word" in your compiler Embarassed
Yes, I have not met the requirements for marking the parameters of the data block anywhere in other compilers. I worked with different computers (ZX-Spectrum, IBM, Soviet computers...) and compilers, but there was no such need. Shocked

albertsm wrote:
so only the actual data is stored. now if you have a value of 123, how should the compiler know that this is a byte? or a word, or dword, integer, etc. ?

yes, this is a logical decision. I completely agree with you.

albertsm wrote:
I hope this was just a quote and not your own writing.

this is a poorly translated phrase, Embarassed
I wrote the text, translated it in the translate.google and sent it, but I did not check the quality of the translation.
This phrase from a book for beginner programmers. The author is Hungarian or Pole, I do not remember.
Completely this phrase sounds like this: (I specifically checked the translation several times. The meaning of the phrase is now translated correctly):
"Having received a new compiler, my old experience of work with past compilers made me make stupid mistakes and wasted time learning new things."
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sat Sep 12, 2020 2:34 pm    Post subject: Reply with quote

like you I am very unhappy with my poor English, I use Deepl as a translator, I find it much better than google

Как и ты, я очень недоволен своим бедным английским, я использую "Deepl" в качестве переводчика, я нахожу это намного лучше, чем "Google".
Wink
I hope Deepl do a good translation

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Sat Sep 12, 2020 2:56 pm    Post subject: Reply with quote

Smile
I know about this site. I have the link to this site on the second place
the first place is circuit simulator Falstad: http://www.falstad.com/circuit/circuitjs.html
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum