By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,946 Members | 1,676 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,946 IT Pros & Developers. It's quick & easy.

a vb syntax peculiarity

P: n/a
In the example below, the indicated line yields a syntax error. If the
phrase 'New Test1' appears where an expression is expected, it seems to work
ok. But if it appears where a statement is expected, it does not work. Why
does vb syntax have this peculiar asymmetry? Please no comments about the
foolishness of the code, it just minimally illustrates my question. Also,
the issue poses no inconvenience - I am just curious.

Public Class test1
Public Sub sub1(ByVal i As Integer)
End Sub
Public Function func1(ByVal i As Integer) As Integer
End Function
Public Shared Sub driver()
Dim t As New test1
Dim i As Integer
i = t.func1(i)
i = (New test1).func1(i) ' this compiles ok
t.sub1(i)
(New test1).sub1(i) ' syntax error on this line
End Sub
End Class

Aug 3 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 3 Ago, 23:16, AMercer <AMer...@discussions.microsoft.comwrote:
In the example below, the indicated line yields a syntax error. If the
phrase 'New Test1' appears where an expression is expected, it seems to work
ok. But if it appears where a statement is expected, it does not work. Why
does vb syntax have this peculiar asymmetry? Please no comments about the
foolishness of the code, it just minimally illustrates my question. Also,
the issue poses no inconvenience - I am just curious.

Public Class test1
Public Sub sub1(ByVal i As Integer)
End Sub
Public Function func1(ByVal i As Integer) As Integer
End Function
Public Shared Sub driver()
Dim t As New test1
Dim i As Integer
i = t.func1(i)
i = (New test1).func1(i) ' this compiles ok
t.sub1(i)
(New test1).sub1(i) ' syntax error on this line
End Sub
End Class
probably it's more clear if you write

i = (New test1).sub1(i) '

problem is that a sub does not produce a value, while a function does.

Seems a logic behavior.

T

Aug 3 '07 #2

P: n/a
Try adding the "Call" keyword on the left

Thus:
-------------------------------------------------------------
Call (New test1).sub1(i) ' syntax error on this line
-------------------------------------------------------------

--
Rory
Aug 3 '07 #3

P: n/a
"Rory Becker" <Ro********@newsgroup.nospamschrieb:
Try adding the "Call" keyword on the left

Thus:
-------------------------------------------------------------
Call (New test1).sub1(i) ' syntax error on this line
-------------------------------------------------------------
This will work and it's the only case in which 'Call' is still mandatory.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Aug 3 '07 #4

P: n/a
Thanks Rory and Herfried. I guess the call statement gives vb compiler
enough context to proceed.

Aug 4 '07 #5

P: n/a
I agree with all you have said, but you go beyond my original question which
was just about when a syntax error occurs at compile time.

Aug 4 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.