Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Problem passing variables between Subs

hello,

I'm trying to pass two Variant variables between two Subroutines, one that calls the other one, and am getting the

error message
Run-time error '5':

Invalid procedure call or assignment

and the code stops on
AppActivate CablettersAppId

Private Sub ForTestingPurposes_Click()
Dim CablettersAppId, CabcallsAppId As Variant

CablettersAppId = Shell("C:\Program Files\Anzio15\anzio32.exe", 1)
CabcallsAppId = Shell("D:\PROGRAM FILES\TELSTAR\TelStar.exe", 1)

Call CABCALLSandCABLETTERStestTelnet(CabletttersAppId, CabcallsAppId)

Status.Text = "end of test"
End Sub


Private Sub CABCALLSandCABLETTERStestTelnet(CablettersAppId, CabcallsAppId)

TimeDelay (7)
AppActivate CablettersAppId
VbSendKeys "robinson{ENTER}"
TimeDelay (2)
VbSendKeys "CAB{ENTER}"
TimeDelay (2)
VbSendKeys "DR75{ENTER}"
TimeDelay (2)
VbSendKeys "{ENTER}"

TimeDelay (60 * 5)

TimeDelay (7)
AppActivate CabcallsAppId
VbSendKeys "robinson{ENTER}"
TimeDelay (2)
VbSendKeys "ROPER{ENTER}"
TimeDelay (2)
VbSendKeys "DR75{ENTER}"
TimeDelay (2)
VbSendKeys "{ENTER}"
TimeDelay (2)
End Sub

Now this code use to work before when I had it all contained within one Sub like this:

[code]
Private Sub ForTestingPurposes_Click()
Dim CablettersAppId, CabcallsAppId As Variant

CablettersAppId = Shell("C:\Program Files\Anzio15\anzio32.exe", 1)
CabcallsAppId = Shell("D:\PROGRAM FILES\TELSTAR\TelStar.exe", 1)

TimeDelay (7)
AppActivate CablettersAppId
VbSendKeys "robinson{ENTER}"
TimeDelay (2)
VbSendKeys "CAB{ENTER}"
TimeDelay (2)
VbSendKeys "DR75{ENTER}"
TimeDelay (2)
VbSendKeys "{ENTER}"

TimeDelay (60 * 5)

TimeDelay (7)
AppActivate CabcallsAppId
VbSendKeys "robinson{ENTER}"
TimeDelay (2)
VbSendKeys "ROPER{ENTER}"
TimeDelay (2)
VbSendKeys "DR75{ENTER}"
TimeDelay (2)
VbSendKeys "{ENTER}"
TimeDelay (2)
Status.Text = "end of test"
End Sub
[\code]

Can anyone help me to get it to work in a multi-subroutine/function setting?

thanks in advance,
david
[2494 byte] By [dgr7] at [2007-11-11 10:24:29]
# 1 Re: Problem passing variables between Subs
Nevermind, I fixed the problem, had a typo
thank you!
dgr7 at 2007-11-11 17:22:39 >
# 2 Re: Problem passing variables between Subs
Dim CablettersAppId, CabcallsAppId As Variant

FYI: In case you did not know this but in VB you must declare each variable explicitly for each data type you want. The above Dim only works because the default data type is Variant. You could have just done this:
Dim CablettersAppId, CabcallsAppId
And you would have the same result; but if you had done this:
Dim I, J, K As Integer
Only K would be an Integer, I and J are both Variants to have all three as type Integer you would need to use this:
Dim I As Integer, J As Integer, K As Integer

Have Fun! :WAVE:
Ron Weller at 2007-11-11 17:23:39 >