Curious about VB.Net Syntax

T

tshad

I was curious if there is some reason why you don't need the "then" in the
if test of VB.Net or is it just ASP.NET.

I just noticed that I don't really need to explicitly put the word "then" as
part of my if statement.

For example:

if a = b
b= 10
end if

works just as well as

if a = b then
b = 10
end if.

That used to give an error.

Is there some reason this has changed? I haven't seen it mentioned anywhere
before.

Just curious.

Thanks,

Tom
 
M

Marina

Probably became optional because it wasn't necessary for the parser. VB is
so verbose as is, I guess they figured no need to make it required.
 
S

Steve C. Orr [MVP, MCSD]

"Then" is indeed required for VB.NET in Visual Studio 2003.
Are you using something else? If so, what?
 
T

tshad

Steve C. Orr said:
"Then" is indeed required for VB.NET in Visual Studio 2003.
Are you using something else? If so, what?

It might be in VB.Net and Visual Studio 2003, but if you leave it out in
your asp.net pages (in my case I am using DW) that is not created by VS, it
works fine.

I assume that VS will catch it when trying to compile it, but ASP.Net
apparently lets it go through and knows that there is supposed to be a
"Then" there.

I was curious if it was a VB.Net or ASP.Net anomaly (and why). Apparently,
it is an ASP.NET anomaly.

Tom
 
T

tshad

David Anton said:
The "Then" is indeed entirely optional, whether you're coding in ASP.NET
or
not.

My question would be - why?

I really don't care whether they have the "then" there or not. I am
confused as to why they wouldn't just leave it as VB always was, instead of
starting to change things that don't need to be changed. I do like some of
the changes, I am just confused as to the logic of having either way.

Tom
 
G

Guest

Having an excessive number of alternatives is one of the hallmarks of VB.

For example:
1. Two radically different ways of wiring event handlers.
2. Numerous styles of declaring and initializing arrays (too many to list
here).
3. Two radically different ways of setting function return values
(assignment to function name or via the return statement).
4. Two radically different ways of handling exceptions.
5. "Case" in "Select Case" is optional.
6. "ByVal" is optional (i.e., parameters are ByVal if the modifier is
omitted).

and this is just off the top of my head...

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter
 
K

Kevin Spencer

My question would be - why?
I really don't care whether they have the "then" there or not. I am
confused as to why they wouldn't just leave it as VB always was, instead
of starting to change things that don't need to be changed. I do like
some of the changes, I am just confused as to the logic of having either
way.

Solution to your confusion: Pretend you never heard of any changes, and code
like you're used to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top