Code: Select all
' Program comparison function
' Returns 0 if all elements are equal
' Returns 1 if any of the items was different
' We can compare from position 1 to the end
' And / or from an initial position to an intermediate / end in the array
declare function comparation (i, f, a ()) as integer
dim i as integer ' position init
dim f as integer ' position end
dim a () as integer
cls
x = 100
redim a (x)
i = 1
f = x
for h = 1 to 100
a (h) = 3
next h
print comparation (i, f, a ())
a (5) = 8
print comparation (i, f, a ())
sleep
end
function comparation (i, f, a ()) as integer
z = 0
y = a(i)
for j = i to f
for k = i to f
if a (k) <> y then z = 1 :exit for
next k
if z = 1 then exit for
next j
if z = 0 then
comparation = 0 'True
else
comparation = 1 'False
end if
end function