loading
 
Setting array variable problem
Kresimir Majdenic from Croatia  [14 posts]
1 year
Have a problem with SetArrayVariable ... sometimes it works but in this example it appears it does not work - here is a code snippet ... I expected to see AN1 as an array variable in WATCH Variable module but AN1 does not show at all.

Can you point me where the problem might be?

Blobs = GetArrayVariable("BLOBS")
NoA = GetVariable("NumOfABox")
ABH = GetVariable("ABoxHeight")
ABW = GetVariable("ABoxWidth")
ABG = GetVariable("ABoxGap")
AH = GetVariable("AHeight")

ReDim Results(NoA,2)
for i = 0 to NoA-1
  Results(i,0) = "-"
  Results(i,1) = "-"
next

if isArray(Blobs) then
  BCount = (ubound(Blobs) + 1) / 2

  if BCount >= 1 then

    ReDim YBoxes(NoA,2)
    Y_Begin = AH
    for i = 0 to NoA-1
      YBoxes(i,0) = Y_Begin
      YBoxes(i,1) = Y_Begin - ABH
      Y_Begin = Y_Begin - ABH - ABG
    next

    ReDim XBoxes(4,2)
    X_Begin = 0
    for i = 0 to 4-1
      XBoxes(i,0) = X_Begin
      XBoxes(i,1) = X_Begin + ABW
      X_Begin = X_Begin + ABW
    next

    for j = 0 to BCount-1
      x = Blobs(j*2)
      y = Blobs(j*2+1)
        for i = 0 to NoA-1
        if (y >= YBoxes(i,1)) and (Y <= YBoxes(i,0)) then
          if (x >= XBoxes(0,0)) and (x <= XBoxes(0,1)) then
            if (Results(i,0) = "-") or (Results(i,0) = "S") then
              Results(i,0) = "S"
            else
              Results(i,0) = "?"
            end if
          elseif (x >= XBoxes(1,0)) and (x <= XBoxes(1,1)) then
            if Results(i,0) = "-" or (Results(i,0) = "I") then
              Results(i,0) = "I"
            else
              Results(i,0) = "?"
            end if
          elseif (x >= XBoxes(2,0)) and (x <= XBoxes(2,1)) then
            if Results(i,0) = "-" or (Results(i,0) = "R") then
              Results(i,0) = "R"
            else
              Results(i,0) = "?"
            end if
          elseif (x >= XBoxes(3,0)) and (x <= XBoxes(3,1)) then
            Results(i,1) = "A"
          else
            ' This should never happen
          end if
          exit for
                end if
            next
    next
  end if
end if

SetArrayVariable "AN1", Results
Steven Gentner from United States  [260 posts] 1 year
Kresimir,

The SetArrayVariable will expect a 1 dimensional array (i.e. a list of numbers). You are creating a two dimensional array which it will ignore. The reason for this is to keep things simple in terms of exporting and referencing arrays ... as not all the other scripting modules also have the concept of two dimensional arrays.

Instead, just double up, i.e. if you want to index the 10th row, use 10*2 and assume the array is double the size. In other words, simulate a 2 dimensional array using a single dimension.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index