Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In order to do it in the manner you want, you either need to make an instance of the classes as @Chipmunk suggests or make the method Shared. You also should get away from the old VB6 method of doing this. Your method should look like:</p> <pre><code>Public Shared Function Add(ByVal n1 As Int16, ByVal n2 As Int16) As Int16 Return n1 + n2 End Function </code></pre> <p><strong>Edit:</strong><br /> This would then be called using:</p> <pre><code>Dim x as Int16 = MyFunc1.MyFunc2.Add(15, 16) </code></pre> <p>Using <code>Call</code> assumes you are executing a sub and not a function. The purpose of a function is to return data. Simply <code>Call</code>ing it won't result in the desired effect.</p> <p><strong>Edit 2 (example)</strong></p> <p>You can use a module for this as @Chipmunk states, or you can use a class. My preference is class only because MS hasn't made their minds up about modules (they did away with them for one of the versions - I forget which - and then brought them back).</p> <p><strong>Class method</strong></p> <pre><code>Namespace MyFunc1 Public Class MyFunc2 Public Shared Function Add(ByVal n1 As Int16, ByVal n2 As Int16) As Int16 Return n1 + n2 End Function End Class End Namespace </code></pre> <p>Usage in Form1.vb</p> <pre><code>Imports MyFunc1 ... Public Sub DoAdd() Dim x as Int16 = MyFunc2.Add(15, 16) ' MyFunc1 Namespace imported, MyFunc2 ' is assumed. No instance is created End Sub </code></pre> <p><strong>Module Method</strong></p> <pre><code>Public Module MyFunctions ' Notice no shared modifier here. The module uses the legacy module ' concept to assume that it is shared Public Function Add(ByVal n1 as Int16, ByVal n2 as Int16) As Int16 Return n1 + n2 End Function End Module </code></pre> <p>Usage in Form1.vb</p> <p>Since the module would be in a referenced namespace in your project, you would just call it directly:</p> <pre><code>Public Sub DoAdd() Dim x as Int16 = MyFunctions.Add(15, 16) ' This assumes that your MyFunctions ' module is in an imported namespace End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload