Home and Blog button

Pages

Introduction

Welcome To my Blog !!
This is a blog where you can get some knowledge that i have learned and been using. Sharing is gaining pals. So Happy Sharing and don't forget to follow and link my blog with yours! Thanks.
Happy Programming!!

Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Wednesday, July 22, 2009

Simple Calculator Using VBScript!

Simple Calculator Using VBScript!!



Update: June 25, 2012:


By default this program will run on the Internet Explorer Browser only. If you want to run in Firefox, you would want to add add-on to support VBScript. Since VBScript is Microsoft's Native Scripting language only IE will be able to execute it by default. I saw comments stating that it doesn't work. So guys try running in IE, it will work. Javascript is the scripting language that supports almost all browsers.

This is the Simple Calculator created by using the VBScript. Here, three functions are used to manipulate each buttons, clear all and to calculate the sum when the user creates the "Equal" button!! User interface is given below. Try out the following code to run the program!!






Source Code:
<html>
<head>
<title>A simple VBScript Calculator</title>
<script language = "VBscript">
Dim Novalue
Novalue = 0

Function Math(val)
If (Novalue = 1) Then
document.f.ans.value = ""
Novalue = 0
End If
document.f.ans.value=document.f.ans.value+val
End Function

Function equals()
document.f.ans.value=eval(document.f.ans.value)
Novalue = 1
End Function

Function Clear()
document.f.ans.value = ""
End Function
</script>
</head>
<body>
<form name ="f">
<center>
<BR>
<table width="184" height="180" border="2">
<tr>
<td colspan="4"><input name = "ans" type = "text" size="0"></td>
</tr>
<tr> <td width="41"><input type = "button" value = " 7 " name = "7" onclick = "Call Math('7')"></td>
<td width="41"><input type = "button" value = " 8 " name = "8" onclick = "Call Math('8')"></td>
<td width="41"><input type = "button" value = " 9 " name = "9" onclick = "Call Math('9')"></td>
<td width="41"><input type = "button" value = " / " name = "/" onclick = "Call Math('/')"></td>
</tr>
<tr> <td><input type = "button" value = " 4 " name = "4" onclick = "Call Math('4')"></td>
<td><input type = "button" value = " 5 " name = "5" onclick = "Call Math('5')"></td>
<td><input type = "button" value = " 6 " name = "6" onclick = "Call Math('6')"></td>
<td><input type = "button" value = " * " name = "*" onclick = "Call Math('*')"></td> </tr>
<tr> <td><input type = "button" value = " 1 " name = "1" onclick = "Call Math('1')"></td>
<td><input type = "button" value = " 2 " name = "2" onclick = "Call Math('2')"></td>
<td><input type = "button" value = " 3 " name = "3" onclick = "Call Math('3')"></td>
<td><input type = "button" value = " - " name = "-" onclick = "Call Math('-')"></td> </tr>
<tr>
<td colspan="3"><input type = "button" value = " + " name = "+" onclick = "Call Math('+')"></td>
<td rowspan="2"><input height="40" type = "button" value = " = " name = "=" onclick = "Call equals"></td>
</tr>
<tr>
<td height="28" colspan="3"><input name="button" type = "button" onclick = "Call Clear" value = " Clear All "></td>
</tr>
</table>
<br>
<br>
</center>
</form>
</body>
</html>

Tuesday, July 7, 2009

How to use Cookies in browsers using VBScript?

Do you love Cookies?

The cookie is a small amount of data which is given a name and stores by browser in the clients computer. It is associated with a webpage or website and it can be used to save states of the webpage. For Example:
  1. Saving user preferences.
  2. Recalling user preferences.
  3. Saving and recalling state information.
  4. Enables informations to be accessed by multiple web pages.
Cookies can be written or read by VBScripts, CGI scripts and javascript. Here given below is an example to save to and retrive the cookie from the browser's computer.

Saving Cookies to Eat!!

Write Cookie to Save: Display Saved Cookie:
Source Code:


<html> 
<head>
<title>vbscript - Save Cookies!</title>
<script language =vbscript> 
Sub bttnSave_OnClick() 
If not document.form1.txtcookie.value = "" Then 
document.cookie = document.form1.txtcookie.value 
msgbox("Cookies Saved Successfully!!") 
Else
msgbox("Write data first!") 
End If 
End Sub 

Sub bttnDisplay_OnClick() 
document.form1.txtres.value = document.cookie
End Sub

</script>
</head> 
<body> 

<form name="form1"> 
<b>Saving Cookies to Eat!!</b><br>
<hr> 
Write Cookie to Save:&nbsp <input type="text" name="txtcookie" value=""> <input type="button" name="bttnSave" value="Save Cookie"><br> 
Display Saved Cookie: <input type="text" name="txtres" value=""> <input type="button" name="bttnDisplay" value="Display Cookie"><br> <input type="Reset" name="Reset" value="Clear"><br> 
</form> 
</body> 
</html>

Wednesday, July 1, 2009

Use of Date function in VBscript!!

Checking validity of date and Using each date's day, month and year.











Source Code.


<html>
<head><title>vbscript - Check date!</title>
   <script language =vbscript>
   Dim StoredDate
   document.write("<b>Today's Date is: " & Date & "</b><hr>")
   Sub bttnconvert_OnClick()
   If Not IsDate(document.form1.txtdate.value) Then
   msgbox("Invalid Date!!")
   document.form1.txtdate.value = ""
   else
   StoredDate = document.form1.txtdate.value
   document.form1.txtres.value = day(StoredDate) & "-" & month(storeddate)    & "-" & year(storeddate)
   End if
   End Sub
   </script>
</head>
<body>
<form name="form1">
<input type="text" name="txtdate" value="">
<input type="button" name="bttnConvert" value="Convert Date Format"><br>
<input type="text" name="txtres" value="">
<input type="Reset" name="Reset" value="Clear"><br>
</form>
</body>
</html>

Saturday, June 27, 2009

How to use Elements array in VBScript!


The concept of the elements array in the VBScript!!!


Objective Question Answers!!



1. Result of 2+2 is:

4 5 6 10

2. Who is father of computer?

Mr. Rajan Charles Babbage Charles Darwin Charles Angels

3. What is DML?

Do More Language Data Mining Language Develop Money Land Data Manipulation langauage

Source Code:
<html>
<head><title>Use of VBScript</title>
<link rel="stylesheet" href="mystyle.css">

<script language="vbscript">
sub scoreclick()
dim score
if (form1.elements(0).checked = true) then
score = score + 5
end if
if (form1.elements(5).checked = true) then
score = score + 5
end if
if (form1.elements(11).checked = true) then
score = score + 5
end if
msgbox ("Your score is:" & score)
end sub
</script>
</head>

<body>
<form name="form1">
<p class="question">1. Result of 2+2 is:</p>
<p class="answer">
<input type="radio" name="q1" >4
<input type="radio" name="q1" >5
<input type="radio" name="q1" >6
<input type="radio" name="q1" >10
</p>
<p class="question">2. Who is father of computer?</p>
<p class="answer">
<input type="radio" name="q2" >Mr. Rajan&nbsp&nbsp
<input type="radio" name="q2" >Charles Babbage &nbsp&nbsp
<input type="radio" name="q2" >Charles Darwin&nbsp&nbsp
<input type="radio" name="q2" >Charles Angels
</p>
<p class="question">3. What is DML?</p>
<p class="answer">
<input type="radio" name="q3" >Do More Language&nbsp&nbsp
<input type="radio" name="q3" >Data Mining Language&nbsp&nbsp
<input type="radio" name="q3" >Develop Money Land&nbsp&nbsp
<input type="radio" name="q3" >Data Manipulation langauage
</p>
<input type="button" name="bttncalc" value="Show Score" onclick=scoreclick()>
<input type="Reset" name="reset" value="Reset">
</form>
</body>
</html>

Thursday, June 18, 2009

How to find Largest Number in VBScript?

This is the simple vbscript program which is will find the largest number from the given three inputs. Here the use of if...then..elseif...else statement is used. Hope you will learn and feel it easy!!

Find Largest Number!!


The user interface goes like below:

First No:
Second No:
Third No:
Result:


Source Code :

<html>

<head><title>Find Largest Number using vbscript!</title>

<script language="vbscript">
          sub large_no()
             dim a, b, c, res
             res = 0
             a=cint(document.vbtest.txt1.value)
             b=cint(document.vbtest.txt2.value)
             c=cint(document.vbtest.txt3.value)
             if (a>b) And (a>c) then
                res= a
             elseif (b>a) And (b>c) then
                res = b
             else
                res = c
             end if
             document.vbtest.txtres.value = res
          End sub
</script>
</head>
<body>
<form name="vbtest">
<h2> Find Largest Number!! </h2> <hr>
First No:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="txt1"><br>
Second No:<input type="text" name="txt2"><br>
Third No:&nbsp&nbsp&nbsp<input type="text" name="txt3"><br>
Result:&nbsp;&nbsp;&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="txtres"><br><br>
<input type="button" name="bttncalc" value="Show Result" onclick="large_no()">
<input type="Reset" name="reset" value="Reset"><br>
</form>
<hr>
</body>
</html>

Tuesday, June 16, 2009

What is VBscript, Script?

Brief Introduction to VBScript!

  1. Vbscript is the scripting language.
  2. Scripting languages are such type of programming languages which is used to provide control in another host enviroment.
  3. Scripting Languages are interpreted not compiled. They can be embedded to the <head>..</head> section or the <body>..</body> section of the html tags.
  4. <head>..</head> section is prefered one because the head section gets interpreted first than the <body>..</body> section.Vbscript is the client-sided scripting languages which is the light version of VB and default scripting language of ASP.
  5. If you are the good vb programmer then you will not have difficulties in using the vbscript language in your web page.
Sample Vbscript Program:

<html>
   <head>
      <title> Title of Your page!</title>
      <script language = "vbscript">
         Sub welcome()
            Dim String
            String = "Hello"
            String = String & " world!"
            document.write(String)
         End Sub
      </script>
   </head>
   <body onload=welcome()>
      <h3>Use of vbscript in webpage! </h3>
   </body>
</html>

Search This Blog