Sie sind auf Seite 1von 27

October 2004

Solution:
Note: Draw the form layout (if not given in paper), before writing the solution.

Info.html (a)(with validation)


<html>
<head><title> Information </title>
<script language="vbscript">
Function check()
dim name
dim l,i
name=f1.t1.value
l=len(name)
for i=1 to l
if isnumeric(mid(name,i,1))=true then
document.write "Enter valid name"
exit for
end if
next
end Function
</script></head>
<body>
<form name="f1" method="post" action="thank.asp" onsubmit="check()">
Name: <input type=text name=t1><br>
Address: <input type=text name=t2><br>
<!-- fieldset and legend are not compulsory, you can directly give radio buttons -->
<fieldset>
<legend> Computer Configuration</legend>
<input type=radio name="r1" value="p4" checked>Pentium-IV<br>
<input type=radio name="r1" value="p3">Pentium-III<br>
<input type=radio name="r1" value="c">Celeron
</fieldset><br>
<fieldset>
<legend> Computer Usage</legend>
<input type=checkbox name="c1" value="office">At Office<br>
<input type=checkbox name="c2" value="home">At Home<br>
<input type=checkbox name="c3" value="cyber">Cyber Cafe<br>
<input type=checkbox name="c4" value="other">Other
</fieldset><br>
Comments:<textarea rows="4" cols="10" name="ta"></textarea><br>
<input type=checkbox name="c5" value="mail">Add to mailing list<br><br>
<input type="submit" value="Submit"> &nbsp;&nbsp; <input type="reset" value="Reset">
</form>
</body>
</html>

Thank.asp
<%@ language=vbscript %>
<html>
<head>
<title>Inserting Information </title>
<%
dim c1,c2,c3,c4
response.write "<h4> Thank you for the information.</h4>"
response.write "<b>Name:</b> " & request.form("t1") & "<br>"
response.write "<b>Address: </b>" & request.form("t2") & "<br>"
if request.form("r1")="p4" then
response.write "<b>Computer Configuration:</b> Pentium IV" & "<br>"
elseif request.form("r1")="p3" then
response.write "<b>Computer Configuration:</b> Pentium III" & "<br>"
else
response.write "<b>Computer Configuration:</b> Celeron" & "<br>"
end if
if request.form("c1")="office" then
c1="At Office"
end if
if request.form("c2")="home" then
c2="At Home"
end if
if request.form("c3")="cyber" then
c3="Cyber Cafe"
end if
if request.form("c4")="other" then
c4="Other"
end if
response.write "<b>Computer Usage:</b>" & c1 & " " & c2 & " " & c3 & " " & c4 & "<br>"
response.write "<b>Comments:</b> " & request.form("ta") & "<br>"
if request.form("c5")="mail" then
response.write "<b>You have been added to the mailing list</b>"
end if
%>
</head>
<body>
</body>
</html>
Solution:
Note: Draw the form layout (if not given in paper), before writing the solution.

SurveyLab.html
<html>
<head>
<title> Survey Information for Computer Laboratory </title>
</head>
<body>
<form name="f1" method="post" action="insertVote.asp">
1. Ambience<br>
<input type="radio" name="r1">Not Satisfactory &nbsp;
<input type="radio" name="r1">Satisfactory &nbsp;
<input type="radio" name="r1">Good &nbsp;
<input type="radio" name="r1">Excellent<br><br>

2. Computers<br>
<input type="radio" name="r2">Not Satisfactory &nbsp;
<input type="radio" name="r2">Satisfactory &nbsp;
<input type="radio" name="r2">Good &nbsp;
<input type="radio" name="r2">Excellent <br><br>

3. Network<br>
<input type="radio" name="r3">Not Satisfactory &nbsp;
<input type="radio" name="r3">Satisfactory &nbsp;
<input type="radio" name="r3">Good &nbsp;
<input type="radio" name="r3">Excellent<br><br>

4. Air-Conditioner<br>
<input type="radio" name="r4">Not Satisfactory &nbsp;
<input type="radio" name="r4">Satisfactory &nbsp;
<input type="radio" name="r4">Good &nbsp;
<input type="radio" name="r4">Excellent<br><br>
<input type="submit" value="Save Vote"> &nbsp; &nbsp;
<input type="reset" value="Clear Vote">
</form>
</body>
</html>

insertVote.asp
<% @language=vbscript %>
<html>
<head><title>Inserting Vote</title></head>
<body>
<%
dim cn
set cn=server.createobject("Adodb.Connection")
cn.open "dsn=boardSolution"
dim rs
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "surveyLab",cn,2,3
if request.form("r1")<>"" then
rs(1)=rs(1)+1
rs.update
rs.movenext
end if

if request.form("r2")<>"" then
rs(1)=rs(1)+1
rs.update
rs.movenext
end if

if request.form("r3")<>"" then
rs(1)=rs(1)+1
rs.update
rs.movenext
end if

if request.form("r4")<>"" then
rs(1)=rs(1)+1
rs.update
rs.movefirst
end if

response.write "Thank You for participating in the opinion poll<br><br><br>"


response.write "Number of votes for each criteria are: <br>"

do until rs.eof
response.write rs.fields(0) & " : " & rs(1) & "<br>"
rs.movenext
loop
rs.close
cn.close
%>
</body>
</html>
Solution
Login.html
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form name="f1" method="post" action="CheckUser.asp">
User ID <input type="text" name="t1"><br>
Password <input type="password" name="p1"><br>
<input type=”submit” value="Submit"> &nbsp;&nbsp; <input type="reset" value="Reset">
</form>
</body>
</html>

CheckUser.asp
<% @language=vbscript %>
<html>
<head>
<title>Check User</title>
</head>
<body>
<%
dim cn
set cn=server.createObject("ADODB.Connection")
cn.open "dsn=boardSolution"

dim sqlq
sqlq="select* from User"

dim rs
set rs=server.createObject("ADODB.Recordset")
rs.open sqlq,cn

if rs(0)=request.form("t1") and rs(1)=request.form("p1") then


response.redirect "Welcome.asp?user=" & request.form("t1")
else
response.redirect "Wrong.html"
end if
%>
</body>
</html>

Welcome.asp
<% @language=vbscript %>
<html>
<head>
<title>Welcome User</title>
</head>
<body>
<%
response.write "Welcome " & request.querystring("user")
%>
</body>
</html>

Wrong.html
<html>
<head>
<title>Wrong User</title>
</head>
<body>
Sorry !!! User and/or Password incorrect. Please try again!
</body>
</html>

October 2005
Q.1 (d) Write a VbScript Function to accept a number. Display it in reverse order. (5)

Solution:

Reverse.html
<html>
<head>
<title>Reversing the Number</title>
<script language="vbscript">
dim num,rm,rnum
rnum=0
num=int(inputbox("Enter a number:"))
do while num>0
rm=num mod 10
rnum=(rnum*10)+rm
num=int(num/10)
loop
document.write "Reverse of the number is: " & rnum
</script>
</head>
<body>
</body>
</html>

Q.3 (d) Write a vbscript code to count and display the number of words in the input. (5)
Input: This junk line contains no data at all
Output: 8

Solution:

CountWords.html
<html>
<head><title>Count No. of Words</title>
<script language="vbscript">
sub mysub()
dim str
dim i,word
word=1
str=trim(f1.t1.value)
for i=1 to len(str)
if mid(str,i,1)=" " and mid(str,i+1,1)<>" " then
word=word+1
end if
next
f1.t2.value=word
end sub
</script></head>
<body>
<form name="f1">
Input: <input type="text" name="t1"><br>
Output: <input type="text" name="t2" readonly><br>
<input type="button" value="Count" onclick="mysub()">
</form>
</body>
</html>

Q.5

Solution:

Triangle.html
<html>
<head>
<title>Triangle</title>
<script language="vbscript">
sub check()
dim s1,s2,s3
s1=int(f1.t1.value)
s2=int(f1.t2.value)
s3=int(f1.t3.value)
if (s1+s2)>s3 and (s2+s3)>s1 and (s1+s3)>s2 then
if (s1*s1)+(s2*s2)=(s3*s3) or (s3*s3)+(s2*s2)=(s1*s1) or

(s1*s1)+(s3*s3)=(s2*s2) then
msgbox "It is a right-angled traingle"
elseif s1=s2 and s2=s3 and s1=s3 then
msgbox "It is an equilateral triangle"
elseif s1=s2 or s2=s3 or s1=s3 then
msgbox "It is an isosceles triangle"
end if
else
msgbox "Invalid Triangle"
end if
end sub
</script>
</head>
<body>
<form name="f1" method="post">
<fieldset>
<legend>Triangle Information</legend>
Side1 <input type="text" name="t1"><br>
Side2 <input type="text" name="t2"><br>
Side3 <input type="text" name="t3"><br>
<input type="submit" value="Check" onclick="check()">
</form>
</body>
</html>

Q.6

Solution:

Links.html
<html>
<head><title>Links Page</title></head>
<body>
<a href=CountryChoice.asp?countrychoice=1>USA</a> <br>
<a href=CountryChoice.asp?countrychoice=2>UK</a>
</body>
</html>

CountryChoice.asp
<% @language=vbs %>
<html>
<head><title>CountryChoice Page</title></head>
<body>
<%
if request.querystring("countrychoice")=1 then
response.write "i know you like USA"
else
response.write "i know you like UK"
end if
%>
</body>
</html>

Solution:

Bill.html
<html>
<head><title>Input Bill information</title>
<script language=vbs>
function check()
if trim(f1.t1.value)<>"" and trim(f1.t2.value)<>"" then
if isnumeric(f1.t1.value)=true and isnumeric(f1.t1.value)=true then
msgbox "valid data"
else
document.write "enter numeric data only"
end if
else
document.write "enter data"
end if
end function
</script></head>
<body>
<form name="f1" method="post" action="Check.asp" onsubmit="check()">
Enter bill no. : <input type="text" name="t1"><br>
Enter ProductId : <input type="text" name="t2"><br>
<input type="submit" value="Submit" accesskey="S">
</form>
</body>
</html>

Check.asp
<% @language=vbscript %>
<html><head><title>Code for checking</title></head>
</body>
<%
Dim cn, rs, sqlq
set cn=server.createObject("ADODB.Connection")
cn.open "dsn=BillingDetail"
set rs=server.createObject("ADODB.Recordset")
sqlq="select * from bill where bill_no="&request.form("t1")& " and product_id="&
request.form("t2")
rs.open sqlq,cn,2,3
if rs.eof then
response.write "record doesnt exist"
else
response.write "record exists"

%>
<form name="f2" method="post" action="delete.asp">
Bill no. <input type="text" name="t3" value="<%=request.form("t1")%>"><br>
Product Id: <input type="text" name="t4" value="<%=request.form("t2")%>"><br
Product name:<input type="text" name="t5" value="<%=rs("product_name")%>"><br>
Cost: <input type="text" name="t6" value="<%=rs("cost")%>"><br>
Quantity: <input type="text" name="t7" value="<%=rs("quantity")%>"><br>
<input type="submit" value="Delete">
</form>
<%end if%>
</body>
</html>

Delete.asp
<% @language=vbscript %>
<html><head><title>Delete the record</title></head>
<body>
<%
Dim cn, rs, sqlq
set cn=server.createObject("ADODB.Connection")
cn.open "dsn=BillingDetail"
sqlq="delete from bill where bill_no=" & request.form("t3")
cn.execute sqlq
response.write "record deleted successfully"
%>
</body>
</html>
May 2005
Q.4
Solution:

CorrectPath.asp
<% @ language=vbscript %>
<html><head> <title>correct.asp</title> </head>
<body>
<a href="link.asp?x=1">Click here to link</a>
</body>
</html>

FaultyPath.asp
<% @language=vbscript %>
<html><head><title>faulty.asp</title></head>
<body>
<a href="link.asp?x=2">Click here to link</a>
</body>
</html>

Link.asp
<% @language=vbscript %>
<html><head><title>linkpath.asp</title></head>
<body>
<%
if request.querystring("x")=1 then
response.write "<h1>Welcome " & request.servervariables("http_User_Agent")
else
response.write "<h1>Plz. come from correct path</h1>"
end if
%>
</body>
</html>

Solution:

Info.html
<html>
<head><title>1st question</title>
<script language=vbscript>
function check()
if isnumeric(f1.t1.value)=true or isnumeric(f1.t2.value)=true or isnumeric(f1.t3.value)=false or
isnumeric(f1.t4.value)=false or isnumeric(f1.t5.value)=false or isnumeric(f1.t6.value)=false or
isnumeric(f1.t7.value)=false then
document.write("enter valid marks")
end if
end function
</script></head>
<body>
<form name="f1" method="post" action="insert.asp" onsubmit="check()">
<table border="1">
<tr>
<th>rollno</th>
<td><input type="text" name="t1"></td>
</tr>
<tr>
<th>Name</th>
<td><input type="text" name="t2"></td>
</tr>
<tr>
<th>IS</th>
<td><input type="text" name="t3"></td>
</tr>
<tr>
<th>VB</th>
<td><input type="text" name="t4"></td>
</tr>
<tr>
<th>SQL2</th>
<td><input type="text" name="t5"></td>
</tr>
<tr>
<th>WEB</th>
<td><input type="text" name="t6"></td>
</tr>
<tr>
<th>ELECTIVE2</th>
<td><input type="text" name="t7"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Save"></td>
</tr>
</table>
</form>
</body>
</html>

Insert.asp
<html>
<head><title>Insert Data</title></head>
<body>
<%
dim cn
set cn=server.createobject("ADODB.connection")
cn.open "dsn=finalmarks"
name=request.form("t2")
rollno=request.form("t1")
is1=int(request.form("t3"))
vb=int(request.form("t4"))
sql2=int(request.form("t5"))
web=int(request.form("t6"))
elective2=int(request.form("t7"))
total=is1+vb+sql2+web+elective2
dim sqlq
sqlq="insert into final(rollno,name1,is,vb,sql2,web,elective2,total) values('" & rollno & "','" & name & "',"
& is1 & "," & vb & "," & sql2 & "," & web & "," & elective2 & "," & total & ")"
cn.execute sqlq
cn.close
response.write" successful insertion"
%>
</body>
</html>

Select.asp
<html>
<head><title>Display Data</title></head>
<body>
<%
dim cn
set cn=server.createObject("ADODB.Connection")
cn.open "dsn=finalmarks"
dim sqlq
sqlq="select * from final order by total desc"
dim rs
set rs=server.createObject("ADODB.Recordset")
rs.open sq,cn
%>
<table border=2>
<tr>
<%for i=0 to rs.fields.count-1%>
<th><%=rs.fields(i).name%></th>
<%next%>
</tr>
<% do until rs.eof %>
<tr>
<%for i=0 to rs.fields.count-1%>
<td><%=rs.fields(i)%> </td>
<%next%>
</tr>
<%rs.movenext%>
<%loop%>
</table>
</body>
</html>

Q.7
Solution:
Note: Draw the form layout (if not given in paper), before writing the solution. Also mention the
table’s name and its fields. For example, in the following code we are using table structure as
follows: Survey(Email varchar2/text, Service varchar2/text)

Survey.html
<html>
<head><title> Survey Information </title></head>
<body>
<form name="f1" method="post" action="insert.asp">
Email ID: <input type="text" name="t1"><br>
<fieldset>
<legend> Choose Mobile Service</legend>
<input type="radio" name="r1" value="bpl" checked>BPL<br>
<input type="radio" name="r1" value="orange">Orange<br>
<input type="radio" name="r1" value="airtel">Airtel<br>
<input type="radio" name="r1" value="dolphin">Dolphin
</fieldset>
<br>
<input type="submit" value="Save Vote">
</form>
</body>
</html>

Insert.asp
<% @language=vbscript %>
<html>
<head><title>Inserting Vote</title></head>
<body>
<%
dim cn
set cn=server.createobject("Adodb.Connection")
cn.open "dsn=boardSolution"
dim sqlq
sqlq="insert into survey (Email, Service) values('" & request.form("t1") & "','" &
request.form("r1") & "')"
cn.execute sqlq
response.write "Your vote has been casted successfully"
cn.close
%><br><br>
To see the total number of votes for each service please <a href="count.asp">Click</a> here.
</body>
</html>

Count.asp
<% @language=vbscript %>
<html>
<head><title>Counting Votes</title></head>
<body>
<%
response.write "Number of votes for each service are: <br><br>"
dim cn
set cn=Server.CreateObject("ADODB.Connection")
cn.open "dsn=boardSolution"
dim rs
set rs=Server.CreateObject("ADODB.Recordset")
dim sqlq
sqlq="select Service ,count(Service) from survey group by Service"
rs.open sqlq,cn
do until rs.eof
response.write rs(0) & " : "& rs(1) & "<br>"
rs.movenext
loop
rs.close
cn.close
%>
</body>
</html>
November 2006
Q.1 (d): Write a vbscript function to accept an year. Display whether it is a leap year or not. (5)

Solution:

Leap.html
<html>
<head><title>Leap Year</title></head>
<script language="vbscript">
Sub check()
Dim yr
Yr=f1.t1.value
If yr mod 4=0 then
Msgbox "Year entered is a leap year"
Else
Msgbox "Year entered is not a leap year"
End if
End sub
</script>
<body>
<form name="f1">
Year: <input type="text" name="t1" maxlength=”4”><br>
<input type="button" value="Check" onclick="check()">
</form>
</body>
</html>

Q.6 (c): Write a vbscript code to accept a character. Display if it is a vowel or a consonant. (6)

Solution:

CheckChar.html
<html>
<head> <title>Case conversion</title>
<script language="vbscript">
sub check()
dim n
n=f1.t1.value
if isnumeric(n)=false then
if n="a" or n="A" or n="e" or n="E" or n="i" or n="I" or n="o" or n="O" or n="u" or n="U"

then
msgbox "Entered character is a vowel"
else
msgbox "Entered character is a consonant"
end if
else
msgbox "Only alphabets are allowed"
f1.t1.value=""
end if
end sub
</script></head>
<body>
<form name="f1">
Enter an alphabet: <input type="text" name="t1" maxlength="1">
<br>
<input type="button" value="Check" onclick="check()">
</form>
</body>
</html>

Q.7 (a) Write an HTML code to design the following page: (8)

The above form allows a user to place orders for coffee, tea and lime juice. Validate the above form using
VBScript. Quantity and rate must be positive no.s. user must select atleast one option from coffee, tea or
lime juice. Also write a vbscript code (called on click of CALCULATE button) which will calculate the
amount and display it in the textbox next to that item.
(B): create an insert.asp page (called on click on SAVE button) to insert data of the above form into
database table.
ORDERDETAIL(order_no,product_nme,quantity,rate,amount)
(C): create a summary.asp page(called on click of SUMMARY button) to display the data fraom the above
table in tabulat format.

Solution:

Form.html
<html>
<head>
<title>Input Order</title>
<script language=vbs>
sub select1()
window.open("summary.asp")
end sub
sub setoption(x)
f1.h1.value=x
end sub
sub calc()
if int(f1.t1.value)>0 and int(f1.t2.value)>0 then
price=int(f1.t1.value)*int(f1.t2.value)
if f1.h1.value="c" then
f1.t3.value=price
f1.t4.value=""
f1.t5.value=""
elseif f1.h1.value="t" then
f1.t3.value=""
f1.t4.value=price
f1.t5.value=""
elseif f1.h1.value="l" then
f1.t3.value=""
f1.t4.value=""
f1.t5.value=price
else
msgbox "no options selected"
end if

else
msgbox "invalid quantity and rate"
end if
end sub
</script>
</head>

<body>
<table border=2 cellspacing=5>
<form method=post name=f1 action="insert.asp">
<tr>
<td align=right> Quantity: <input type=text name=t1> <br>
Rate: <input type=text name=t2> <br><br>
<center> <input type=button name=b1 value="Calculate" onclick="calc()"> </center>
</td>

<td> <input type=radio name=op1 value="c"onclick=setoption('c')>Coffee <br><br>


<input type=radio name=op1 value="t" onclick=setoption('t')>Tea <br><br>
<input type=radio name=op1 value="l" onclick=setoption('l')>Lime Juice
</td>

<td> <input type=text name=t3 readonly> <br>


<input type=text name=t4 readonly> <br>
<input type=text name=t5 readonly>
</td>
<input type=hidden name=h1 value="ctl">
</tr>
<tr>
<td> &nbsp;</td>
<td> <input type=button value="Summary" onclick="select1()"></td>
<td> <input type=submit value="Save"></td>
</tr>
</form>
</table>
</body>
</html>

Insert.asp
<% @language=vbs %>
<html>
<head>
<title>Inserting the data</title>
</head>
<body>
<%
temp=request.form("op1")
if temp="c" then
product="coffee"
amnt=request.form("t3")
elseif temp="t" then
product="tea"
amnt=request.form("t4")
else
product="lime juice"
amnt=request.form("t5")
end if
qty=request.form("t1")
rate=request.form("t2")
set cn=server.createobject("ADODB.Connection")
set rs=server.createobject("ADODB.Recordset")
cn.open "dsn=boardSolution"
rs.open "select max(order_no) from ORDERDETAIL",cn
ono=rs(0)+1
sqlq="insert into ORDERDETAIL (order_no,product_name,quantity,rate,amount) values (" & ono
& ",'" & product & "'," & qty & "," & rate & "," & amnt & ")"
cn.execute sqlq
response.write "new record added"

%>
</body>
</html>

Summary.asp
<% @language=vbs %>
<html>
<head><title>Summary Page</title></head>
<body>
<table border=1>
<%
set cn=server.createobject("adodb.connection")
set rs=server.createobject("adodb.recordset")
cn.open "dsn=db2"
rs.open "select * from ORDERDETAIL",cn
%>
<table border=2>
<%
do until rs.eof
response.write "<tr>"
for i=0 to rs.fields.count-1
response.write "<td>"&rs(i).value&"</td>"
next
response.write "</tr>"
rs.movenext
loop
%>
</table>
</body>
</html>
November 2007
Q.1 (c): Write vbscript function to accept 5 no.s. display how many of these are odd, even and neutral
no.s (5)
Solution:

countNumbers.html
<html>
<head><title>Count no.s</title>
<script language="VBScript">
dim arr(5)
dim i,ctrEven,ctrOdd,ctrNeutral
ctrEven=0
ctrOdd=0
ctrNeutral=0
for i=0 to Ubound(arr)-1
arr(i)=int(inputbox("Enter a number:"))
if arr(i) mod 2=0 then
ctrEven=ctrEven+1
elseif arr(i) mod 2 <>0 then
ctrOdd=ctrOdd+1
else
ctrNeutral=ctrNeutral+1
end if
next
document.write "There are total " & ctrEven & " even no.s , " & ctrOdd & " odd no.s and " &
ctrNeutral & " neutral no.s."
</script>
</head>
<body>
</body>
</html>

Q.6 (c): Write a vbscript function to accept a character. Display its case. Convert it to the other case
and display again. Do not use UCASE and LCASE functions. (6)
Solution:

Case.html
<html>
<head><title>Case conversion</title>
<script language="vbscript">
sub check()
dim c,n
c=f1.t1.value
if isnumeric(c)=false then
n=asc(c)
if n>=65 and n<=91 then
document.write "You have entered the character in Uppercase<br>"
document.write "Its Lowercase is : " & chr(n+32)
elseif n>=97 and n<=123 then
document.write "You have entered the character in Lowercase<br>"
document.write "Its Uppercase is : " & chr(n-32)
else
msgbox "Special symbols are not permitted"
end if
else
msgbox "Only alphabets are allowed"
end if
end sub
</script></head>
<body>
<form name="f1">
Enter an alphabet: <input type="text" name="t1" maxlength="1"> <br>
<input type="button" value="Check" onclick="check()">
</form>
</body>
</html>

Solution:

Product.html
<html>
<head> <title>Product Insertion</title>
<script language=vbscript>
function check()
if isnumeric(f1.t1.value)=true or isnumeric(f1.t2.value)=false or isnumeric(f1.t3.value)=false then
document.write "Please enter valid data"
end if
end function
</script> </head>
<body>
<form name=f1 method=post action="insert.asp" onsubmit="check()">
<table border=1 cellspacing=10>
<tr>
<td>Product Description</td>
<td>:</td>
<td><input type=text name=t1></td>
</tr>
<tr>
<td>Product Price</td>
<td>:</td>
<td><input type=text name=t2></td>
</tr>
<tr>
<td>Product Quantity</td>
<td>:</td>
<td><input type=text name=t3></td>
</tr>
<tr>
<td colspan=3 align=center><input type=submit value="ADD"></td>
</tr>
</table>
</form>
</body>
</html>

Insert.asp
<%@ language=vbscript%>
<html>
<head>
<title>Insert Product</title>
</head>
<body>
<%
dim cn
set cn=server.createobject("ADODB.Connection")
cn.open "dsn=db2"
pd=request.form("t1")
pr=request.form("t2")
qty=request.form("t3")
amt=pr*qty
sqlq="insert into Product(PDesc,PPrice,PQty,PAmt) values ('" & pd & "'," & pr & "," & qty &

"," & amt & ")"


cn.execute sqlq
cn.close
response.write "Successful insertion"
%>
</body>
</html>
November 2008
Q.1 (b) Write a vbscript function to print all prime no.s from 1 to 100 (5)

Solution:

Prime.html
<html>
<head>
<title>Printing Prime no.s from 1 to 100</title>
<script language=vbscript>
dim x,i
dim flag
flag=1
for x=1 to 100
for i=2 to x/2
if x mod i = 0 then
flag=0
exit for
else
flag=1
end if
next
if flag=1 then
document.write x & "<br>"
end if
next
</script>
</head>
<body>
</body>
</html>

Q.3

Solution:

Age.html
<html>
<head>
<script language="vbscript">
sub CalcAge()
dim by,bm,cy,cm
dim ty,tm
by=f1.yr.value
bm=f1.s1.value
cy=DatePart("yyyy",Date)
cm=DatePart("m",Date)
if int(bm)<=int(cm) then
tm=cm-bm
ty=cy-by
msgbox ty & " years " & tm & " months"
elseif int(bm)>int(cm) then
tm=12-(bm-cm)
ty=(cy-by)-1
msgbox ty & " years " & tm & " months"
end if
end sub
</script>
</head>
<body>
<form name="f1">
Select month:
<select name="s1">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Enter year: <input type="text" name="yr"></br>
<input type="submit" value="Calculate" onclick="CalcAge()"><br>
</form>
</body>
</html>

Hint: use hidden fields

Solution:

Assess.html
<html>
<head>
<title>Assessment</title>
<script language="vbscript">
function validate()
if isnumeric(f1.ISt1.value)=true and isnumeric(f1.ISt2.value)=true and
isnumeric(f1.ISt3.value)=true and isnumeric(f1.VBt1.value)=true and

isnumeric(f1.VBt2.value)=true and isnumeric(f1.VBt3.value)=true and


isnumeric(f1.SQLt1.value)=true and isnumeric(f1.SQLt2.value)=true and
isnumeric(f1.SQLt3.value)=true then

if f1.ISt1.value>0 and f1.ISt2.value>0 and f1.ISt3.value>0 and


f1.VBt1.value>0 and f1.VBt2.value>0 and f1.VBt3.value>0 and
f1.SQLt1.value>0 and f1.SQLt2.value>0 and f1.SQLt3.value>0 then

if f1.ISt1.value<f1.ISt2.value or f1.VBt1.value<f1.VBt2.value or

f1.SQLt1.value<f1.SQLt2.value or f1.ISt3.value>f1.ISt2.value or

f1.VBt3.value>f1.VBt2.value or f1.VBt3.value>f1.VBt2.value then


document.write "Invalid information"
end if
else
document.write "Enter Positive no.s only"
end if
else
document.write "Enter numbers only"
end if
end function
</script>
</head>
<body>
<form name="f1" method="post" action="insert.asp" onsubmit="validate()">
<h4>
Examination: T.Y.B.Sc.(IT)
<input type="hidden" value="T.Y.B.Sc.(IT)" name="exam"><br><br>
Semester: V
<input type="hidden" value="V" name="sem"> <br><br>
Year: 2008-2009
<input type="hidden" value="2008-2009" name="yr"><br><br>
</h4>
<table border="1" width="70%">
<tr>
<th>Subject</th>
<th>Exam Date</th>
<th>No. of Answer Books</th>
<th>Assessed</th>
<th>Moderated</th>
</tr>
<tr>
<td>Internet<br>Security
<input type="hidden" value="Internet Security" name="is">
</td>
<td>10-11-2008
<input type="hidden" value="10-11-2008" name="ISdate">
</td>
<td><input type="text" name="ISt1"></td>
<td><input type="text" name="ISt2"></td>
<td><input type="text" name="ISt3"></td>
</tr>
<tr>
<td>Visual<br>Basic
<input type="hidden" value="Visual Basic" name="vb">
</td>
<td>12-11-2008
<input type="hidden" value="12-11-2008" name="VBdate">
</td>
<td><input type="text" name="VBt1"></td>
<td><input type="text" name="VBt2"></td>
<td><input type="text" name="VBt3"></td>
</tr>
<tr>
<td>Structured Query<br>Language 2
<input type="hidden" value="Structured Query Language" name="sql">
</td>
<td>14-11-2008
<input type="hidden" value="14-11-2008" name="SQLdate">
</td>
<td><input type="text" name="SQLt1"></td>
<td><input type="text" name="SQLt2"></td>
<td><input type="text" name="SQLt3"></td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" value="Submit">
</tr>
</table>
</form>
</body>
</html>

Insert.asp
<% @language=vbscript %>
<html>
<head>
<title>Inserting Assessment information</title>
</head>
<body>
<%
dim cn
set cn=server.createobject("Adodb.Connection")
cn.open "dsn=boardSolution"

dim rs
set rs=server.createObject("ADODB.Recordset")
rs.open "Assessment",cn,2,3

rs.AddNew
rs(0)=request.form("exam")
rs(1)=request.form("sem")
rs(2)=request.form("yr")
rs(3)=request.form("is")
rs(4)=request.form("ISdate")
rs(5)=request.form("ISt1")
rs(6)=request.form("ISt2")
rs(7)=request.form("ISt3")

rs.AddNew
rs(0)=request.form("exam")
rs(1)=request.form("sem")
rs(2)=request.form("yr")
rs(3)=request.form("vb")
rs(4)=request.form("VBdate")
rs(5)=request.form("VBt1")
rs(6)=request.form("VBt2")
rs(7)=request.form("VBt3")

rs.AddNew
rs(0)=request.form("exam")
rs(1)=request.form("sem")
rs(2)=request.form("yr")
rs(3)=request.form("sql")
rs(4)=request.form("SQLdate")
rs(5)=request.form("SQLt1")
rs(6)=request.form("SQLt2")
rs(7)=request.form("SQLt3")
rs.update
response.write "Records added successfully"
cn.close
%>
</body>
</html>

Das könnte Ihnen auch gefallen