DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

For-Loop

Hello Community,

 

I am a Diadem Beginner and I am currently trying to Display the numbers from 1 to 10 by using a for-loop like in the following Code:

 

Dim i
Sub SFD_ProcessChannel(ChannelNumberP, InputListV, ParamP, DataP, ErrorP)
for i = 1 to 10
DataP = i
Next
End Sub

 

The important thing is that i want to visualize these numbers in every step of the loop.

Can someone explain to me why I get either "no value" or just the last number of the loop (10) displayed in visual?

0 Kudos
Message 1 of 6
(2,120 Views)

Hi Beginner,

 

To display the value in the loop. can put  logfilewrite i in loop.

 

Dim i
Sub SFD_ProcessChannel(ChannelNumberP, InputListV, ParamP, DataP, ErrorP)
  for i = 1 to 10

    logfilewrite i

    DataP = i

  Next
End Sub

 

Paul

 

if you are wanting to pass parameters back in parameter. then prefix the call parameter with either byref or byval.  

Byval when passing value and do not return anything. 

Byref when can return/modify the value in the sub/function.

Sub SFD_ProcessChannel(byval ChannelNumberP, byval InputListV, byval ParamP,byref DataP, byref ErrorP)

 

 

0 Kudos
Message 2 of 6
(2,063 Views)

Hi Pesmith, thanks for your answer. Sadly the Problem is still there. Only the last value of my loop is being displayed. I have attached a PNG of the "visual-window" in Diadem to Show you my actual Problem.

0 Kudos
Message 3 of 6
(2,012 Views)

Hi Beginner12345,

 

It is my understanding that when you run a script block in DAC, the entire script executes before the script block returns and the data flow recommences.  That would explain why in DAC/VISUAL you only ever see the last iteration of the variable.  The DAC/VISUAL automation environment is designed for data acquisition control, based on configurations defined by nodes and wires-- it's not designed to be fully automated by a scripting language.  The script block is a tool to help you expand what one node can do in DAC/VISUAL, but the execution is still determined by the data/event flow of the wires and nodes.

 

Perhaps Walter Rick will comment further-- he knows more about this than I do.

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 4 of 6
(2,002 Views)

Hi Brad_Turpin,

 

thank you for your answer. I will try to contact Walter_Rick. If you have any other ideas i would love to hear them.

 

 

0 Kudos
Message 5 of 6
(1,994 Views)
08-24-2020

Hi Beginner12345,

 

The DAC kernel calls the function SFD_ProcessChannel and waits until it is finished. Your problem can be realized by using the output of the VBS-Block back as input and this script:

 

dim i

Sub SFD_ProcessChannel( ChannelNumberP, InputListV, ParamP, DataP, ErrorP )

    DataP = InputListV(0) + 1

End Sub

 

Greetings

Walter

0 Kudos
Message 6 of 6
(1,969 Views)