Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:56 02 Aug 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 Syntax

Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 08:54pm 12 Mar 2020
Copy link to clipboard 
Print this post

Hi All,

Just trying to understand this a bit better; Arrays have always been a love/hate for me....


 I2C read &H5A, 0, 2, Baseline() ' read the register
 Baseline(2) = true
 VAR Save Baseline()


2nd line I assume sets a 1 in element 2,
3rd line saves the entire array.

But not quite clear in the 1st that addresses ().

Tried to think it out in DOS, but get a few unexpected results.
Particularly the 1st attempt to set element 0; Returning an error,
but then setting Ok after doing element 1.

Guess what I'm asking for is a better understanding of the usage of ().

Thanks

Phil.


DOS MMBasic Ver 5.05.02
Copyright 2011-2019 Geoff Graham

> dim integer baseline(2)
> print baseline()
Error: Dimensions
> print baseline(0)
0
> baseline(0)=1
Error: Unknown command

> baseline(1)=2
> baseline(0)=1
> baseline(2)=3
> print baseline(0)
1
> print baseline(1)
2
> print baseline(2)
3

> print baseline()
Error: Dimensions
>

Edited 2020-03-13 06:56 by Phil23
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:05pm 12 Mar 2020
Copy link to clipboard 
Print this post

The only time you use an array name without a dimension is when you pass the full array to a sub/function etc.
For normal use, you need the dimension or index

Depending on OPTION BASE, the first valid value for an index is 0 or 1

VAR SAVE and I2C are examples of passing the array name and therefore don't need the index

Jim
VK7JH
MMedit
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 10:40pm 12 Mar 2020
Copy link to clipboard 
Print this post

Thanks Jim,

I'm still at a loss as to why baseline(0)=1 returned Unknown Command.
Just tried to reproduce it & I can't.

DOS MMBasic Ver 5.05.02
Copyright 2011-2019 Geoff Graham

> dim integer baseline(2)
> print baseline()
Error: Dimensions
> print baseline(0)
0
> baseline(0)=1
>


Planning on modifying Geoff's Airqual code by adding some Console output via ESP-Link & HC-12 Comms for logging on the E64.

I am pretty sure it will see the sensor as New, & uncalibrated each time I load the updated code.

Assuming I can read all the saved VAR's & reload them at boot while I't testing the new code.

Phil.
 
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