Skip to content

Instantly share code, notes, and snippets.

@miftahafina
Last active January 18, 2017 16:18
Show Gist options
  • Save miftahafina/30a0826d6ce7b2a4d1cf2db052204552 to your computer and use it in GitHub Desktop.
Save miftahafina/30a0826d6ce7b2a4d1cf2db052204552 to your computer and use it in GitHub Desktop.
Catatan ASP classic
<% Option Explicit %>
<!DOCTYPE html>
<html>
<head>
<title>Catatan ASP Classic</title>
</head>
<body>
<%
// Deklarasi variable
// Menggunakan Option Explicit agar semua variabel harus dideklarasikan terlebih dahulu
dim nama(3)
dim nama_saya
dim i
dim x
dim y
dim angka1
dim angka2
dim hasil
dim hasil_perkalian
// Cetak string
response.write "<h2>Bismillah</h2>"
// Assigning variabel
nama(0) = "afin"
nama(1) = "mila"
nama(2) = "umi"
nama(3) = "abah"
// Procedure
sub daftar_nama()
// Perulangan
for i = 0 to 3
response.write("<li>" & nama(i) & "</li>")
next
end sub
// Fungsi
function perkalian(angka1, angka2)
hasil = angka1 * angka2
perkalian = hasil
end function
// Assigning variabel dengan larik berindeks
nama_saya = nama(0)
// Penggabungan pencetakan string dengan variabel
response.write("Nama saya adalah " & nama_saya & "<br>" )
response.write("Daftar seluruh nama:<br>")
// Pemanggilan procedure
daftar_nama()
response.write("<br>")
// Pemanggilan fungsi
hasil_perkalian = perkalian(5, 8)
response.write("Hasil dari 5 x 8 adalah " & hasil_perkalian)
response.write("<br>")
// Fungsional
if hasil_perkalian = 40 then
response.write("Hasil perkalian adalah benar 40")
else
response.write("Hasil perkalian bukan 40, melainkan " & hasil_perkalian)
end if
response.write("<br>")
// Perulangan for each
y = 0
for each x in nama
y = y+1
response.write("<li>")
response.write(y & ". " & x)
response.write("</li>")
next
response.write("<br>")
%>
<!-- Contoh form -->
<form method="get" action="Default.asp">
GET: Film favorit? <br>
<input type="text" name="film_favorit"> <br>
<input type="submit" value="Kirim"> <br><br>
</form>
<form method="post" action="Default.asp">
POST: Sutradara favorit? <br>
<input type="text" name="sutradara_favorit"> <br>
<input type="submit" value="Kirim"> <br><br>
</form>
<%
// Menerima method get
response.write("GET: Film favorit Anda adalah ")
response.write(request.querystring("film_favorit"))
response.write("<br>")
// Menerima method post
response.write("POST: Sutradara favorit Anda adalah ")
response.write(request.form("sutradara_favorit"))
%>
<!-- Include file -->
<hr>
<p>
<!-- #include file="tes.inc" -->
</p>
<hr>
<%
// Koneksi ke MS SQL
Dim con
Set con = Server.CreateObject("ADODB.Connection")
con.ConnectionString = "Provider=SQLOLEDB;Data Source=tavs-pc\afin;Database=catatan_db;User ID=miftah;password=miftahafina"
If con.errors.count = 0 Then
Response.Write "Connected OK"
End If
%>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<%
' Koneksi ke database
set conn = createObject("ADODB.connection")
set cmd = createObject("ADODB.command")
set rs = createObject("ADODB.recordSet")
conn.connectionString = "Provider=SQLOLEDB; Data Source=(local); Database=catatan_db; User ID=miftahafina; password=123"
conn.open
' Ambil data dari database
sql = "select * from catatan_tbl"
set data = conn.execute(sql)
%>
<% while not data.eof %>
<article>
<h1><% =data("judul_catatan") %></h1>
<p><% =data("isi_catatan") %></p>
<small><% =data("status_catatan") %></small>
</article>
<hr>
<%
data.movenext
wend
%>
</body>
</html>
Ini adalah file tes.inc
<%
response.write("Sekarang pukul" & Time)
%>
@miftahafina
Copy link
Author

Username dan password sekedar untuk testing saja.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment