Looking for instructions and help in using Sub Main() and End Sub an such

Looking for instructions and help in using Sub Main() and End Sub an such

Anonymous
Not applicable
3,523 Views
3 Replies
Message 1 of 4

Looking for instructions and help in using Sub Main() and End Sub an such

Anonymous
Not applicable

Looking for help in using sub Main() and End Sub an such for iLogic 2012 coding.  I'd like to know when and why I would use such programming techniques.

0 Likes
3,524 Views
3 Replies
Replies (3)
Message 2 of 4

MjDeck
Autodesk
Autodesk

Sub Main() and End Sub are required if you want to define a function in your rule.  If you define a function, you can call it several times in the rule.  You can make the rule shorter and easier to understand.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 4

Anonymous
Not applicable

Mike:

 

Thanks for answering my question.  Would it possible to flesh out your answer a bit more?  Something like:

 

Sub Main()

 

Majority of iLogic Code Placed Here

 

Call Sub X

 

End Sub

 

Sub X

 

iLogic Code for sub or function Placed Here

 

End Sub

 

By doing so, I think I and others reading this thread might understand the concept of Sub End Sub much better.

 

Thanks again for your reply!

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hope you do not mind my kibitzing Mike,

 

Jim,

 

As Mike said a 'Sub Main' procedure is required by iLogic.  When to use other procedures 'Sub Routines' or 'Functions' is dependent on what you are trying to achieve as the programmer.  The general rule of thumb is that repetitive code should be placed in a sub routine or function. This however is not the only reason..  

 

Sub Routines process code and return control to the main programming thread. 

Functions return a single variable and can be used inline in lieu of a single value in forumulas and such.

 

Sub Main()

  Dim Inches as Single = 10

  ' Display Inches as Millimeters

  Messagebox.Show(MM(Inches))

End Sub

 

Function MM(Byval Inches as Single) as Single

  Dim Millimeters as Single = Inches * 25.4

  Return Millimeters

End Function

 

As this topic covers a lot of ground under the heading of general programming I would suggest you pick up a getting started VB book, Look up VB on line tutorials or ask questions in general VB forums.