Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:55 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Array initialisation

Author Message
f2cf1g
Newbie

Joined: 18/11/2016
Location: United Kingdom
Posts: 13
Posted: 05:45pm 11 Feb 2018
Copy link to clipboard 
Print this post

I need to initialise a lookup table of 120-odd integer elements. I can't put the initialisation values one line nor can I split it over several lines. The only method that I can think of is to write some code to load multiple DATA statements into the array during initialisation. I'm new to MM Basic and was wondering if there is a more elegant method of doing it?
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 09:26pm 11 Feb 2018
Copy link to clipboard 
Print this post

How many characters in each integer?

You ma be able to set a couple of string variables & read them in bit by bit in a loop using Val & Mid$.

Something a bit like this.
(Not sure the synatax is correct, but should give you the picture.

  Quote   Data1$="0001000200030004000500060007000800090010"

For n=1 to 10

p=n*
4-3

DArray%(n-
1)=Val(Mid$(Data1$,p,4)

Next n


Edit, DATA can probably also be imported with a similar loop.

Phil

Edit again..

Others might comment on if what's below would work.

  Quote   Data 0001,0002,0003,0004,0005,0006,0007,0008,0009,0010

For n=1 to 10

Read DArray%(n-1)

Next n



Edited by Phil23 2018-02-13
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 10:22pm 11 Feb 2018
Copy link to clipboard 
Print this post

Hi Roy,
maybe a job for Nathan's newest invention (simpleArrayFuncGen)?
This could save time and space (memory).

See also http://www.thebackshed.com/forum/forum_posts.asp?TID=10040.

Kind regards
Michael


causality ≠ correlation ≠ coincidence
 
f2cf1g
Newbie

Joined: 18/11/2016
Location: United Kingdom
Posts: 13
Posted: 12:01am 12 Feb 2018
Copy link to clipboard 
Print this post

I was afraid that the simplearraygeneration might be something relevant to my problem! Life is too short for that sort of complexity given I only have 120 numbers to deal with. I will use your second example Phil, with several data statements. Thanks both for you help.
Roy
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025