Skip to main content

Hello everyone,

 

So I'm trying to come up with a script that will be running the same thing multiple times, with only one variable changing.

I want to do this as Subroutine but am unsure how to accomplish this.

Here is what I have so far:

There is a Main Script that calls into the Subroutine.

The Subroutine will be the same for each report I need, however, in each report I need it to call which "Division" it is doing like 10 or 11.

Is there a way I can have the subroutine pull the division number from a list or from somewhere?

 

I was trying to avoid having multiple subroutines just for that one changing variable, as there are hundreds of these reports I need to run.

'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************

Dim V10 as String, V11 as String

V10 = 10
V11 = 11

SysHide "Timer"
EMConnect "A"

'*****************************************************************************************************
' Main Script
'*****************************************************************************************************
GoSub D10 'Configure Division 10 Report
GoSub D11 'Configure Division 11 Report
Exit Sub
'*****************************************************************************************************
' Divisions
'*****************************************************************************************************
D10:

GoSub DIV
Return


D11:

GoSub DIV
Return
*****************************************************************************************************
' Subroutine
'*****************************************************************************************************
DIV:
EMSendkey "14<ENTER>"
EMWaitX 1, RetC
EMSendkey "12<ENTER>"
EMWaitX 1, RetC
EMSendkey "7<ENTER>"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey *Insert Varibable(Division #) here*
EMWaitX 1, RetC

Return

*****************************************************************************************************
' End
'*****************************************************************************************************

 

As always, thank you in advance.


#Rumba

Hello everyone,

 

So I'm trying to come up with a script that will be running the same thing multiple times, with only one variable changing.

I want to do this as Subroutine but am unsure how to accomplish this.

Here is what I have so far:

There is a Main Script that calls into the Subroutine.

The Subroutine will be the same for each report I need, however, in each report I need it to call which "Division" it is doing like 10 or 11.

Is there a way I can have the subroutine pull the division number from a list or from somewhere?

 

I was trying to avoid having multiple subroutines just for that one changing variable, as there are hundreds of these reports I need to run.

'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************

Dim V10 as String, V11 as String

V10 = 10
V11 = 11

SysHide "Timer"
EMConnect "A"

'*****************************************************************************************************
' Main Script
'*****************************************************************************************************
GoSub D10 'Configure Division 10 Report
GoSub D11 'Configure Division 11 Report
Exit Sub
'*****************************************************************************************************
' Divisions
'*****************************************************************************************************
D10:

GoSub DIV
Return


D11:

GoSub DIV
Return
*****************************************************************************************************
' Subroutine
'*****************************************************************************************************
DIV:
EMSendkey "14<ENTER>"
EMWaitX 1, RetC
EMSendkey "12<ENTER>"
EMWaitX 1, RetC
EMSendkey "7<ENTER>"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey *Insert Varibable(Division #) here*
EMWaitX 1, RetC

Return

*****************************************************************************************************
' End
'*****************************************************************************************************

 

As always, thank you in advance.


#Rumba
Run it in a Do or While loop and iterate through the Div numbers.

Hello everyone,

 

So I'm trying to come up with a script that will be running the same thing multiple times, with only one variable changing.

I want to do this as Subroutine but am unsure how to accomplish this.

Here is what I have so far:

There is a Main Script that calls into the Subroutine.

The Subroutine will be the same for each report I need, however, in each report I need it to call which "Division" it is doing like 10 or 11.

Is there a way I can have the subroutine pull the division number from a list or from somewhere?

 

I was trying to avoid having multiple subroutines just for that one changing variable, as there are hundreds of these reports I need to run.

'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************

Dim V10 as String, V11 as String

V10 = 10
V11 = 11

SysHide "Timer"
EMConnect "A"

'*****************************************************************************************************
' Main Script
'*****************************************************************************************************
GoSub D10 'Configure Division 10 Report
GoSub D11 'Configure Division 11 Report
Exit Sub
'*****************************************************************************************************
' Divisions
'*****************************************************************************************************
D10:

GoSub DIV
Return


D11:

GoSub DIV
Return
*****************************************************************************************************
' Subroutine
'*****************************************************************************************************
DIV:
EMSendkey "14<ENTER>"
EMWaitX 1, RetC
EMSendkey "12<ENTER>"
EMWaitX 1, RetC
EMSendkey "7<ENTER>"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey *Insert Varibable(Division #) here*
EMWaitX 1, RetC

Return

*****************************************************************************************************
' End
'*****************************************************************************************************

 

As always, thank you in advance.


#Rumba
Thank you Owen.

Luckily I was able to figure out a way to do it. I just Set the Variable "V" every time it calls the next Division.

'*****************************************************************************************************
' Main
'*****************************************************************************************************
GoSub D10 'Configure Division 10 Report
'GoSub D20 'Configure Division 20 Report
'GoSub D30 'Configure Division 30 Report
'GoSub D40 'Configure Division 40 Report
'GoSub D45 'Configure Division 45 Report
'GoSub D50 'Configure Division 50 Report
'GoSub D55 'Configure Division 55 Report
'GoSub D60 'Configure Division 60 Report
'GoSub D70 'Configure Division 70 Report
'GoSub D75 'Configure Division 75 Report
'GoSub D80 'Configure Division 80 Report
'GoSub D90 'Configure Division 90 Report
Exit Sub
'*****************************************************************************************************
' Division 10
'*****************************************************************************************************
D10:
V = 10
GoSub DIV
Return

D20:
V = 20
GoSub DIV
Return

D30:
V = 30
GoSub DIV
Return

Hello everyone,

 

So I'm trying to come up with a script that will be running the same thing multiple times, with only one variable changing.

I want to do this as Subroutine but am unsure how to accomplish this.

Here is what I have so far:

There is a Main Script that calls into the Subroutine.

The Subroutine will be the same for each report I need, however, in each report I need it to call which "Division" it is doing like 10 or 11.

Is there a way I can have the subroutine pull the division number from a list or from somewhere?

 

I was trying to avoid having multiple subroutines just for that one changing variable, as there are hundreds of these reports I need to run.

'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************

Dim V10 as String, V11 as String

V10 = 10
V11 = 11

SysHide "Timer"
EMConnect "A"

'*****************************************************************************************************
' Main Script
'*****************************************************************************************************
GoSub D10 'Configure Division 10 Report
GoSub D11 'Configure Division 11 Report
Exit Sub
'*****************************************************************************************************
' Divisions
'*****************************************************************************************************
D10:

GoSub DIV
Return


D11:

GoSub DIV
Return
*****************************************************************************************************
' Subroutine
'*****************************************************************************************************
DIV:
EMSendkey "14<ENTER>"
EMWaitX 1, RetC
EMSendkey "12<ENTER>"
EMWaitX 1, RetC
EMSendkey "7<ENTER>"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey "1"
EMWaitX 1, RetC
EMSendkey *Insert Varibable(Division #) here*
EMWaitX 1, RetC

Return

*****************************************************************************************************
' End
'*****************************************************************************************************

 

As always, thank you in advance.


#Rumba
Hi guys,

for this find of thing I would use a Function, and then call that from your Sub Main

e.g.
Sub Main
RetC = myRoutine(10)
Msgbox RetC
RetC = myRoutine(11)
Msgbox RetC
End Sub

Function myRoutine(myDiv as Integer) as Boolean
Msgbox myDiv
myRoutine = True
End Function

All I'm doing is passing an Int to the function and popping a message box and setting a Return code. You should take the code you want to repeated execute and drop it into the function, then when you want to call it, pass the DIV number which you want it to execute.

You don't need a return code, but it's there is you want to add a check to see if you are on the correct end screen or not.

Using GoTo and GoSub ect should be avoided if possible as it can make it hard to follow the flow of the code. Using Functions reduces the number of lines of code and simplifies the logic (IMHO :-).

Tom