PROSEDUR SUB DAN FUNCTION
Prosedur sub dan function merupakan potongan program yang bertugas menjalankan perintah yang sering diulang.
Prosedur sub biasanya digunakan jika perintah tersebut mempunyai nilai tetap,
sedangkan function akan menghasilkan nilai kembalian yang sifatnya berubah-ubah.
Function namafunction (variabel) Pernyataan
End Function
Sub namasub(variabel) Pernyataan
<html> <body> <center>
<%
Sub Judul()
Response.Write "<font face = 'arial' color ='red'>" Response.Write "<h2>SELAMAT DATANG</h2></font>"
Response.Write "Web Site Gaul On-Line<br>" Response.Write "www.gaul-online.com<br>"
Response.Write "<HR><br></center>" End Sub
call Judul
%>
</body> </html>
CONTOH PROSEDUR SUB
<html> <body>
<%
Function Tambah(x,y) Tambah = x + y
End Function
Response.Write "Mencoba Function" & "<BR>" Response.Write "x = 3" & "<BR>"
Response.Write "y = 5" & "<BR>"
Response.Write "Hasil Penjumlahan x + y = " & Tambah(3,5)
%>
</body> </html>
CONTOH FUNCTION:
ASP memungkinkan Anda untuk menggabungkan beberapa file menjadi satu dengan cara menyisipkan file-file tersebut kedalam file induk
menggunakan perintah #include.
Format penulisannya adalah sebagai berikut:
MENGGABUNGKAN FILE
<html> <body>
<!— #include file = “prosedur.asp" —> <%
Function Tambah(x,y) Tambah = x + y
End Function
Response.Write "Mencoba Function" & "<BR>" Response.Write "x = 3" & "<BR>"
Response.Write "y = 5" & "<BR>"
Response.Write "Hasil Penjumlahan x + y = " & Tambah(3,5)
%>
</body> </html>
CONTOH FUNCTION:
File yang digunakan : a) Counter.asp
b) Counter.txt
c) 10 file gambar
0.gif 1.gif 2.gif 3.gif 4.gif 5.gif 6.gif 7.gif 8.gif 9.gif
<HTML><BODY>
<% Dim Filecounter, RekamanAngka %>
<% Dim counter, Digit, HitungDigit, TampilDigit %>
<% Set FileCounter = CreateObject("Scripting.FileSystemObject") %>
<% Set RekamanAngka = FileCounter.OpenTextFile("D:\counter.txt",1) %>
<% Do While Not RekamanAngka.AtEndOfStream %> <% Counter = RekamanAngka.ReadLine %>
<% Loop %>
<% RekamanAngka.Close %> <% Digit = Len(Counter) %>
<% For HitungDigit = 1 to Digit %>
<% TampilDigit = TampilDigit & "<img src=""" &
Mid(Counter, HitungDigit,1) & ".gif"">" %> <% Next %>
<%= TampilDigit %>
<% Set RekamanAngka = FileCounter.CreateTextFile("D:\counter.txt") %>
<% RekamanAngka.Write Counter + 1 %> <% RekamanAngka.Close %>
</BODY></HTML>
TUGAS
•
Buatlah script ASP untuk
menampilkan:
Waktu sekarang :
Kamis, 8 Desember 2011
Waktu sekarang :
Rabu, 1 Pebruari 2012