Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call to child script: Should parent wait for execution? 1

Status
Not open for further replies.

iamareplicant

Programmer
Aug 7, 2004
50
US
I am new to vbscript.

I have some test scripts set up that look like this (the parent instantiates several class objects from a child script, one of which is a timer):

(PARENT SCRIPT .wsf file)

Code:
<job id="Job1">
     <script language="VBScript" src="C:\WINNT\Profiles\jgoodma1\Desktop\Classes.vbs"/>
    <script language="VBScript">
option explicit
Dim NewTimer
dim objAcc
set NewTimer = New UniversalTimer
NewTimer.Interval = 60
NewTimer.RunTimer
set objAcc = New RunAccessMacro
objAcc.f_DoAdbTest
set objAcc = nothing 
    </script>
</job>

(CHILD SCRIPT Clasess.vbs)
Code:
Class UniversalTimer

	Public Property Let Interval(nValue)
		nValue = Interval 
	End Property
	
	Public Property Get Interval()
		Interval = nValue
	End Property

	Public Sub RunTimer

		Dim lngStart
		
        
        		lngStart = Timer()
	        	intPause = Interval
		        Do While Timer() < lngStart + intPause 
        		loop

	End Sub

End Class


Class RunAccessMacro

public sub f_DoAdbTest()


	dim objAccess

		set objAccess = CreateObject("Access.Application")
		objAccess.OpenCurrentDatabase ("C:\WINNT\Profiles\jgoodma1\Desktop\Utility.mdb")

		objAccess.docmd.RunMacro "macTest"
set objAccess=nothing
  

end sub
End Class

When the code NewTimer.RunTimer is run, the timer should run for 60 seconds, which I would think would mean that the next 2 lines in the parent would NOT get executed for 60 seconds.

Again, I am new to vbscript. The parent is a .wsf file, and when I exectute the parent, the entire script runs instantly (and I know that objAcc.f_DoAdbTest runs correctly becuase that line of code runs an Access macro in that creates a temp table in an Access db).

So, my issue is this: I want to be able to create a rather involved parent that uses a number of classes, and those class's methods. But each method called needs to finish before going on to the next line of code in the parent. This is why I set up a timer to see if this is true.

But it appears not to be.

Can one of you experts shed some light on calling another script for a parent, and how the parent (.wsf) file handles the calls/objects to those child scripts? Does/should the parent call or instantiantion of a child's method execute before the next line of parent code is run?

Thanks in advance for any insight into this.

Jeff
 
i might be wrong but

lngStart = Timer() 'this looks like you are just declaring an empty array
intPause = Interval
Do While Timer() < lngStart + intPause 'therefore this will do nothing?
loop

or am i missing something?

this might be better

Do While i < intPause
i = i + 1
Wscript.Sleep 1000
Loop
 
TImer is the built-in VB function...

When I run just the timer code as a sub inside of Access, it does work as intended.

However I will swap in your code no matter...'preciate the reply....
 
Ran the new timer code, same thing....script runs instantly..

So then, based on your reply, the parent SHOULd wait for the timer to execute before executing its next line of code (set objAcc = New RunAccessMacro), correct?
 
you are running a wsf file....which uses an include to a vbscript file....these therefore inheritly use the WSH and vbscript runtimes....i think you will find there is no built in timer function in vbscript...there is as you rightly point out in VB but not in vbscript, perhaps there is a Timer control available in VBA as well...

either way i think you will find you are doing something like (i presume an empty array will be implicitly convertted to 0)

Do While 0 < 60...which should loop forever which is all very confusing....

try the alternative using Wscript.Sleep
 
these statements are wrong

Public Property Let Interval(nValue)
nValue = Interval
End Property

Public Property Get Interval()
Interval = nValue
End Property
 
well actually this is a better context to make the 'wrong' statement
<code>
Class UniversalTimer

Public Property Let Interval(nValue)
nValue = Interval
End Property

Public Property Get Interval()
Interval = nValue
End Property
</code>
 
Public Property Let Interval(nValue)
nValue = Interval
End Property

nValue is the value you pass to the Sub, i.e. the value you want to set/let Interval be...therefore your next statement

nValue = Interval

does not make any sense.
 
perhaps this will make things clearer...

set NewTimer = New UniversalTimer
NewTimer.Interval = 60
Wscript.Echo NewTime.Interval
 
you are missing the fact that for your class to 'hold' properties for re-use later you will need to internal variables to the class to hold this info in memory or it will be lost to the atmosphere as soon as the property assignment subs have finished their work
 
you are my hero. I used part of your solution, and got rid of my stupid bug (indeed, nValue = Interval...uh, hello) and I have success. I appreciate your help Mr. Movie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top