'Then' is Optional?!?

M

Mike Labosh

VS.NET 2003, ASP.NET Project with Option Strict turned ON.

(yes, I know this is not the aspnet group. This is a VB syntax thing, not
an ASP.NET thing)

This actually compiles without the "Then" keyword. What gives?!?

If Not Page.IsPostBack

End If

--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 
M

m.posseth

Mike

Look again ,,, and surprise there is your then


however there it was in my situation as soon as i leave the page and return
or even when i jump to another part in the same class VB adds the Then
statement automaticly

so that is what is happening


Regards

Michel Posseth [MCP]
 
H

Herfried K. Wagner [MVP]

Mike Labosh said:
VS.NET 2003, ASP.NET Project with Option Strict turned ON.

(yes, I know this is not the aspnet group. This is a VB syntax thing, not
an ASP.NET thing)

This actually compiles without the "Then" keyword. What gives?!?

If Not Page.IsPostBack

End If

If this was really the case I'd consider it a compiler bug ;-).
 
M

Marina

Yes, I think it is optional, though as was pointed out by Mike, the IDE will
put it in for you many times.

Why is this a big deal? It's not like 'Then' is really adding any syntactic
meaning. C# and other languages have if statements without a 'then' just
fine. Isn't VB verbose enough as is?
 
H

Herfried K. Wagner [MVP]

Sorry, I mixed something up. 'Then' is optional for the block 'If'
statement.
 
M

Mike Labosh

Look again ,,, and surprise there is your then
however there it was in my situation as soon as i leave the page and
return or even when i jump to another part in the same class VB adds the
Then statement automaticly

Apparently not, because here's the procedure after several edits, saves,
builds and runs.

Protected Overrides Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load

MyBase.Page_Load(sender, e)

If Not Page.IsPostBack

Dim ssKey As Integer = Convert.ToInt32(Request.QueryString("ssKey"))

lblHeader.Text = "Reviewing countries in Sample Source " &
ssKey.ToString()

End If

End Sub

--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 
M

Mike Labosh

Why is this a big deal? It's not like 'Then' is really adding any
syntactic meaning. C# and other languages have if statements without a
'then' just fine. Isn't VB verbose enough as is?

Oh, I'm certainly not complaining about that. :) It's just that I've never
seen any flavor of VB behave like this until today.
--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 
M

Mike Labosh

If Not Page.IsPostBack

Woah! I missed this the first time I checked the help topics. The MSDN
topic for the "If Statement Visual Basic Language Reference" says this:

"If Then is absent, it must be the beginning of a multiple-line
If...Then...Else."

I guess when in doubt, RTFM *closely* :)

--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 
M

Mike Labosh

Sorry, I mixed something up. 'Then' is optional for the block 'If'
statement.

Yep, I just found the one-liner that says so, buried below manu paragraphs.
How bizarre.

--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 
C

Cor Ligthert [MVP]

Ken,
Sound like you want C# >then< <g>

No I want a tool that is better than C# and can be a tool for the future.

The Visual Basic language has in my idea a prominence position to become
that.

A pity is that some classic VB diehards want to keep all kind of things that
has no sense and therefore makes that it looks like an outdated tool.

:)

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
No I want a tool that is better than C# and can be a tool for the future.

The Visual Basic language has in my idea a prominence position to become
that.

A pity is that some classic VB diehards want to keep all kind of things
that has no sense and therefore makes that it looks like an outdated tool.

'Dim' and 'Then' make perfectly sense, IMO, especially 'Dim'. I would not
want to miss them.
 
C

Cor Ligthert [MVP]

"Herfried K. Wagner [MVP]"


Yes I know the same as that the C# guys want to see that a delclaration
always ends with (); do you want to see that it always begins with DIM
inside a method.

\\\
Public sub b()
Dim c as string 'here is for you (not for the compiler) the Dim absolut
needed.
d as string 'for me this is obvious a declaration of a string
End sub
///

Strange is that you don't want this one to keep in consequent in the
language.
\\\
Public sub b()
for dim i as integer = 0 to etc.
End sub
///
It is now very inconsequent, although I would hate it to see as it is above.

Cor
 
P

Paul Clement

¤ Ken,
¤
¤ > Sound like you want C# >then< <g>
¤
¤ No I want a tool that is better than C# and can be a tool for the future.
¤

You already have one...or you wouldn't be using it. ;-)

¤ The Visual Basic language has in my idea a prominence position to become
¤ that.

Already there. Why reduce readability by removing keywords?

Are you certain you're not a C# developer? ;-)

¤
¤ A pity is that some classic VB diehards want to keep all kind of things that
¤ has no sense and therefore makes that it looks like an outdated tool.
¤

No, many of us just want to retain the keywords that differentiate Visual Basic from less verbose
(and less code readable) programming languages.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
C

Cor Ligthert [MVP]

Paul,
No, many of us just want to retain the keywords that differentiate Visual
Basic from less verbose
(and less code readable) programming languages.

See as well my samples in the message to Herfried, for me the "Dim" (not
even the "then" about that we can discuss), makes in my opinion the language
more unreadable for new users. It has absolute not the meaning more what it
had in the "BASIC" time, and therefore will look the same for newbies in the
language as

\\\
Public sub
Kzp MyVariable as String
end sub .
///
This makes it for me not more readable.

I am absolute not talking about the keywords declaring the scope, however
beside the "Static" are those not needed inside a method.

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
See as well my samples in the message to Herfried, for me the "Dim" (not
even the "then" about that we can discuss), makes in my opinion the
language more unreadable for new users. It has absolute not the meaning
more what it had in the "BASIC" time, and therefore will look the same for
newbies in the language as

\\\
Public sub
Kzp MyVariable as String
end sub .
///
This makes it for me not more readable.

As you already know for sure, 'Dim' is simply an abbreviation of
"dimension". 'ReDim' stands for "redimension". Both keywords make perfect
sense and they are more than just some useless characters. Visual Basic
..NET doesn't have special blocks to put declarations of local variables in.
Thus it's important to be able to identify variable declarations easily. I
usually do not put all declarations of local variables at the beginning of a
method's body. Instead, I spread them throughout a method in front of the
line where the variable is being used for the first time. The blue 'Dim'
keyword is very important for me to identify variable declarations.
 
M

m.posseth

Cor,


BASIC

Beginner's All-purpose Symbolic Instruction Code,

symbolic stands in this context as far as i know for a way to define the
abstract

in my opinion C like syntaxes are abstract by themselves ,,, what you want
is to evolve the language to a more abstract language


or am i going to deep here :)

Michel ,
 

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

Top