adsense


Thursday, 5 November 2015

VB SCRIPT DECLARING CONSTANTS PAGE 3

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button




VB SCRIPT DECLARING CONSTANTS






Declaring Constants 
Syntax 
[Public | Private] Const Constant_Name = Value 
The Constant can be of type Public or Private. The Use 
of Public or Private is Optional. The Public constants 
are available for all the scripts and procedures while 
the Private Constants are available within the procedure 
or Class. One can assign any value such as number, String 
or Date to the declared Constant. 
Example 1 
In this example, the value of pi is 3.4 and it displays 
the area of the circle in a message box. 
<!DOCTYPE html> 
<html> 
<body> 
<script language="vbscript" type="text/vbscript"> 
 
  Dim intRadius 
  intRadius = 20 
  const pi=3.14 
  Area = pi*intRadius*intRadius 
  Msgbox Area 
 
</script> 
</body> 
</html> 
 
 
 
Example 2 
The following example illustrates how to assign a String 
and Date Value to a Constant. 
<!DOCTYPE html> 
<html> 
<body> 
<script language="vbscript" type="text/vbscript"> 
 
  Const myString = "VBScript" 
  Const myDate = #01/01/2050# 
  Msgbox myString 
  Msgbox myDate 
</script> 
</body> 
</html> 
Example 3 
In the following example, the user tries to change the 
Constant Value; hence, it will end up with an Execution Error. 
<!DOCTYPE html> 
<html> 
<body> 
<script language="vbscript" type="text/vbscript"> 
   Dim intRadius 
   intRadius = 20 
   const pi=3.14 
   pi = pi*pi 'pi VALUE CANNOT BE CHANGED.THROWS ERROR' 
   Area = pi*intRadius*intRadius 
   Msgbox Area 
   </script> 
</body> 
</html> 


No comments: