ilogic Functions &/Or Sub Routines Passing Arguments Back To Main Code

ilogic Functions &/Or Sub Routines Passing Arguments Back To Main Code

Tim_Mulder
Contributor Contributor
1,346 Views
5 Replies
Message 1 of 6

ilogic Functions &/Or Sub Routines Passing Arguments Back To Main Code

Tim_Mulder
Contributor
Contributor

Hello All,

 

I'm struggling to understand Functions &/Or Sub Routines in ilogic.
In effect I am trying to have a function/sub routine within my code that stores a list of integers.

Then I want return some of those integers (with some if else statements) to my called function/sub routine so Ican use these values elsewhere. I have a rough idea of how functions work in VBA but that doesn't seem to translate to ilogic, unless I am missing something. Here is what I have so far

 

Sub Main
Call SplitPinCalc((BoltSize), Split_Pin, Split_Pin_Hole, Split_Pin_Dist)
'These values above don't update with function values below
End Sub

Function SplitPinCalc(BoltSize As Integer, Split_Pin As Integer, Split_Pin_Hole As Integer, Split_Pin_Dist As Integer)
If BoltSize = "12" Then
	Split_Pin = 3
	Split_Pin_Hole = 4
	Split_Pin_Dist = BoltSize*2
Else If 'Blah Blah Blah
End If
Return SplitPinCalc
End Function

My code so far enters into the function and works as intended, but those values are not passed back up to the called function arguments.

Any help & instruction would be much appreciated.

 

Kind Regards

 

Tim

0 Likes
1,347 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor

What would you like to be returned for the function:

Split_Pin = 3
	Split_Pin_Hole = 4
	Split_Pin_Dist

This function can only return one value.

If you need more you need to create a Class.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 6

bradeneuropeArthur
Mentor
Mentor

This is how it works in basics

 

Public Sub main()
MsgBox a(2)
End Sub
Private Function a(b As Integer) As Integer

If b = 1 Then
a = 11
End If

If b = 2 Then
a = 22
End If

End Function

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @Tim_Mulder ,

 

Welcome to the forum. In addition to the previous replies, this simple example might help illustrate the use of a function.

 

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

 

Sub Main

'basket 1
Apples = 10
Oranges = 10

'get qty of basket1
Basket1 = QTY_Fruit( Apples, Oranges)

'basket 2
Apples = 2
Oranges = 3

'get qty of basket2
Basket2 = QTY_Fruit( Apples, Oranges) 

MsgBox(Basket1 + Basket2 & " total pcs")
End Sub

Function QTY_Fruit(A As Integer, O As Integer )

	'calc fruit
	oQTY = A + O
	
	'send sum back to main sub
	Return oQTY 
End Function

 

and here is a slightly different way of doing this based on the syntax that bradeneuropeArthur 's example used to write and return the function.

Sub Main

'basket 1
Apples = 10
Oranges = 10

'get qty of basket1
Basket1 = QTY_Fruit( Apples, Oranges)


'basket 2
Apples = 2
Oranges = 3

Basket2 = QTY_Fruit( Apples, Oranges) 

MsgBox(Basket1 + Basket2 & " total pcs")
End Sub

Function QTY_Fruit (A As Integer, O As Integer ) As Integer

	'calc fruit
	QTY_Fruit = A + O

End Function

 

EESignature

0 Likes
Message 5 of 6

Tim_Mulder
Contributor
Contributor

Thanks for your reply,

 

Please find in picture what I'm intending the function or sub to achieve.

 

Intended Function_Sub.png

 

I have the feeling I may be trying to do something the Function can't handle.

Thanks for the help.

 

Regards

 

Tim

0 Likes
Message 6 of 6

laszlo_nagy
Contributor
Contributor

Hi!

 

Try  this

 

Sub Main

Dim Spin_Pin As Integer = 0
Dim Spin_Pin_Hole As Integer = 0
Dim Spin_Pin_Dist As Integer = 0

'Array
Dim result(2) As Integer

'Call the Function
result = SplitPinCalc(12)

'Store the results 
Spin_Pin = result(0)
Spin_Pin_Hole = result(1)
Spin_Pin_Dist = result(2)

'Display the Result
MessageBox.Show("Pin is:" & Spin_Pin & " - Hole is:" & Spin_Pin_Hole & " - Distance is:" & Spin_Pin_Dist )

End Sub


Function SplitPinCalc(Boltsize As Integer) As Integer()
	
	
	Dim fResult(2) As Integer
	
	'Condition
	If Boltsize = 12 Then
		fResult(0) = 3 'Pin
		fResult(1) = 4 'Hole
		fResult(2) = Boltsize * 2 'Dist
	End If
	
	'Return Value (Array)
	SplitPinCalc = fResult
	
End Function