08-13-2020 06:08 AM
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?
08-14-2020 08:31 AM
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)
08-17-2020 04:13 AM
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.
08-17-2020 02:23 PM
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
08-18-2020 12:53 AM
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.
08-24-2020 08:37 AM
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