iLogic question

iLogic question

mgrenier2
Advocate Advocate
305 Views
3 Replies
Message 1 of 4

iLogic question

mgrenier2
Advocate
Advocate

When you pass variables to a Function or another Sub, is to possible to combine/group variables of the same type together instead of doing it one by one so it shortens/simplify the line?

 

I could not find an awnser on this

 

Private Function ExportExcel(ByRef oExcelApp As Object,ByRef oExcelWorkbook As Object, ByRef oExcelWorkSheet As Object, ByRef iRow As Integer, ByRef oPartsList As PartsList, ByRef Client As String, ByRef Projet As String, ByRef Titre As String,ByRef Dessinateur As String, ByRef F75_1 As String, ByRef F75_2 As String, ByRef F75_3 As String, ByRef excelTemplatePath As String, ByRef excelSheetName As String)

 

0 Likes
306 Views
3 Replies
Replies (3)
Message 2 of 4

Frederick_Law
Mentor
Mentor

Put them in a collection.

 

Do you really need to pass so many parameters?

Message 3 of 4

WCrihfield
Mentor
Mentor

Hi @mgrenier2.  This is essentially the same general idea that @Frederick_Law suggested, but maybe a little more specific.  There is an Inventor API object that is often really good for these types of situations, called a NameValueMap.  This is a transient object used for transferring one or more Name & Value pairs of data.  Each entry in it has a 'Name' (always a String), and a Value (an Object - can hold different data types or object types).  To use one of these, you have to create one with the TransientObjects.CreateNameValueMap method, and set the object it creates as the value of a NameValueMap type variable.  Then you can use that variable to add entries into it.  Then you can pass that variable to another method (Sub or Function) as one of its 'input' values (as long as that method is designed to accept one).  Then, once you have that object in the other method, you can access all the entries within it inside that method's block of code.

 

Below is a quickie, partial example of how it could be used.

Sub Main
	Dim oMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	oMap.Add("EntryName", "EntryValue")
	oMap.Add("RowIndex", 3)
	oMap.Add("PartsList", oMyPartsListObject)
	oMap.Add("Document", oMyInventorDocumentObject)
	oMap.Add("BooleanName", True)
	
	'call the other method to run, and supply this NameValueMap to it as 'input'
	ExportExcel(oMap)
	
End Sub

Sub ExportExcel(ByRef DataForExport As Inventor.NameValueMap)
	Dim oDoc As Inventor.Document = Nothing
	Dim oPList As Inventor.PartsList = Nothing
	Dim iRow As Integer = 0
	'make sure something was pass in, and make sure the expected entries are present
	If DataForExport.Count > 0 Then
		For i As Integer = 1 To DataForExport.Count
			Dim sEntryName As String = DataForExport.Name(i)
			Dim oEntryValue As Object = DataForExport.Value(sEntryName)
			If sEntryName = "Document" Then
				oDoc = oEntryValue
			ElseIf sEntryName = "PartsList" Then
				oPList = oEntryValue
			ElseIf sEntryName = "RowIndex" Then
				iRow = oEntryValue
				'and so on...
			End If
		Next 'i
		'use the recieved data as needed
		'more code...
	End If
	
	'or, just do this directly, to get the value, if you are sure it is there
	'Dim oDoc As Inventor.Document = DataForExport.Value("Document")
	
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

Curtis_Waguespack
Consultant
Consultant

@mgrenier2 

Here are a couple of other ways to do this.

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main
	oDog = "Fido"
	oCat = "Felix"
	Call Critters

	oDog = "Rover"
	oCat = "Rex"
	Call Critters

	oDog = "Spot"
	oCat = "Sam"
	Call Critters
	
End Sub

'declare here to share between subs
Dim oDog As String
Dim oCat As String

Sub Critters

	MsgBox("Dog name: " & oDog, , "iLogic")
	MsgBox("Cat name: " & oCat, , "iLogic")
End Sub

 

Class ThisRule

	'declare here to share between subs
	Dim oDog As String
	Dim oCat As String

	Sub Main
		oDog = "Fido"
		oCat = "Felix"
		Call Critters

		oDog = "Rover"
		oCat = "Rex"
		Call Critters

		oDog = "Spot"
		oCat = "Sam"
		Call Critters

	End Sub

	Sub Critters
		MsgBox("Dog name: " & oDog, , "iLogic")
		MsgBox("Cat name: " & oCat, , "iLogic")
	End Sub

End Class

EESignature

0 Likes