DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

GlobalReDim %22Preserve%22 Problems

Solved!
Go to solution

Dear,

 

I am having problems using global arrays 

 

 If UBound(index) <> 0 then
    For j = 0 to (UBound (index))
      nDiff = (index2(j)*nDelT)-(index(j)*nDelT)
      If nDiff >= 7 then
        GlobalReDim "Preserve ind_1_5(j)" : ind_1_5(j) = index(j) +(1.5/nDelT)
        GlobalReDim "Preserve ind_5(j)": ind_5(j) = index(j) +(5/nDelT)
        GlobalReDim "Preserve ind_7(j)":  ind_7(j) = index(j) +(7/nDelT)
      End If
      If nDiff <7 and nDiff >= 5  then
        GlobalReDim "Preserve ind_1_5(j)" : MsgBox (Ubound(ind_1_5) & " y " & j)
        ind_1_5(j) = index(j) +(1.5/nDelT)
        GlobalReDim "Preserve ind_5(j)": ind_5(j) = index(j) +(5/nDelT)
        GlobalReDim "Preserve ind_7(j)" :  ind_7(j) = -1
      End If
      If nDiff  >= 1.5 and nDiff <5 then
        GlobalReDim "Preserve ind_1_5(j)": ind_1_5(j)= index(j) +(1.5/nDelT)
        GlobalReDim "Preserve ind_5(j)": ind_5(j) = -1
        GlobalReDim "Preserve ind_7(j)" :  ind_7(j) = -1
      End If
      If nDiff < 1.5 then
        GlobalReDim"Preserve ind_1_5(j)" : ind_1_5(j)  = -1
        GlobalReDim"Preserve ind_5(j)" : ind_5(j) = -1
        GlobalReDim"Preserve ind_7(j)" : ind_7(j) = -1
      End If
    Next
  Else
      GlobalReDim (ind_1_5(0)) : ind_1_5(0)  = -1
      GlobalReDim(ind_5(0)) : ind_5(0) = -1
      GlobalReDim(ind_7(0)) : ind_7(0) = -1
  End If 

The command GlobalReDim "Preserve.... is not working... I dont know why it dont re dimension the arrays. I get to j =1, after asking to do the GlobalReDim ("Preserve") my Arrays should have new dimension but after I recieve a message "Subscript out of range: 'j' ", the message bos I locate in the code is to verify that case.

 

Any idea what I am doing wrong???

0 Kudos
Message 1 of 7
(4,863 Views)

Hi Maria,

 

I didn't spot a problem in your code, but it looks like you're doing an awful lot of redimensioning.  Could you please describe what you're trying to accomplish?  Also, when and how do these variables get created the first time?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 2 of 7
(4,828 Views)

Dear,

 

I am trying to find when some condition in a channel if happening, in this case that the value in my channel will be 100, if it happens for more than 7 seconds I want to keep the information of other channel just after those 7 seconds, but also after 5 and 1.5 seconds. If it only happend for a total time between 5 and 7 seconds, I want to have the information of the other channel at 5 and 1.5 seconds... so thats basically the idea.

 

Do 
      cnt = cnt + 1
      iInd = ChnFind ("Ch("""&str(Data.Root.ActiveChannelGroup.Name)&"/"& str(oAccel.Name) &""")="&str(nInd),iInd2+1)
      iInd2 = ChnFind ("Ch("""&str(Data.Root.ActiveChannelGroup.Name)&"/"& str(oAccel.Name) &""")<"&str(nInd),iInd+1)
      ReDim Preserve index(cnt-1) : index(cnt-1) = iInd
      ReDim Preserve index2(cnt-1) : index2(cnt-1) = iInd2
    Loop Until (iInd = 0)
  ReDim Preserve index(UBound(index)-1) 
  ReDim Preserve index2(UBound(index2)-1) 
  Dim nDelT : nDelT = oAccel.Properties("wf_increment").Value
  
  'Times
  GlobalDim ("ind_1_5()"):  GlobalDim ("ind_5()") : GlobalDim ("ind_7()") : Dim nDiff

 Thats the fisrt part of the procedure...

 

Thank you for your answer

 

Best Regards

 

Maria

0 Kudos
Message 3 of 7
(4,812 Views)
Solution
Accepted by topic author MariaEsmeral

Hi Maria,

 

If you have DIAdem 2014 or later I'd recommend using the ChnEvent...() functions to identify the regions of interest.  These functions officially released in DIAdem 2015 with ANALYSIS dialogs and Help entries, but there is a slightly different version that shipped with DIAdem 2014 that was only available from a VBScript.  What DIAdem version are you using?

 

What is the reason for storing your answers in global arrays as opposed to local VBScript arrays or new DIAdem channels?  What do you want to do with those results after you discover them?  Plot them?  Analyze them?  Save them back to a data file?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 7
(4,797 Views)

Hi,

I have familiar problem like Maria was a few years ago.
I am trying to make dynamic array to print values at table but global function Call GlobalReDim ("Preserve Arr(index)") : Arr(index) = 0 do not work.

 

Down below you have the script code:

 

Dim i

GlobalDim "Arr" : Arr = Array()

For i=0 to 10
GlobalReDim "Preserve Arr(i)"
Arr(i) = 0
Next

0 Kudos
Message 5 of 7
(1,648 Views)

Hi Dan-Dud,

 

Your loop variable needs to be interpreted. The correct code is as follows:

Dim i

If Not Iteminfoget("Arr") Then
  call GlobalDim("Arr()")
end if

For i=0 to 10
  call GlobalReDim("Preserve Arr(" & str(i) & ")")
  Arr(i) = i
Next

For i=0 to 10
  LogfileWrite Arr(i) 
Next

 

Greetings

Walter

0 Kudos
Message 6 of 7
(1,619 Views)

Thank you, now it works perfectly.

0 Kudos
Message 7 of 7
(1,611 Views)