LeighWardle
asked on
vb.net - compilation error when trying to call overloaded constructor
Hi Experts,
Here is a sample of my code.
I am trying to call the overloaded constructor (see 3rd statement from the end).
But this gives a compiler "Type Expected" error.
Regards,
Leigh
Here is a sample of my code.
Public Class clsLicenceSentinel
Private mvarintProgramNumber As Integer
Public Sub New(intProgramNumber As Integer)
mvarintProgramNumber = intProgramNumber
End Sub
Public Sub New(strProgramNameAndMajorVersion As String)
Dim intProgramNumber As Integer
Select Case strProgramNameAndMajorVersion
Case "APSDS3"
intProgramNumber = 1
Case "CIRCLY6"
intProgramNumber = 2
Case "CIRCLY3"
intProgramNumber = 3
Case "CIRCLY4"
intProgramNumber = 4
Case "APSDS4"
intProgramNumber = 5
Case "CIRCLY5"
intProgramNumber = 6
Case "APSDS5"
intProgramNumber = 7
Case "HIPAVE1", "HIPAVE5" '20050208
intProgramNumber = 8
End Select
'call the constructor
Call New (intProgramNumber) '<<<< gives "Type Expected" error
End Sub
End Class
I am trying to call the overloaded constructor (see 3rd statement from the end).
But this gives a compiler "Type Expected" error.
Regards,
Leigh
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, sethi.
Regards,
Leigh
Regards,
Leigh
ASKER
Thanks, Paul Jackson, for your suggestion.
I tried that, but it gave this error:
Constructor call is valid only as the first statement in an instance constructor.
I have now found a workaround to get my code working - by putting all the code that is common to the two contructors into a single sub.
I tried that, but it gave this error:
Constructor call is valid only as the first statement in an instance constructor.
I have now found a workaround to get my code working - by putting all the code that is common to the two contructors into a single sub.
Glad I could help. Thanks.
Leigh, that method is the correct way to do it, its not a work around.
Open in new window