Home/Support/Support Forum/Error trying to print array variable in RabbitWeb
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Error trying to print array variable in RabbitWeb

0 votes
I want to print out a structure member from an array and RabbitWeb gives me a "ZHMTL ERROR: Unknown variable error. The variables are declared globally and registered via the #web command.
struct meas1_type { char year; char mon; char mday; char hour; char min; char sec; char rh; char temp; } meas1 [MEAS1_SIZE]; #web meas1; int idx1 = 0; #web idx1;
Here is applicable portion of the RabbitWeb script:
idx = <?z print($idx1) ?> << OK <table border="1"> <tr><th>Idx</th><th>Time</th><th>Temp</th><th>Jumid</th></tr> <tr><td><?z print($A) ?></td> << OK <td><?z print($meas1[0].hour) ?>: <?z print($meas1[$idx1].min) ?>: << Error <?z print($meas1[$idx1].sec) ?></td> << Error
The "print($idx1)" and the "print($meas1[0].hour" execute correctly. The two "$meas1[$idx1].xxxx" outputs have the errors. I have used "$meas1[$A].xxxx" in the past with a loop with no problems.
Why is RabbitWeb throwing an error for $meas1[$idx1].xxxx"?
asked Jan 4, 2016 in Rabbit Software by bflusche New to the Community (3 points)

Please log in or register to answer this question.

1 Answer

0 votes
I'm pretty sure that's a limitation of RabbitWeb. I think you can only use loop variables to index into arrays, but you'd have to double-check the documentation on that.

You could possibly create another RabbitWeb variable as a pointer to one of the meas1 entries. Update that instead of (or in addition to) updating idx1, and then reference the record that way ($curmeas->hour).

If RabbitWeb doesn't allow the use of pointers, then you'd have to make a copy of "meas1[idx1]" into "curmeas" whenever idx1 changes, and reference the fields as "$curmeas.hour".
answered Jan 20, 2016 by TomCollins Veteran of the Digi Community (2,311 points)