Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

array error

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Mon Apr 14, 2014 6:16 pm    Post subject: array error Reply with quote

To avoid unpleasant reproaches I tryed to search for my problem, but I have not found the answer. If there is, can you sign me please?

In the help file there is :

Code:
'the empty () indicated that an array will be passed
Declare Sub Teststr(b As Byte , Dl() As String)
 


In my case I have a sub that I have declared:
Code:
Declare Sub Lcd_message(byval Indice_messaggio As Byte , Byval Message_array() As Byte)


and then I tryed to use with no success:

Code:
Lcd_message(1 , Ric_idcard())


I tryed with call, without with different message error as you can see at row 276 and 312

Apologize if the question is fool, but I don't understand something.
BR


(BASCOM-AVR version : 2.0.7.7 )

_________________
Bascom AVR full
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 14, 2014 6:59 pm    Post subject: Reply with quote

Code:
Declare Sub Lcd_message(byval Indice_messaggio As Byte , Message_array() As Byte)
dim ar(10) as Byte , b as byte

for b = 1 to 10
  ar(b) = b
next

lcd_message 3 , ar(1)


Sub Lcd_message(byval Indice_messaggio As Byte , Message_array() As Byte)
  print message_array(Indice_messaggio)

end sub


in the declare you use () but when passing data, you need to pass the first element.
also notice that arrays are passed byref.

_________________
Mark
Back to top
View user's profile Visit poster's website
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Mon Apr 14, 2014 9:32 pm    Post subject: Reply with quote

Mr. Alberts,

you are right, and in the file help is wrote, only now I have read. But I use also in this mode without warning message:

Code:
Ceck_ric_reader_rfid Rcv_buff()


Where is the difference?

BR

_________________
Bascom AVR full
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 14, 2014 9:55 pm    Post subject: Reply with quote

when you omit an element, the first will be used. but it is much better to be specific.
_________________
Mark
Back to top
View user's profile Visit poster's website
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Tue Apr 15, 2014 10:17 pm    Post subject: Reply with quote

Quote:
also notice that arrays are passed byref.


OK thank you Mr. Alberts, it's clear. But I've notice that if I have a sub:

Code:
Declare Sub Lcd_message(byval Indice_messaggio As Byte , Message_array() As Byte)


Message_array is passed byref. But inside sub when I use Message_array i have no correct value! (strange value that i no understand). So only for test inside sub I used original array and the value is correct!
Is there some concept that i lose?
BR

_________________
Bascom AVR full
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Apr 15, 2014 10:39 pm    Post subject: Reply with quote

without code it is hard to tell.
but the concept of passing an array is simple : you pass byreference which means you pass the address of the array.
in the sub you refer to this array with the name you used to pass.
Code:
dim ar(10) as byte
declare sub test(some() as byte)


sub test(some() as byte)
  print some(1)  'will print content of ar(1)
end sub
 


if the content is not right, test if the passed array is still ok.
you should post some code that demos your problem. (no screen shots)

_________________
Mark
Back to top
View user's profile Visit poster's website
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Tue Apr 15, 2014 10:54 pm    Post subject: Reply with quote

Ok i post a link to complete file. The problem is on Sub Lcd_message(byval Indice_messaggio As Byte , Message_array() As Byte).


https://dl.dropboxusercontent.com/u/15219757/2560_9_4_2014REV1Work.bas

BR

_________________
Bascom AVR full
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Apr 17, 2014 10:14 pm    Post subject: Reply with quote

when you call the sub, use : Lcd_message 1 , Rcv_buff(1)
that is, the first array element.
if you get strange values, it might be because of an interrupt. in that case, increase $hwstack

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive 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