View previous topic :: View next topic |
Author |
Message |
ivangel
Joined: 20 Sep 2010 Posts: 41 Location: Poland
|
Posted: Fri Jan 16, 2015 2:04 pm Post subject: Problem when printing multi-dimensional array |
|
|
As in the title:
Code: | Print #7 , "IP " ; Socket(1 , 1) ; " " ; Socket(1 , 2) ; " " ; Socket(1 , 3) ; " " ; Socket(1 , 4) ; |
print the value of the first element "Socket(1 , 1)" (4 times the same)
Code: | Dim Socket(5 , 4) As Byte | to be sure...
Code: | Socket(1 , 1) = 192
Socket(1 , 2) = 168
Socket(1 , 3) = 0
Socket(1 , 4) = 65 |
will print: IP 192 192 192 192
(BASCOM-AVR version : 2.0.7.8 )[/code] _________________ www.midaz.com.pl
Last edited by ivangel on Fri Jan 16, 2015 2:18 pm; edited 1 time in total |
|
Back to top |
|
|
aphawk
Joined: 23 Jan 2010 Posts: 168 Location: Brazil
|
|
Back to top |
|
|
ivangel
Joined: 20 Sep 2010 Posts: 41 Location: Poland
|
Posted: Fri Jan 16, 2015 2:21 pm Post subject: |
|
|
Thx aphawk _________________ www.midaz.com.pl |
|
Back to top |
|
|
ivangel
Joined: 20 Sep 2010 Posts: 41 Location: Poland
|
Posted: Fri Jan 16, 2015 3:27 pm Post subject: |
|
|
Code: | Y = 82
For Z = 1 To 5
For X = 1 To 4
Readeeprom Socket(z , X) , Y
Incr Y
E_socket(z , X) = Socket(z , X)
Next X
Next Z |
Readeeprom / Writeeeprom not working to. Generates an error:
Code: | Error : 129 Line : 438 ( or ) missing [___WR30 = X) , Y] , in File : C:\Users\SEM\Downloads\WWW do Webserver\Server_wokrking.bas
Error : 46 Line : 438 Assignment error, unknown variable (DIM) [___WR30: 0 X) , Y: 0] , in File : C:\Users\SEM\Downloads\WWW do Webserver\Server_wokrking.bas
Error : 126 Line : 438 NEXT expected , in File : C:\Users\SEM\Downloads\WWW do Webserver\Server_wokrking.bas
|
_________________ www.midaz.com.pl |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jan 16, 2015 4:25 pm Post subject: |
|
|
It was probably not a good idea to release this multi dim support without publishing the restrictions but i still have on the todo list to give more info on different new features.
Original i wanted to add something like setarray/getarray so there would not be any conflict with the existing design.
But doing it the same as VB syntax was of course way better. So that is how it is implemented. But there is a trap : the code that calculates the memory offset trashes registers. And some are loaded since the code is expecting the values in certain registers. It need more extensive rewrites of code to change that.
So what works is assigning variables and reading them. But as soon you use the multi dim array in other ways , you can get problems. I say can, since it depends on the statement, datatype and operation. So you best assume that it will NOT work.
Maybe it was not such a good idea to include multi dim already. It might be removed in the next update and reintroduced till the other required changes are made as well. _________________ Mark |
|
Back to top |
|
|
ivangel
Joined: 20 Sep 2010 Posts: 41 Location: Poland
|
Posted: Fri Jan 16, 2015 7:30 pm Post subject: |
|
|
Mark absolutely not! I believe, and certainly not just me, it's a very good idea, and it is us, the users, to share his modest help in the removal of any problems. With all these problems you can go out comparing each element of the array in a temporary variable (in my case Byte type) and use it in the functions is Print, Readeeprom etc.
Code: | Y = 82
For Z = 1 To 5
For X = 1 To 4
Readeeprom Temp , Y
Socket(z , X) = Temp
Incr Y
E_socket(z , X) = Socket(z , X)
Next X
Next Z |
where "Temp as Byte"...
Best regards[/code] _________________ www.midaz.com.pl |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sat Jan 17, 2015 2:56 am Post subject: |
|
|
I agree with Ivangel.
Being able to use multidimensional arrays as part of normal math manipulations is really useful.
Getting data from EEprom, and outputting it with Prints or whatever can always be handled with easy-to-write work arounds, usuallly only needing a temporary variable.
Bascom has a similar design philisophy with the restriction to only handle one math operation per statement. I never saw a problem with that. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
aphawk
Joined: 23 Jan 2010 Posts: 168 Location: Brazil
|
Posted: Sat Jan 17, 2015 3:55 am Post subject: |
|
|
I agree with Ivangel too !
Multidimensional arrays helps a lot in many programs. They are working, and this eventual problem can be fixed easy in our programs.
Paulo |
|
Back to top |
|
|
aphawk
Joined: 23 Jan 2010 Posts: 168 Location: Brazil
|
Posted: Sat Jan 17, 2015 4:00 am Post subject: |
|
|
I agree with Ivangel too !
Multidimensional arrays helps a lot in many programs. They are working, and this eventual problem can be fixed easy in our programs.
Paulo |
|
Back to top |
|
|
AndersL
Joined: 25 Jan 2010 Posts: 92 Location: Kragerø,Norway
|
Posted: Sun Jan 18, 2015 5:42 pm Post subject: |
|
|
It seems that when the multi array are inside a sub and called, it will not compile.
Code: |
$regfile = "m1284pdef.dat"
$hwstack = 150
$swstack = 150
$framesize = 150
$crystal = 12000000
$baud = 38400
Config Submode = New
Config Base = 0 'need tu use zero based array
Const C_module_cnt = 1
Dim Module_data_size(c_module_cnt , 2) As Byte
Dim Temp_byte As Byte
Sub Profibus_rx
Temp_byte = 2
Module_data_size(module_cnt , 0) = Temp_byte + 1
End Sub
Do
Profibus_rx
Loop
End
|
Gives two of these errors: Error : 61 Line : 18 Label not found [_X_MODULE_DATA_SIZE]
Could there be a workaround for this? _________________ Anders |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sun Jan 18, 2015 9:47 pm Post subject: |
|
|
yes, when the array is not accessed in the main, the data lines created for the array are not found. for each multi array, a lookup value is created with the index values and weight. but the submode/new causes this table not to be written. i will have a look at that.
workaround is simple : put a read or assign to the multi array in the main, and make sure one of the indexes is a variable. _________________ Mark |
|
Back to top |
|
|
AndersL
Joined: 25 Jan 2010 Posts: 92 Location: Kragerø,Norway
|
Posted: Sun Jan 18, 2015 10:44 pm Post subject: |
|
|
Thanks a lot Mark, that made it work _________________ Anders |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Mon Jan 19, 2015 4:25 pm Post subject: |
|
|
Hi both,
Quote: | workaround is simple : put a read or assign to the multi array in the main, and make sure one of the indexes is a variable.
|
Could you explain (post code)?
Regards, Meister |
|
Back to top |
|
|
mmarlette
Joined: 30 Nov 2007 Posts: 311 Location: Delano, MN
|
Posted: Mon Jan 19, 2015 9:05 pm Post subject: |
|
|
My vote is to leave it in as well.
This is a HUGE leap forward for BASCOM.
In the meantime we can live with the simple temp assignment workarounds.
Your explanation on the implementation really helps.
Thanks again!!
Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 20, 2015 12:21 am Post subject: |
|
|
in the mean time it was fixed.
requested code :
just access the multi dim in the global program:
Code: |
$regfile = "m1284pdef.dat"
$hwstack = 150
$swstack = 150
$framesize = 150
$crystal = 12000000
$baud = 38400
Config Submode = New
Config Base = 0 'need tu use zero based array
Const C_module_cnt = 1
Dim Module_data_size(c_module_cnt , 2) As Byte
Dim Temp_byte As Byte
Sub Profibus_rx
Temp_byte = 2
Module_data_size(module_cnt , 0) = Temp_byte + 1
End Sub
Do
Profibus_rx
Loop
Module_data_size(module_cnt , 0) = 1 'ADDED
End |
See ADDED. _________________ Mark |
|
Back to top |
|
|
|