Funky Arrays

new BookmarkLockedFalling
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

Post by Janet on Jan 4, 2008 9:29:04 GMT -5

This code

MyArray1$(1) = "Array Number 01"
MyArray2$(1) = "Array Number 02"
MyArray3$(1) = "Array Number 03"
End

balks at the second line. YET, if you add PRINT statements

MyArray1$(1) = "Array Number 01"
MyArray2$(1) = "Array Number 02"
MyArray3$(1) = "Array Number 03"
Print MyArray1$(1)
Print MyArray2$(1)
Print MyArray3$(1)
End

The code compiles, runs and displays as expected. You can assign the array value to a string value to make it work as well. Run this code with the last 3 lines commented out and uncommented out.

MyArray1$(1) = "Array Number 01"
MyArray2$(1) = "Array Number 02"
MyArray3$(1) = "Array Number 03"
'null$ = MyArray1$(1)
'null$ = MyArray2$(1)
'null$ = MyArray3$(1)
End

Is this some type of efficiency programming -- Run BASIC won't let you set aside memory for arrays unless you're actually going to USE those arrays ???


[br]
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

Post by Janet on Jan 4, 2008 9:31:49 GMT -5

Dimming the array makes it work as well.

Dim MyArray1$(2)
MyArray1$(1) = "Array Number 01"
Dim MyArray2$(2)
MyArray2$(1) = "Array Number 02"
MyArray3$(1) = "Array Number 03"
End

Let me go check the documentation. Maybe all arrays have to be dimmed, not just those with > 10 elements.
[br]
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

[br]
carlgundel
Administrator
*****
Creator of Run BASIC

carlgundel Avatar

Posts: 975

Post by carlgundel on Jan 4, 2008 11:45:34 GMT -5

The code compiles, runs and displays as expected. You can assign the array value to a string value to make it work as well. Run this code with the last 3 lines commented out and uncommented out.

MyArray1$(1) = "Array Number 01"
MyArray2$(1) = "Array Number 02"
MyArray3$(1) = "Array Number 03"
'null$ = MyArray1$(1)
'null$ = MyArray2$(1)
'null$ = MyArray3$(1)
End

Is this some type of efficiency programming -- Run BASIC won't let you set aside memory for arrays unless you're actually going to USE those arrays ???


That's clearly a bug. It's relatively minor in the sense that it only happens if you assign a value to an array that isn't used anywhere in the program, which isn't likely to happen too often. How did you happen across this?

-Carl
Last Edit: Jan 4, 2008 11:46:43 GMT -5 by carlgundel
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

Post by Janet on Jan 4, 2008 12:28:47 GMT -5

carlgundel said:

That's clearly a bug. It's relatively minor in the sense that it only happens if you assign a value to an array that isn't used anywhere in the program, which isn't likely to happen too often. How did you happen across this?

-Carl

Well, I was coding. Reconstructing sequences ...

First, I didn't know that all arrays needed to be dimmed, so I failed to do that. Then I set up a few arrays:

labelText$(1) = "Simple Rubric Generator"
boxWidth$(1) = "800px;"
boxHeight$(1) = "30px;"
boxMargin$(1) = "0px Auto;"
boxBorder$(1) = "1px Dashed #333;"
boxPadding$(1) = "15px 10px 0px 15px;"
backColor$(1) = "#FFFFCC;"
foreColor$(1) = "#333366;"
fontFamily$(1) = "Verdana;"
fontSize$(1) = "12pt;"
fontWeight$(1) = "Normal;"
fontStyle$(1) = "Normal;"
textAlign$(1) = "Left;"


and then tried to set up a sub using a concatenated CSSID:


Sub SetCSS
cssID #Logo, "{
Width: ";boxWidth$(1);"
Height: ";boxHeight$(1);"
Margin: ";boxMargin$(1);"
Border: ";boxBorder$(1);"
Padding: ";boxPadding$(1);"
Background-Color: ";backColor$(1);"
Color: ";foreColor$(1);"
Font-Family: ";fontFamily$(1);"
Font-Size: ";fontSize$(1);"
Font-Weight: ";fontWeight$(1);"
Font-Style: ";fontStyle$(1);"
Text-Align: ";textAlign$(1);"
}"
End Sub
[code]
I kept getting an error. I thought the code was something like this (note: no Dim statements)
[quote]
' Logo Variables
labelText$(1) = "Simple Rubric Generator"
boxWidth$(1) = "800px;"
boxHeight$(1) = "30px;"
boxMargin$(1) = "0px Auto;"
boxBorder$(1) = "1px Dashed #333;"
boxPadding$(1) = "15px 10px 0px 15px;"
backColor$(1) = "#FFFFCC;"
foreColor$(1) = "#333366;"
fontFamily$(1) = "Verdana;"
fontSize$(1) = "12pt;"
fontWeight$(1) = "Normal;"
fontStyle$(1) = "Normal;"
textAlign$(1) = "Left;"

Cls
Call SetCSS
Call DisplayLogo labelText$(1)


Print: Print
Link #q, "Quit", quit

Wait


Sub quit handle$
Cls
End
End Sub

Sub DisplayLogo text$
Div Logo
Print text$
End Div
End Sub

Sub SetCSS
cssID #Logo, "{
Width: ";boxWidth$(1);"
Height: ";boxHeight$(1);"
Margin: ";boxMargin$(1);"
Border: ";boxBorder$(1);"
Padding: ";boxPadding$(1);"
Background-Color: ";backColor$(1);"
Color: ";foreColor$(1);"
Font-Family: ";fontFamily$(1);"
Font-Size: ";fontSize$(1);"
Font-Weight: ";fontWeight$(1);"
Font-Style: ";fontStyle$(1);"
Text-Align: ";textAlign$(1);"
}"
End Sub

But now this code is compiling and not throwing an error.

Oh, okay, now I can reproduce it. When I was originally writing the code, I had defined all the css array variables, but hadn't yet included each array variable into the SetCSS sub. If you remove one of the above lines, say Text-Align: ";textAlign$(1);", you'll get the message with the textAlign$ array. If you don't dim the array, then that array HAS to be used somehow in your code, or it will throw an error.

Does this help?

[br]