tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
Instead of writing this:
I would like to use a loop, as follows:
It works but how can I adapt it if Called takes more than one argument?
For example, if Called looked like this:
how do I change ArgArray in Calling so it passes the args "in pairs"?
Thanks
[/FONT]
<strike></strike>
[/FONT]
<strike></strike><strike></strike>
[/FONT]
<strike></strike>
Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Option Explicit[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Sub Calling()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Call Module1.Called(somearg:=1)
Call Module1.Called(somearg:=2)
Call Module1.Called(somearg:=3)
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Sub Called(ByRef somearg As Integer)[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
somearg = somearg + 1[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
End Sub
I would like to use a loop, as follows:
Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif][FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Option Explicit
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Calling()
Dim ArgArray() As Variant
ArgArray() = Array(1, 2, 3)
Dim i As Integer
For i = LBound(ArgArray(), 1) To UBound(ArgArray(), 1)
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] Call Module1.Called(somearg:=CInt(ArgArray(i)))
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] Next I
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]End Sub[/FONT]
[/FONT][FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
It works but how can I adapt it if Called takes more than one argument?
For example, if Called looked like this:
Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Called(ByRef somearg As Integer, ByRef somearg2 As Integer)[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
somearg = somearg2 + 1[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
End Sub
how do I change ArgArray in Calling so it passes the args "in pairs"?
Thanks
[/FONT]
<strike></strike>
[/FONT]
<strike></strike><strike></strike>
[/FONT]
<strike></strike>