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

It will not work because I have to Dim x in the sub add() so what I want is a way to pass that value of x to the sub add().

Ivan
  • 34,531
  • 8
  • 55
  • 100
  • You need to study up on [Scope in VB](http://stackoverflow.com/a/33249045/1070452); the the very basic task of *passing parameters to methods*, all after you read [ask] and take the [tour] – Ňɏssa Pøngjǣrdenlarp Aug 27 '17 at 19:43

1 Answers1

0

You can use Scoping to pass variables to a method like this :

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
Mousa Alfhaily
  • 1,260
  • 3
  • 20
  • 38