473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

a vb syntax peculiarity

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
5 1085
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
Try adding the "Call" keyword on the left

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

--
Rory
Aug 3 '07 #3
"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
Thanks Rory and Herfried. I guess the call statement gives vb compiler
enough context to proceed.

Aug 4 '07 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
22
by: Tuang | last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss Army knife" tool. The longer I can remember the syntax for performing a task, the more likely I am to use it on the spot if...
14
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def...
3
by: Diez B. Roggisch | last post by:
Hi, I just wrote my first decorator example - and I already love them. However I've encountered one peculiarity that strikes me odd: When one writes a decorated function like this: ...
16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
5
by: GitarJake | last post by:
Hello all, Newbie here. SQL 2000, Windows 2000 I'm trying to alter tables in my SQL DB using statements like the following: /* AD_GROUPS */ alter table AD_GROUPS alter column...
23
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.