Sub Function byval byref
in Console Application and Class Library
  1. Output = 3 Module Module1 Dim a As Integer = 1 Sub Main() Dim a As Integer = 2 Console.WriteLine(a + Module1.a) Console.ReadLine() End Sub End Module
  2. Output = 5 Module Module1 Sub Main() oho() Console.ReadLine() End Sub Sub oho() Console.WriteLine(5) End Sub End Module
  3. Output = 1 Module Module1 Sub Main() Dim a As Integer = 1 oho(a) Console.ReadLine() End Sub Sub oho(ByVal b As Integer) Console.WriteLine(b) End Sub End Module
  4. Output = 2 Module Module1 Sub Main() Dim a As Integer = 1 burin(a) Console.WriteLine(a) Console.ReadLine() End Sub Sub burin(ByRef b As Integer) b = 2 End Sub End Module
  5. Output = 1001 Module Module1 Sub Main() Dim a As Integer = 1 Dim b As Integer = 10 burin(a, b) Console.WriteLine(a + b) Console.ReadLine() End Sub Sub burin(ByVal x As Integer, ByRef y As Integer) x = 100 : y = 1000 End Sub End Module
  6. Output = 5 Module Module1 Sub Main() Console.WriteLine(burin()) Console.ReadLine() End Sub Function burin() As Integer burin = 5 End Function End Module
  7. Output = 10 Module Module1 Sub Main() Console.WriteLine(burin(5)) Console.ReadLine() End Sub Function burin(ByRef x As Integer) As Integer burin = x * 2 End Function End Module
  8. Output = 4 Module Module1 Sub Main() Dim a As Integer = 1 Console.WriteLine(burin(a) + a) Console.ReadLine() End Sub Function burin(ByRef x As Integer) As Integer burin = x * 2 : x = burin End Function End Module
  9. Output = 56 Module Module1 Sub Main() sub1() Console.Write(func1()) End Sub Sub sub1() Console.Write(5) End Sub Function func1() As Integer func1 = 6 End Function End Module
  10. Output = 16 Module Module1 Dim a As Integer = 1 Sub Main() sub1(a, a) Console.WriteLine(func1(a)) End Sub Sub sub1(ByRef x As Integer, ByRef y As Integer) a += x : x += a : y += a End Sub Function func1(ByRef x As Integer) As Integer func1 = x + x End Function End Module
  11. Output = 4 ' Application type = windows application ' startup = Sub Main Public Class Class1 Shared a As Integer = 1 Shared Sub main() sub1(a, a) MsgBox(func1(a)) End Sub Shared Sub sub1(ByVal x As Integer, ByVal y As Integer) a = x + y End Sub Shared Function func1(ByRef x As Integer) As Integer func1 = x + x End Function End Class
  12. Output = 4 ' Application type = windows application ' startup = Sub Main ' Class1 and Class2 is in same file Public Class Class1 Shared a As Integer = 1 Shared Sub main() Class2.sub1(a, a) MsgBox(Class2.func1(a)) End Sub End Class Public Class Class2 Shared Sub sub1(ByRef x As Integer, ByVal y As Integer) x = x + y End Sub Shared Function func1(ByRef x As Integer) As Integer func1 = x + x End Function End Class