View previous topic :: View next topic |
Author |
Message |
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Mon Apr 14, 2014 6:16 pm Post subject: array error |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Mon Apr 14, 2014 6:59 pm Post subject: |
|
|
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 |
|
|
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Mon Apr 14, 2014 9:32 pm Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Mon Apr 14, 2014 9:55 pm Post subject: |
|
|
when you omit an element, the first will be used. but it is much better to be specific. _________________ Mark |
|
Back to top |
|
|
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Tue Apr 15, 2014 10:17 pm Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Tue Apr 15, 2014 10:39 pm Post subject: |
|
|
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 |
|
|
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Thu Apr 17, 2014 10:14 pm Post subject: |
|
|
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 |
|
|
|