ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Object instead of passing arguments (https://www.excelbanter.com/excel-programming/400859-object-instead-passing-arguments.html)

Arne Hegefors

Object instead of passing arguments
 
Hi! I have a sub that calls another sub and passes alot of arguments. The
idea is for the main sub to send Strings to the other sub that fills those
strings with data. This works fine but is it possible to use an obect instead
and just pass the object as argument? How would you write that? The problem
is that the number of arguments may become very large and it just seems like
a bad idea to pass eg 20 arguments to a sub? Any help appreciated!

Here is the main sub:
Dim secID As String
Dim strikePrice As String
Dim maturityDate As String
Dim counterParty As String
Dim numberOfUnits As String
Dim optionType As String
Dim excerciseType As String

If sSecurityTypeText = "#FX OPTION" Then
oPosFile.Cells(i, 1).Value = "COMMODITY OPTION"
secID = oPosFile.Cells(i, 3)
Call readFXOptionFile(secID, numberOfUnits,
strikePrice, maturityDate, counterParty, optionType, excerciseType)

and here is the other sub:

Public Sub readFXOptionFile(ID As String, unts As String, strike As String,
matDate As String, cPrt As String, tpe As String, exType As String)
Dim i As Long

ID = Split(ID, "_")(0)
Workbooks.Open "X:\SCD_RiskManager_Pos\RMDBII\test.xls"
Workbooks("test.xls").Activate

Range("A1").Activate
Do Until ActiveCell.Offset(i, 0) = ""
If InStr(CStr(ActiveCell.Offset(i, 0)), ID) 0 Then 'match ID
unts = ActiveCell.Offset(i, 1) 'assign
data
strike = ActiveCell.Offset(i, 3)
matDate = ActiveCell.Offset(i, 4)
cPrt = ActiveCell.Offset(i, 5) 'fix cells!!!!!!!
tpe = ActiveCell.Offset(i, 5)
exType = ActiveCell.Offset(i, 5)
End If
i = i + 1
Loop
End Sub


Any help most appreciated! Thanks alot!


joel

Object instead of passing arguments
 
You could put the strings in an array an then pass the array.

"Arne Hegefors" wrote:

Hi! I have a sub that calls another sub and passes alot of arguments. The
idea is for the main sub to send Strings to the other sub that fills those
strings with data. This works fine but is it possible to use an obect instead
and just pass the object as argument? How would you write that? The problem
is that the number of arguments may become very large and it just seems like
a bad idea to pass eg 20 arguments to a sub? Any help appreciated!

Here is the main sub:
Dim secID As String
Dim strikePrice As String
Dim maturityDate As String
Dim counterParty As String
Dim numberOfUnits As String
Dim optionType As String
Dim excerciseType As String

If sSecurityTypeText = "#FX OPTION" Then
oPosFile.Cells(i, 1).Value = "COMMODITY OPTION"
secID = oPosFile.Cells(i, 3)
Call readFXOptionFile(secID, numberOfUnits,
strikePrice, maturityDate, counterParty, optionType, excerciseType)

and here is the other sub:

Public Sub readFXOptionFile(ID As String, unts As String, strike As String,
matDate As String, cPrt As String, tpe As String, exType As String)
Dim i As Long

ID = Split(ID, "_")(0)
Workbooks.Open "X:\SCD_RiskManager_Pos\RMDBII\test.xls"
Workbooks("test.xls").Activate

Range("A1").Activate
Do Until ActiveCell.Offset(i, 0) = ""
If InStr(CStr(ActiveCell.Offset(i, 0)), ID) 0 Then 'match ID
unts = ActiveCell.Offset(i, 1) 'assign
data
strike = ActiveCell.Offset(i, 3)
matDate = ActiveCell.Offset(i, 4)
cPrt = ActiveCell.Offset(i, 5) 'fix cells!!!!!!!
tpe = ActiveCell.Offset(i, 5)
exType = ActiveCell.Offset(i, 5)
End If
i = i + 1
Loop
End Sub


Any help most appreciated! Thanks alot!



All times are GMT +1. The time now is 08:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com