Hello Guest it is July 07, 2020, 12:08:07 AM

Author Topic: V.B. programming problem  (Read 1089 times)

0 Members and 1 Guest are viewing this topic.

V.B. programming problem
« on: November 16, 2016, 08:45:55 AM »
Hi, everbody,

The defined variable‘s value in the main program cannot pass down to subroutine program....

In main program, there are different cases to have different time values as below:

Sub main
.....
 Case 1.... t=1000.... call A
 Case 2.....t=2000.....call A
......
End Sub
....

Sub A
ActivateSignal(Output4)
Sleep(t)
DeActivateSignal(Output4)
Sleep(50)
End Sub

However, during the program runs, corresponding t value cannot be read in subroutine, can anybody help to explain what mistakes were made?
Rob

Albert Einstein ― “If you can't explain it to a six year old, you don't understand it yourself.”
Re: V.B. programming problem
« Reply #2 on: November 17, 2016, 05:51:46 AM »
Thanks for the guild line. It works now as below:

Sub main
.....
 Case 1.... t=1000.... call A(1000)
 Case 2.....t=2000.....call A(2000)
......
End Sub
....

Sub A(t As Integer)
ActivateSignal(Output4)
Sleep(t)
DeActivateSignal(Output4)
Sleep(50)
End Sub

'-------------------------------------------
'--------------------------------------------
However, to go a step further, wanting to define the two variables at the beginning of program, it won't work..??

Sub main

Dim t1
Dim t2
t1=1000
t2=2000
.....
 Case 1.... t=1000.... call A(t1)
 Case 2.....t=2000.....call A(t1)
......
End Sub

Sub A(t As Integer)

ActivateSignal(Output4)
Sleep(t)
DeActivateSignal(Output4)
Sleep(50)

End Sub
Re: V.B. programming problem
« Reply #3 on: November 17, 2016, 05:52:49 AM »
 Case 2.....t=2000.....call A(t1) should be   Case 2.....t=2000.....call A(t2)....
Re: V.B. programming problem
« Reply #4 on: November 17, 2016, 05:57:10 AM »
Glad you found a solution, sorry couldn't be more help, but that's for reposting as I learnt something (been playing with c, c# for a while, VB requires a brain reboot)
Rob

Albert Einstein ― “If you can't explain it to a six year old, you don't understand it yourself.”