Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 29, 2024, 12:52:54 12:52


Login with username, password and session length


Pages: [1]
Print
Author Topic: Array  (Read 3138 times)
0 Members and 1 Guest are viewing this topic.
Husanto
Newbie
*
Offline Offline

Posts: 10

Thank You
-Given: 0
-Receive: 1


« on: November 27, 2007, 10:37:50 10:37 »

Hi,

    i want to ask about using array in microbasic. example i have a code:

dim temp1 as byte[4]
const temp as byte[3][4] =((1,2,3,4),(5,6,7,8),(7,5,3,2))
main()
     for i=0 to 3
          temp1 = temp[2]
     next i
end.

why the result always (1,2,3,4) not ( 7,5,3,2) Huh?can give information about using array two dimension to use in looping function.
Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #1 on: November 28, 2007, 01:06:53 01:06 »

This is actually better solved in C, but since You do it in Basic, let's see...
Proton does a 2-dim array this way:

' Display text from two LDATA tables
' Based on their address located in a seperate table
      
        ' Use a 14-bit core device
       
        Dim ADDRESS as Word
        Dim LOOP as Word
        Dim DATA_BYTE as Byte
       
        Delayms 200                     ' Wait for PICmicro to stabilise
        Cls                           ' Clear the LCD
        ADDRESS = LREAD ADDR_TABLE         ' Locate the address of the first string
          While 1 = 1                     ' Create an infinite loop
           DATA_BYTE = LREAD ADDRESS      ' Read each character from the LDATA string
            If DATA_BYTE = 0 Then Break      ' Exit if NULL found
           Print DATA_BYTE               ' Display the character
            Inc ADDRESS                  ' Next character
        Wend                        ' Close the loop
EXIT_LOOP:
      
        Cursor 2,1                     ' Point to line 2 of the LCD
      ADDRESS = LREAD ADDR_TABLE + 2      ' Locate the address of the second string
          While 1 = 1                     ' Create an infinite loop
           DATA_BYTE = LREAD ADDRESS      ' Read each character from the LDATA string
            If DATA_BYTE = 0 Then Break    ' Exit if NULL found
           Print DATA_BYTE               ' Display the character
            Inc ADDRESS                  ' Next character
        Wend                        ' Close the loop
EXIT_LOOP2:
        Stop
       
       
ADDR_TABLE:                           ' Table of address's
      LDATA WORD STRING1,WORD STRING2
STRING1:
      LDATA "HELLO",0
STRING2:
      LDATA "WORLD",0
******************************************************************************************
From here You would be able to add one more table and get the job done
Logged

Code Warrior
th_sak
Active Member
***
Offline Offline

Posts: 141

Thank You
-Given: 150
-Receive: 149



« Reply #2 on: November 28, 2007, 12:51:13 12:51 »

You have only one pointer for your 2 dimension array, but you should have 2 pointers.
This should work.

dim temp1 as byte[4]
const temp as byte[3][4] =((1,2,3,4),(5,6,7,8),(7,5,3,2))
main()
     for i=0 to 2      ; this is pointer for rows [3]
        for j=0 to 3   ; this is pointer for columns [4]
          temp1 = temp[i,j]
        next j
     next i
end.
Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #3 on: November 28, 2007, 04:33:55 16:33 »

As I say, less is more(though I haven't tested it yet)
Logged

Code Warrior
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC