VBScript merupakan varian dari visual basic yang menjadi default dari internet ekplorer selain javascript. Interpreternya sudah disediakan oleh internet ekplorer.
<!– HelloRasid.html // emerer.com–>
<html>
<body>
<script language=”vbscript”>
window.document.write (“Hello Rasid”)
</script>
</body>
</html>
Variable dan Konstanta
Beberapa hal yang harus diperhatikan:
<!– Deklarasi.html // emerer.com–>
<html>
<body>
<script language=”vbscript”> <br>
const varstring=”Selamat Pagi”
const varangka= 354
const vartanggal= #1/1/2013#
public x
private y
dim z
x=5
y=10.2
z=”Siang”
window.document.write(varstring)&” dan “
window.document.write(varangka)&” adalah angka “
window.document.write(vartanggal)&” merupakan tanggal “
window.document.write(x)&” dan “
window.document.write(y)&” dan “
window.document.write(z)
</script>
</body>
</html>
Operator Aritmatik
<!– Aritmatik.html // emerer.com–>
<html><body>
<script language=”vbscript”>
sub eMeReR()
var1=window.prompt(” Nilai pertama : “)
var2=window.prompt(” Nilai kedua : “)
document.write(” Concatenation dengan operator & (dan) “)
document.write “<br>”& var1&var2
document.write(“<br>”+” Concatenation dengan operator + (plus) “)
document.write “<br>”& var1+var2
document.write(“<br> Penjumlahan : “+”<br>”)
document.write cint(var1) + cint(var2)
document.write(“<br> Pengurangan : <br>”)
document.write cint(var1) – cint(var2)
document.write(“<br> Pangkat : <br>”)
document.write cint(var1) ^ cint(var2)
document.write(“<br> Mod : <br>”)
document.write cint(var1) mod cint(var2)
document.write(“<br> Integer div : <br>”)
document.write cint(var1) \ cint(var2)
document.write(“<br> Real div : <br>”)
document.write cint(var1) / cint(var2)
end sub
</script>
<input type=”button” name=”tombol” value=”Aritmatic” onClick=”eMeReR” ></body></html>
Operator Logika
Operator Logika | Function |
val1 And val2 | True jika keduanya true |
val1 Or val2 | True jika satu atau keduanya true |
val1 Xor val2 | True jika hanya satu is true |
val1 Eqv val2 | True jika keduanya adalah true atau keduanya adalah false |
val1 Imp val2 | True jika val2 true atau keduanya false |
Not val | True jika val false |
<!– Logika.html // emerer.com–>
<html>
<body>
<script language=”vbscript”>
sub eMeReR()
var1=window.prompt(” Nilai pertama : “)
var2=window.prompt(” Nilai kedua : “)
document.write(“Operator and : <br>”)
document.write cbool(var1) and cbool(var2)
document.write(“<br> Operator or : <br>”)
document.write cbool(var1) or cbool(var2)
document.write(“<br> Operator xor : <br>”)
document.write cbool(var1) xor cbool(var2)
document.write(“<br> Operator imp : <br>”)
document.write cbool(var1) imp cbool(var2)
document.write(“<br> Operator eqv : <br>”)
document.write cbool(var1) eqv cbool(var2)
document.write(“<br> Operator not div : <br>”)
document.write not cbool(var1)
end sub
</script>
<input type=”button” name=”tombol” value=”Logika” onClick=”eMeReR” >
</body>
</html>
Operator Relational
<!– Relational.html // emerer.com–>
<html>
<body>
<script language=”vbscript”>
sub eMeReR()
var1=window.prompt(” Nilai pertama : “)
var2=window.prompt(” Nilai kedua : “)
document.write(“Operator > hasilnya ” & cbool(var1 > var2) & “<br>”)
document.write(“Operator < hasilnya “& cbool(var1 < var2) & “<br>”)
document.write(“Operator >= hasilnya “& cbool(var1 >= var2) & “<br>”)
document.write “Operator <= hasilnya “& cbool(var1 <= var2) & “<br>”
document.write(“Operator = hasilnya “& cbool(var1 = var2) & “<br>”)
document.write(“Operator <> hasilnya “& cbool(var1 <> var2) & “<br>”)
end sub
</script>
<input type=”button” name=”tombol” value=”Relational” onClick=”eMeReR” >
</body>
</html>
Operasi String
<!– OperatorString.html // emerer.com–>
<html>
<body>
<script language=”vbscript”>
sub eMeReR()
var1=window.prompt(” Masukan sebuah kata : “)
document.write “Fungsi asc(var) hasilnya ” & asc(var1) & “<br>”
document.write “Fungsi ucase(var) hasilnya ” & ucase(var1) & “<br>”
document.write “Fungsi lcase(var) hasilnya ” & lcase(var1) & “<br>”
document.write “Fungsi left(var,3) hasilnya ” & left(var1,3) & “<br>”
document.write “Fungsi right(var,3) hasilnya ” & right(var1,3) & “<br>”
document.write “Fungsi mid(var,2,4) hasilnya ” & mid(var1,2,4) & “<br>”
document.write “Fungsi len(var) hasilnya ” & len(var1) & “<br>”
document.write “Fungsi trim(var) hasilnya” & trim(var1) & “kata lain<br>”
document.write “Fungsi rtrim(var) hasilnya” & rtrim(var1) & “kata lain<br>”
document.write “Fungsi ltrim(var) hasilnya” & ltrim(var1) & “kata lain<br>”
end sub
</script>
<input type=”button” name=”tombol” value=”Operator String” onClick=”eMeReR” >
</body></html>
Operasi Date dan Time
<!– DateTime.html // emerer.com–>
<html><body>
<script language=”vbscript”>
document.write “now() hasilnya ” & now() & “<br>”
document.write “date() hasilnya ” & date() & “<br>”
document.write “time() hasilnya ” & time() & “<br>”
document.write “day(date()) hasilnya ” & day(date()) & “<br>”
document.write “month(date()) hasilnya ” & month(date()) & “<br>”
document.write “year(date()) hasilnya ” & year(date()) & “<br>”
document.write “hour(time()) hasilnya ” & hour(time()) & “<br>”
document.write “minute(time()) hasilnya ” & minute(time()) & “<br>”
document.write “second(time()) hasilnya ” & second(time()) & “<br>”
document.write “datepart(“”d””,date()) hasilnya ” & datepart(“d”,date()) & “<br>”
document.write “datepart(“”m””,date()) hasilnya ” & datepart(“m”,date()) & “<br>”
document.write “datepart(“”y””,date()) hasilnya ” & datepart(“y”,date()) & “<br>”
document.write “datepart(“”ww””,date()) hasilnya ” & datepart(“ww”,date()) & “<br>”
document.write “dateadd(“”m””,1,date()) hasilnya ” & dateadd(“m”,1,date()) & “<br>”
document.write “dateadd(“”d””,20,date()) hasilnya ” & dateadd(“d”,20,date()) & “<br>”
document.write “datediff(“”d””,””03/08/1985″”,date()) hasilnya ” & datediff(“d”,”03/08/1985″,date()) & “<br>”
</script></body></html>
Penggunaan If
<!– Penggunaan If.html // emerer.com–>
<html><body>
<script language=”vbscript”>
sub Rasid()
var1=inputbox(” Masukan Usia Anda : “)
if var1>17 then window.document.write “Anda sudah dewasa, boleh lihat konten ini “
end sub
</script>
<input type=”button” name=”tombol” value=”Penggunaan If” onClick=”Rasid” >
</body></html>
If…..else
<!– Penggunaan If Else.html // emerer.com–>
<html><body>
<script language=”vbscript”>
sub Rasid()
var1=inputbox(” Masukan Usia Anda : “)
if var1>17 _
then string1= “Anda sudah dewasa, boleh lihat konten ini ” _
else string1= “Anda DILARANG KERAS meneruskan !!! “
msgbox(string1)
end sub
</script><input type=”button” name=”tombol” value=”Penggunaan If Else” onClick=”Rasid” >
</body></html>
Nested If
<!– Penggunaan Nested If.html // emerer.com–>
<html>
<body>
<script language=”vbscript”>
sub Rasid()
i=hour(time)
If i = 9 Then
document.write(“Baru dimulai…!”)
ElseIf i = 10 Then
document.write(” Habis Istirahat”)
ElseIf i = 17 Then
document.write(“Selamat Sore”)
ElseIf i = 20 Then
document.write(“Break dulu”)
Else
document.write(“Bye”)
End If
end sub
</script>
<input type=”button” name=”tombol” value=”Penggunaan Nested If” onClick=”Rasid” >
</body>
</html>
Penggunaan Case
<!– Case.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
d=weekday(date)
Select Case d
Case 1
document.write(“Libur hari Minggu”)
Case 2
document.write(“Senin lagi :-(“)
Case 3
document.write(“Baru hari Selasa”)
Case 4
document.write(“Rabu!”)
Case 5
document.write(“Kamis…”)
Case 6
document.write(“Akhirnya Jumat juga”)
Case else
document.write(“Sabtu, nanti bisa malam mingguan”)
End Select
</script>
</body>
</html>
Pengulangan For
<!– For.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
for x=1 to 7
document.write x & “<br>”
next
</script>
</body>
</html>
Pengulangan While…Wend
<!– WhileWend.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
x=0
while x <= 7
document.write x & “<br>”
x = x+1
wend
</script>
</body></html>
Pengulangan Do…Loop Until
<!– DoLoopUntil.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
x=0
do
document.write x & “<br>”
x = x+1
loop until (x > 7)
</script>
</body>
</html>
Pengulangan Do…Looping While
<!– DoLoopWhile.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
x=0
do
document.write x & “<br>”
x = x+1
loop while (x <= 7)
</script>
</body>
</html>
Pengulangan Do While…Looping
<!– DoWhileLoop.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
x=0
do while (x <= 7)
document.write x & “<br>”
x = x+1
loop
</script>
</body></html>
Pengulangan dengan EXIT
<!– LoopExit.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
x=0
do while (x <= 7)
document.write x & “<br>”
x = x+1
if (x=4) then exit do end if
loop
</script></body></html>
Subprogram
<!– SubProgram.html // emerer.com–>
<html>
<body>
<script type=”text/vbscript”>
dim a, b
sub Rasid()
dim temp
temp=a
a=b
b=temp
document.write (“a = “) & a & (“<br>”)
document.write (“b = “) & b & (“<br>”)
end sub
function perkalian(x,y)
perkalian = (x*y)
end function
a = inputbox (“a = “)
b = inputbox (“b = “)
Rasid()
document.write(“Perkalian a * b = “) & perkalian(a,b) & (“<br>”)
</script>
</body>
</html>
Array
<!– Array.asp // emerer.com–>
<html>
<body>
<script language=”vbscript”>
Dim eMeReR(10)
eMeReR(1)=1
eMeReR(3)=354
eMeReR(10)=313
window.document.write (eMeReR(1))
window.document.write (“<br>”)
window.document.write (eMeReR(3))
window.document.write (“<br>”)
window.document.write (eMeReR(10))
</script>
</body>
</html>
Matriks
<!– Matrik.asp // emerer.com–>
<html><body>
<script language=”vbscript”>
dim array1(10,10), array2(10,10), array3(10,10)
a=inputbox(“Array1 Baris”)
b=inputbox(“Array1 Kolom atau Array2 Baris”)
c=inputbox(“Array2 Kolom”)
for x=1 to a
for y=1 to b
array1(x,y)=inputbox(“Array1 Baris ke “&x&” kolom ke “&y)
next
next
for y=1 to b
for z=1 to c
array2(y,z)=inputbox(“Array2 Baris ke “&y&” kolom ke “&z)
next
next
for x=1 to a
for z=1 to c
array3(x,z)=0
for y=1 to b
array3(x,z)=array3(x,z) + (array1(x,y) * array2(y,z))
next
next
next
for x=1 to a
for z=1 to c
document.write (” b “& x &” k “& z &” : “& array3(x,z) &”<br>”)
next
next
</script>
</body>
</html>
Peringatan
<!– Alert.html // emerer.com–>
<html>
<script language=”vbscript”>
sub Rasid()
alert(” Peringatan anda belum melunasi administrasi keuangan “)
end sub
</script>
<body>
<input type=”button” name=”tombol” value=”Lihat Nilai” onClick=”Rasid” >
</body></html>
InputBox
<!– InputBox.html // emerer.com–>
<html>
<head><title> Input Box </title></head>
<script language=”vbscript”>
var1=inputbox(“Masukan nama anda: “)
window.document.write(“Selamat datang “)& var1
</script>
</body>
</html>
MessageBox
<!– MessageBox.html // emerer.com–>
<html>
<head><title> Pesan </title></head>
<script language=”vbscript”>
private x,kel,luas
const phi=3.14
x=inputbox(“Masukan jari jari lingkaran”)
keliling=x*phi*2
luas=phi*x^2
msgbox(“Jadi kelilingnya : ” & keliling)
msgbox(“Jadi luasnya : ” & luas)
</script></body></html>
Prompt
<!– Prompt.html // emerer.com–>
<html>
<body>
<script language=”vbscript”>
sub Rasid()
kalimat = window.prompt(“Masukan Nama Anda !!! “)
kalimat = “Mbak/Mas ” +kalimat
document.write”Selamat Datang “& kalimat
end sub
</script>
<input type=”button” name=”tombol” value=”Prompt” onClick=”Rasid” >
</body></html>
Object Dokumen
<!– Object.html // emerer.com–>
<html>
<head><title> Object </title>
location.href=”http://localhost/”
</head>
<body>
<script language=”vbscript”>
dim n
document.write”<h1> Informasi Dokumen</h1><hr>”
document.write” Judul : ” & document.title & “<br>”
document.write” Lokasi : ” & document.location & “<br>”
document.write” Terakhir modif : ” & document.lastmodified & “<br>”
for n=0 to document.links.lenght-1
document.write” Links (“& cstr(n) &”)=” & document.links(n).href & “<br>”
next
document.write” Warna Link : ” & document.linkcolor & “<br>”
document.write” Alinkcolor : ” & document.alinkcolor & “<br>”
document.write” Vlinkcolor : ” & document.vlinkcolor & “<br>”
document.write” Bgcolor : ” & document.bgcolor & “<br>”
document.write” Fgcolor : ” & document.fgcolor & “<br>”
</script>
<a href=”http://emerer.com”> Rasid </a>
<a href=”http://upbatam.ac.id”> UPB </a>
</body>
</html>
1 Comment
Makasih Infonya :3
Jadi gw bisa buat file html yang di inject pakai file vbs