IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesVB.NetLanguage Basics  Print This     

Cross Ref > Language Basics

By Mike Prestwood

VB.Net versus ASP Classic: A side by side comparison between VB.Net and ASP Classic.

 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Case Sensitivity

[Other Languages] 

Languages Focus

Case sensitiviy in this case is referring to commands and variable names. For example, are "printf" and "PrintF" equivalent? Are fullname and FullName equivalent? When you create commands, operations, methods, or variables should you worry about case?

VB.Net:   No

VB.Net is not case sensitive. If you type any other case for commands or variables, VB.Net will change it to the accepted or defined case. For example, if you type messagebox.show it is converted to MessageBox.Show.

Syntax Example:  

The following code works:

MessageBox.Show("hello")
ASP Classic:   No

ASP Classic is not case sensitive. My preference for all languages where case sensitivity does not matter is to use camel caps as in the first example above. Many developers coming from a case sensitive language prefer to use all lowercase.

Syntax Example:  

You can use any of the following:

Response.Write "Hello"
response.write "Hello"
RESPONSE.WRITE "Hello"
REsponse.WritE "Hello"




Code Blocks

[Other Languages] 

Languages Focus

The rules for code blocks within a language dictate where you can declare variables, how you "bracket" code, etc.

VB.Net:   End Xxx

VB.Net, like VB Classic code blocks, are surrounded by statement ending keywords that all use End such as End Class, End Sub, End Function, and End If.

Syntax Example:
Public Class Dog
End Class
 
Protected Sub MySub
End Sub
  
Public Shared Function MySharedFunction() As Integer
MySharedFunction = 12345
End Function
 
If x Then
End If
ASP Classic:   End Xxx

In .ASP html pages, you embed ASP code between <% and %>.

ASP Classic code blocks are surrounded by statement ending keywords that all use End such as End Sub, End If, and WEnd.

Syntax Example:
<%
Sub x
End Sub
 
If x Then
End If
 
While x
WEnd
%>




Comments

[Other Languages] 

Languages Focus

Commenting code generally has three purposes: to document your code, for psuedo coding prior to coding, and to embed compiler directives. Most languages support both a single line comment and a multiple line comment. Some languages also use comments to give instructions to the compiler or interpreter.

VB.Net:   ' or REM

Commenting Code
VB.Net, like all the VB-based languages, uses a single quote (') or the original class-style basic "REM" (most developers just use a quote). VB.Net does NOT have a multiple line comment.

Syntax Example:
'Single line comment.

REM Old school single line comment.

 


ASP Classic:   ' or REM

Commenting Code
ASP Classic, like all the VB-based languages, uses a single quote (') or the original class-style basic "REM" (most developers just use a quote). ASP Classic does NOT have a multiple line comment.

Preprocessor Directives - @ and #
An @ is used for preprocessor directives within ASP code (within <% %>) and a # is used for HTML-style preprocessor directives.

Note: ASP Classic does not support VB Classic's #If directive.

Syntax Example:
'Single line comment.
REM Old school single line comment.

 

Common Preprocessor Directives include:

<%@LANGUAGE=VBScript%>
<!-- #Include File="includes.inc" -->




Constants

[Other Languages] 

General Info: Computer Language Constants

A constant is just like a variable (it holds a value) but, unlike a variable, you cannot change the value of a constant.

VB.Net:   Const kPI Double = 3.1459

In VB.Net, you define constants with the Const keyword.

All constants are part of a class (no global constants) but you can make a constant public and have access to it using ClassName.ConstantName so long as you have added the class to the project. This works even without creating the class as if the public constants were static, but you cannot use the Shared keyword.

Constants must be of an integral type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, or string), an enumeration, or a reference to null.

Syntax Example:
Public Class Convert
Inherits System.Object
 
  Public Const kName As String = "Mike"
  Private Const kPI Double = 3.1459
 
  //Declare two or more on same line too:
Const kFeetToMeter = 3.2808, kMeterToFeet = 0.3048
End Class
ASP Classic:   Const kPI = 3.1459

Scope can be Public or Private. Public Const is the same as just specifying Const. As with variables, all constants are variants. You do not specify the type, it's implied.

Syntax Example:
Const kPI = 3.1459
Const kName = "Mike"
 
//Public variable:
Public Const kFeetToMeter=3.28, kMeterToFeet=.3




End of Statement

[Other Languages] 

Languages Focus

In coding languages, common End of statement specifiers include a semicolon and return (others exist too). Also of concern when studying a language is can you put two statements on a single code line and can you break a single statement into two or more code lines.

VB.Net:   Return

A return marks the end of a statement and you cannot combine statements on a single line of code. You can break a single statement into two or more code lines by using a space and underscore " _".

Syntax Example:  
Console.WriteLine("Hello1")
Console.WriteLine("Hello2")
Console.WriteLine("Hello3")

'The following commented code
'on a single line does not work...
'Console.WriteLine("Hello4") Console.WriteLine("Hello5")

'Two or more lines works too with a space+underscore:
Console.WriteLine _
"Hello6";
ASP Classic:   Return

A return marks the end of a statement and you cannot combine statements on a single line of code. You can break a single statement into two or more code lines by using a space and underscore " _".

Syntax Example:
Response.Write("Hello1")
Response.Write("Hello2")
Response.Write("Hello3")

'The following commented code on a single line does not work...
' Response.Write("Hello4") Response.Write("Hello5")

'Two or more lines works too with a space+underscore:
Response.Write _
("Hello6")




Literals

[Other Languages] 

General Info: Programming Literals

A value directly written into the source code of a computer program (as opposed to an identifier like a variable or constant). Literals cannot be changed. Common types of literals include string literals, floating point literals, integer literals, and hexidemal literals. Literal strings are usually either quoted (") or use an apostrophe (') which is often referred to as a single quote. Sometimes quotes are inaccurately referred to as double quotes.

Languages Focus

In addition to understanding whether to use a quote or apostrophe for string literals, you also want to know how to specify and work with other types of literals including floating point literals. Some compilers allow leading and trailing decimals (.1 + .1), while some require a leading or trailing 0 as in (0.1 + 0.1). Also, because floating point literals are difficult for compilers to represent accurately, you need to understand how the compiler handles them and how to use rounding and trimming commands correctly for the nature of the project your are coding.

VB.Net:   quote

String literals are quoted as in "Prestwood". If you need to embed a quote use two quotes in a row.

To specify a floating point literal between 1 and -1, preceed the decimal with a 0. If you don't, the compiler will auto-correct your code and place a leading 0. It will change .1 to 0.1 automatically. Trailing decimals are not allowed.

Syntax Example:  
Console.WriteLine("Hello")
Console.WriteLine("Hello ""Mike"".")
  
'Does VB.Net evaluate this simple
'floating point math correctly? No! 
If (.1 + .1 + .1) = 0.3 Then
MsgBox "Correct"
Else
MsgBox "Not correct"
End If
ASP Classic:   quote

String literals are quoted as in "Prestwood". If you need to embed a quote use two quotes in a row.

To specify a floating point literal between 1 and -1, you can preceed the decimal with a 0 or not (both work). In other words, preceding and following decimals are allowed (both .1 and 0.1). Trailing decimals are also allowed (1, 1., and 1.0 are all equivalent and allowed).

Syntax Example:
Response.Write "Hello"
Response.Write "Hello ""Mike""."
  
'Does ASP evaluate this simple
'floating point math correctly? No! 
If (.1 + .1 + .1) = .3 Then
 Response.Write "Correct"
Else
 Response.Write "Not correct"
End If




Variables

[Other Languages] 

Languages Focus

A variable holds a value that you can use and change throughout your code so long as the variable is within scope. With variable declaration, you not only want to know the syntax of how you declare a variable but you also want to know where. Are you allowed to declare a variable inline? What are the available scopes: local vs. global. Can you assign a value at the same time you declare a variable?

VB.Net:   Dim x As Integer=0

Variables are case sensitive but VS.Net will auto-fix your variable names to the defined case. You can declare variables in-line wherever you need them and declarative variable assignment is supported.

Syntax Example:  

Dim FullName As String

Dim Age As Integer

Dim Weight As Double

FullName = "Mike Prestwood"

Age = 32

Weight = 154.4

'Declaritive variable assignment:

Dim Married As String = "Y"

MsgBox(Married)

ASP Classic:   Dim x

ASP Classic is a loosely typed language. No variable types in ASP (all variables are variants). Declaring variables is even optional unless you use the Option Explicit statement to force explicit declaration of all variables with Dim in that script. Using Option Explicit is strongly recommended to avoid incorrectly typing an existing variable and to avoid any confusion about variable scope.

For example, at the top of my common include file, I have the following:

<%@LANGUAGE=VBScript%>
<%
Option Explicit
'...more code here.
%>
Syntax Example:
Dim Fullname
Dim Age
Dim Weight
 
FullName = "Mike Prestwood"
Age = 32
Weight = 154.4
 
'Declaritive assignment not supported:
''Dim Married = "Y"   '>>>Not supported.




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]