dim a(5), b(5), c(5)
for i = 1 to 5
a(i)=i
b(i)=10*i
next
c()=a()+b()
gosub [printArr]
c()=b()-a()
gosub [printArr]
c()=a()*b()
gosub [printArr]
a(0)=1 'or we have division by zero - obviously array operations start with 0's item
c()=b()/a()
gosub [printArr]
end
[printArr]
for i = 1 to 5
print c(i);" ";
next
print
return
dim A(10), B(10), C(10)
userInput$ = "C=A*B"
lhs$ = AddIndices$(word$(userInput$, 1, "="))
rhs$ = AddIndices$(word$(userInput$, 2, "="))
for i = 0 to 10
dummy = eval("FNassign("+lhs$+","+rhs$+")")
next
end
function AddIndices$(a$)
i = 1
while i <= len(a$)
if instr(" +-*/", mid$(a$,i,1)) then
i += 1
else
a$ = left$(a$,i) + "(i)" + mid$(a$,i+1)
i += 4
end if
wend
AddIndices$ = a$
end function
function assign(byref a, b)
a = b
end function
WindowWidth = 640
WindowHeight = 300
dim A(9),B(9),C(9),D(9),E(9),F(9),G(9),H(9),I(9)
nomainwin
for row = 0 to 5
x = 10
for col = 0 to 9
if col = 0 then
stylebits #w.tb _ES_CENTER, 0, 0, 0
w = 120
else
stylebits #w.tb _ES_READONLY, 0, 0, 0
w = 47
end if
textbox #w.tb, x, row*30+20, w, 20
x += w + 7
maphandle #w.tb, "#w.tb";row;col
next col
next row
stylebits #w.tb00 _ES_READONLY or _ES_CENTER, 0, 0, 0
button #w, "RECALCULATE", [recalc], UL, 260, 210
open "Array calculations" for window as #w
#w "trapclose [quit]"
#w.tb00 "index (i)"
#w.tb10 "A = i + 2"
#w.tb20 "B = SQR(A)"
#w.tb30 "C = A - B"
#w.tb40 "D = B * C"
#w.tb50 "E = D / A"
for col = 1 to 9
handle$ = "#w.tb0";col
#handle$ "!disable"
#handle$ col
next col
#w.tb10 "!setfocus"
[recalc]
for row = 1 to 5
handle$ = "#w.tb";row;0
#handle$ "!contents? userInput$"
if userInput$ <> "" then
lhs$ = AddIndices$(word$(userInput$, 1, "="))
rhs$ = AddIndices$(word$(userInput$, 2, "="))
for i = 1 to 9
handle$ = "#w.tb";row;i
try
dummy = eval("FNassign("+lhs$+","+rhs$+")")
#handle$ eval(lhs$)
catch
#handle$ Err$
end try
next i
end if
next row
wait
[quit]
close #w
end
function AddIndices$(a$)
i = 1
while i <= len(a$)
if (i = 1 or not(IsCap(mid$(a$, i-1, 1)))) and _
IsCap(mid$(a$, i, 1)) and _
not(IsCap(mid$(a$, i+1, 1))) then
a$ = left$(a$,i) + "(i)" + mid$(a$,i+1)
i += 3
end if
i += 1
wend
AddIndices$ = a$
end function
function IsCap(a$)
IsCap = (a$ >= "A" and a$ <= "Z")
end function
function assign(byref a, b)
a = b
end function