Machsupport Forum
		Mach Discussion => General Mach Discussion => Topic started by: Raychar 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?
- 
				https://www.google.co.uk/url?sa=t&source=web&rct=j&url=http://www.machsupport.com/wp-content/uploads/2013/02/VBScript_Commands.pdf&ved=0ahUKEwjS6bC-hq7QAhWmIsAKHaasAzcQFggaMAA&usg=AFQjCNFszAIBSvNbzrOHiGC9a9OX58NWWA&sig2=e_RcX9WV8c1DtHsAg3GPSw
 
 Pdf page 11, need to pass the parameters in brackets and need to define the parameters for the sub
 
 VB is not really my thing...
- 
				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
 
- 
				 Case 2.....t=2000.....call A(t1) should be   Case 2.....t=2000.....call A(t2)....
			
- 
				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)