marcus
marcus

Reputation: 81

How do I call a Sub?

I am teaching myself VB and am trying to call the sub Main() however, when I include it after the End Sub it says Syntax error and when I run it without calling, nothing happens. Please could you explain to me what I am doing wrong and how to call the sub.

Imports System.IO

Public Class Form1
    Sub Main()
        HouseCalc(99800, 43100)
        Call HouseCalc(380950, 49500)
    End Sub

    Sub HouseCalc(price As Single, wage As Single)
        If 2.5 * wage <= 0.8 * price Then
            MsgBox("You cannot afford this house.")
        Else
            MsgBox("This house is affordable.")
        End If
    End Sub

End Class

Thanks, Marcus

Upvotes: 0

Views: 923

Answers (1)

SLaks
SLaks

Reputation: 888203

You can only put executable code, such as sub or function calls, inside a sub or a function; not directly within a class.

However, your Sub Main() is never being called; the Sub Main() that VB calls when starting your program must be in a Module.
(and your project already has one; look at Properties/My Project)

Upvotes: 2

Related Questions