From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
05-12-2017 04:47 AM
Is it possible to put a sub precedure inside another sub procedure? I try to
do it but it does not work. Any ideas please?
Solved! Go to Solution.
05-12-2017 06:10 AM
Hi Amanda,
It is not possible to define a procedure inside another procedure:
sub Procedure1() 'do something sub Procedure2() 'do something else end sub end sub
But you can call a procedure inside another procedure:
sub Procedure1() 'do something call Procedure2() end sub sub Procedure2() 'do something else end sub
05-16-2017 03:30 AM
In fact, I created an easy dialog that contains two buttons, and I activated the
eventclick for each button, and so inside '' sub Button1_eventclick ...) i have
to Introduce my script. Besides, my script already contains several SUB
procedures. How can I do? could I replace the SUB
procedure with others that have the same utility? another
solutions? Thank you for your help
05-16-2017 08:43 AM
Hi,
I'm not sure if I understand your question correctly.
I suppose you want to define your procedures in an external file and call them in a SUD dialog?
If this is the case you could do it like this:
Dialog script:
Sub Dialog_EventInitialize(ByRef This) 'Erzeugter Event-Handler call ScriptInclude(CurrentScriptPath & "Procedures.vbs") End Sub Sub Button1_EventClick(ByRef This) 'Erzeugter Event-Handler call OpenMsgBox() End Sub
Procedures.vbs (saved in the same folder like the sud file):
sub OpenMsgBox() call MsgBox("Hello World!") end sub
If this does not help, can you please provide more detailed information about what you want to do?
Regards
05-16-2017 09:41 AM - edited 05-16-2017 09:44 AM
With ScriptInclude you can include different versions of your script.
If there is another command with the same name that was already included before, it will be overwritten.
If you have two buttons that have to execute two different versions of the same procedure you can do it like this:
Sub Button1_EventClick(ByRef This) 'Erzeugter Event-Handler call ScriptInclude(CurrentScriptPath & "Procedures1.vbs") call OpenMsgBox() End Sub Sub Button2_EventClick(ByRef This) 'Erzeugter Event-Handler call ScriptInclude(CurrentScriptPath & "Procedures2.vbs") call OpenMsgBox() End Sub
Where Procedures1.vbs and Procedures2.vbs both include a procedure with name OpenMsgBox but different content.
But DIAdem help does not recommend to use ScriptInclude more than once:
http://zone.ni.com/reference/en-XX/help/370858M-01/comoff/scriptinclude/
05-22-2017 03:48 AM
Thank you very much for your help, But i am still blocked and I do not
know how to proceed. Indeed, I will try to explain more the problem:
I have three totally different scripts, which perform three different functions.
And I want to create a dialog box that contains three buttons each linked to a
script. The problem is that inside each script I have several Sub procedure,
and when I want to assemble it with a button, I find a problem with the sub
procedure, like it is shown in the picture attached. do you have any idea
please??
05-22-2017 08:04 AM
Hi,
It looks like you are using the recording mode to create simple code snippets.
Obviously one of these snippets with the InitMyFolders procedure was copied to another script, right?
Please have a look at my first post again. It shows in the first example that it's not possible to create a procedure inside another procedure, which is exactly what you are trying to do in your example.
You can either just delete the procedure and define the array variable directly inside the other procedure like this:
Sub Button4_EventClick(ByRef This) 'Erzeugter Event-Handler '... dim MyFolders() redim MyFolders(2) MyFolders(0) = "P:\results\" MyFolders(1) = "X:\results\" '... End Sub
or you can move the InitMyFolders procedure outside the other procedure like this (which is the same like in the second example of my first post):
sub InitMyFolders redim MyFolders(2) MyFolders(0) = "P:\results\" MyFolders(1) = "X:\results\" end sub Sub Button4_EventClick(ByRef This) 'Erzeugter Event-Handler '... dim MyFolders() call InitMyFolders() '... End Sub
I hope this helps. Also have a look at some VBScript tutorials about functions and procedures like here.
Regards
05-23-2017 07:36 AM
thank you so much !! it works .
Regards