2017-08-27 16 views
0
Sub main() 

    Dim x as integer=5 

Sub add() 

End sub 

Sub add() 

    Dim z as integer = 5 + x 
    Console.writeline(z) 

End sub y 

它不会工作,因为我要在sub add()Dim x所以我想是的x该值传递给sub add()的方式。传递的东西的价值从子main()中另一个子程序

+0

你需要上晚自习[在VB范围(http://stackoverflow.com/a/33249045/1070452); *将参数传递给方法*的基本任务,所有在您读取[ask]并参加[tour] – Plutonix

回答

0

可以使用Scoping将变量传递给这样的方法:

Sub main() 
    Dim x as integer = 5 
    add(x) 
End sub 

Sub add(NewX As Integer) 
    Dim z as integer = 5 + NewX 
    Console.writeline(z) 
End sub 
相关问题