SIDEBAR
»
S
I
D
E
B
A
R
«
php page
May 25th, 2015 by triwiyono

Mengubah angka/bilangan menjadi kata-kata pada Ms. Excel
Mar 1st, 2012 by triwiyono

Bagaimanakah menjadikan angka menjadi kata-kata agar tidak salah ketik? misalnya dalam pembuatan kuitansi.

ex. :

Rp. 12.000,-

terbilang: Dua belas ribu rupiah

Gunakan skrip di bawah inipada macro VBA.

================================

Function sbt(c As Long)
If (c = 2 ) Then sbt = “puluh”
If (c = 3 ) Then sbt = “ratus”
If (c = 4 ) Then sbt = “ribu”
If (c = 5 ) Then sbt = “puluh”
If (c = 6 ) Then sbt = “ratus”
If (c = 7 ) Then sbt = “juta”
If (c = 8 ) Then sbt = “puluh”
If (c = 9 ) Then sbt = “ratus”
If (c = 10 ) Then sbt = “milyar”
If (c = 11 ) Then sbt = “puluh”
End Function

Private Function nm(cx As String)
If (cx = “1” ) Then nm = “satu”
If (cx = “2” ) Then nm = “dua”
If (cx = “3” ) Then nm = “tiga”
If (cx = “4” ) Then nm = “empat”
If (cx = “5” ) Then nm = “lima”
If (cx = “6” ) Then nm = “enam”
If (cx = “7” ) Then nm = “tujuh”
If (cx = “8” ) Then nm = “delapan”
If (cx = “9” ) Then nm = “sembilan”
If (cx = “0” ) Then nm = “nol”
End Function

Function bilang(angka As String ) As String
Dim ang As Long
Dim bulat As String
Dim bul As Long
Dim x As Long
Dim pos As Long
Dim z As String
Dim w As String
Dim y As Long
Dim k1 As String
Dim k2 As String
Dim yy As Long
Dim ext As String
Dim stp As Long
Dim v As String

ang = Len( angka )
bulat = angka
bul = Len( bulat )
x = bul
stp = 0

Do While (x > 0 )
pos = bul – x + 1
z = Mid(bulat, pos, 1 )
w = Mid(bulat, pos )
y = Len(w)

If (z <> “0” ) Then
‘jika angkanya bukan nol

If ( z = “1” And ( y = 2 Or y = 5 Or y = 8 Or y = 11 ) ) Then
‘jika angka 1 dan merupakan puluhan, puluh ribu, puluh juta, puluh milyar

v = Mid(bulat, pos + 1, 1 )

If ( v = “1” ) Then
‘ jika angka belakangnya = 1
k1 = “sebelas ”
yy = y – 1
k2 = sbt( y – 1 )
ElseIf (v = “0” ) Then
‘jika angka belakangya = 0
k1 = “se”
k1 = k1 & sbt( y )
k1 = k1 & ” ” & sbt( y – 1 )
k2 = “”
Else
‘jika angka di belakngnya bukan 1 ataupun 0
k1 = nm( v )  & ” belas”
yy = y – 1
k2 = sbt( y – 1 )
End If

stp = 0
ext = k1 & ” ” & k2
x = x – 1

ElseIf ( z = “1” And pos = 1 And ( y = 3 Or y = 4 Or y = 6 Or y = 9 ) ) Then
‘ jika angka 1 di posisi paling depan dan merupakan ratusan, ribuan, ratusan ribu, ratusan juta
k1 = “se”
k2 = sbt( y )
ext = k1 & k2
ElseIf ( z = “1” And ( y = 3 Or y = 6 Or y = 9 ) And Mid(bulat, pos + 1, 1 ) = “0” And Mid(bulat, pos + 2, 1) = “0” ) Then
k1 = “se”
k2 = sbt( y ) & ” ” & sbt( y – 2 )
ext = k1 & k2
x = x – 2
ElseIf ( z = “1” And ( y = 3 Or y = 6 Or y = 9 ) ) Then
‘ jika angka 1 di posisi ratusan, ratusan ribu, ratusan juta
k1 = “se”
k2 = sbt( y )
ext = k1 & k2
ElseIf ( z <> “1” And ( y = 3 Or y = 6 Or y = 9 ) And Mid( bulat, pos + 1, 1 ) =  “0” And Mid(bulat, pos + 2, 1  ) = “0” ) Then
‘jika buka angka 1 dan merupakan ratusan bulat, ratusan ribu bulat, ratusan juta bulat
k1 = nm(z)
k2 = sbt(y) & ” ” & sbt(y – 2)
ext = k1 & ” ” & k2
x = x – 2
ElseIf ( z <> “1” And (y = 5 Or y = 8 Or y = 11 ) And Mid(bulat, pos + 1, 1 ) = “0” ) Then
k1 = nm( z )
k2 = sbt(y) & ” ” & sbt( y – 1 )
ext = k1 & ” ” & k2
x = x – 1
Else
k1 = nm( z )
k2 = sbt( y )
ext = k1 & ” ” & k2
End If

ElseIf ( z = “0” And ( y = 4 Or y = 7 Or y = 10 ) And stp = 0 ) Then
‘jika angka 0 dan merupakan ribuan, jutaan, milyaran
If (Mid( bulat, pos – 1, 1 ) <> 0 ) Then
ext = sbt( y )
End If
stp = 1
Else
ext = “”
End If

If (ext <> “” And bilang <> “” ) Then
bilang = bilang & ” ” & ext
ElseIf (ext <> “” And bilang = “” ) Then
bilang = ext
End If
x = x – 1

Loop

bilang = UCase(Mid(bilang, 1, 1 ) ) & Mid(bilang, 2 ) & ” rupiah”

End Function

Sub baru()

End Sub

=============================

Membuat paging halaman web yg ringan
Feb 29th, 2012 by triwiyono

Silakan gunakan skrip ini (anda bisa kustomisasi nama variabelnya):

==============================================

<?php

function paging($isi,$divider){
//data yg mau di-paging dibikin array $isi[]

$jumlah = count($isi);
$jml_hlm = ceil($jumlah/$divider);
$ret .= “Number of pages = $jml_hlm”;
$ret .= “objek = $jumlah”;
$ret .= “per page content $divider”;

//fungsi tampil-sembunyi
$ret .= “<script language=javascript>

function tampilkan(x){
document.getElementById(\”div-\”+x).style.display=”;
document.getElementById(\”a-\”+x).innerHTML=’<font color=red><b>’+x+’</b></font>’;
var y = $jml_hlm;
for(var i=1;i<=y;i++){
if(i!=x){
document.getElementById(\”div-\”+i).style.display=’none’;
document.getElementById(\”a-\”+i).innerHTML=\”<a href=’javascript:tampilkan(\”+i+\”)’>\”+i+\”</a>\”;
}
}
}

function next(x){
var y = x +1;
document.getElementById(\”group-\”+y).style.display=”;
document.getElementById(\”group-\”+x).style.display=’none’;
}

function prev(x){
var y = x -1;
document.getElementById(\”group-\”+y).style.display=”;
document.getElementById(\”group-\”+x).style.display=’none’;
}
</script>
“;

$x=1;
$count = 0;
foreach($isi as $anu){
if($x==1) {
$count++;
if($count==1) {
$status=””;
}else{
$status=”none”;
}
$ret .= “<div style=’border: solid 0px; display:$status’ id=’div-$count’><div style=’background-color: silver; text-align: right’>page $count of $jml_hlm</div>”;
}
$angka = substr($anu,7);
$ret .= “$x = <a href=’tgl.php?var=$angka’ target=’frame’>$anu</a><br>”;
$x++;
if($x==$divider+1) {
$ret .= “</div>”;
$x=1;
}

}
if($x!=0) $ret .= “</div>”;

$ret .= “<div style=’background-color: silver’><table align=center border=0><tr><td>Page:  </td><td>”;
$group =0;
$start = 0;
for($y=1;$y<=$jml_hlm;$y++){
if($group==0) {
$stat=””;
}else{
$stat=”none”;
}
if($start==0) {
$ret .= “<div id=’group-$group’ style=’border: solid 0px; display:$stat; width:400px’><table border= 0 width=100%><tr>”;
if($group>0) $ret .= “<td align=center  width=7%><a href=’javascript: prev($group)’><<< </a></td>”;
}

if($y==1) {
$ret .= “<td  align=center width=7%><div id=’a-$y’><font color=red><b>$y</b></font></div></td>”;
}else{
$ret .= “<td  align=center  width=7%><div id=’a-$y’><a href=’javascript:tampilkan($y)’>$y</a></div></td>”;
}
$start++;
if($y%10==0) {
$ret .= “<td align=center  width=7%><a href=’javascript:next($group)’> >>></a></td></tr></table></div>”;
$start=0;
$group++;
}
}

if($y%10!=0 or $y<=10) {
$ret .= “</tr></table></div>”;
}
$ret .= “</td></tr></table></div>”;
//$ret .=”<iframe name=’frame’ style=’border: solid 0px; width:100%; height:55%’>”;
return $ret;
}

//sample data

for($i=1;$i<=192;$i++){
$objek[] = “Item – $i”;
}

$ret .= paging($objek,5);

echo $ret;
?>

SIDEBAR
»
S
I
D
E
B
A
R
«
»  Substance:WordPress   »  Style:Ahren Ahimsa