Kumpulan Fungsi


Function CheckNumeric(text As String, DecValue As Boolean) As Boolean
    Dim i As Integer
    For i = 1 To Len(text)
        Select Case Mid$(text, i, 1)
            Case “0” To “9”
            Case “-“, “+”
            ‘Tanda minus/plus signs hanya
            ‘untuk pertama kali.
                If i > 1 Then Exit Function

            Case “.”
            ‘Jika decvalue bernilai false, tidak
            ‘diizinkan.
                If Not DecValue Then Exit Function

             ‘hanya satu . (pemisah desimal) yang
             ‘diizinkan.
               If InStr(text, “.”) < i Then Exit Function

            Case Else
            ‘semua karakter selain di atas, tidak valid.
                Exit Function
        End Select
    Next
    CheckNumeric = True
End Function

Function RandomArray(first As Long, last As Long) As Long()
    Dim i As Long, j As Long, temp As Long
    ReDim result(first To last) As Long
    ‘ Inisialisasi array.
    For i = first To last: result(i) = i: Next
    ‘ Acak urutan.
    For i = last To first Step -1
        ‘ menghasilkan posisi acak.
        j = Int(Rnd * (last – first + 1) + first)
        ‘ tukar posisi asli dengan posisi acak.
        temp = result(i)
        result(i) = result(j)
        result(j) = temp
    Next
    RandomArray = result
End Function
Function AlmostEqual(x, y, delta) As Boolean
    AlmostEqual = (Abs(x – y) <= delta)
End Function

Function SinDegree(Angle As Integer) As Single
  Dim radian As Single
  pi = 3.14
  radian = Angle * (pi / 180)
  SinDegree = FormatNumber(Sin(radian), 2)
End Function

Function CosDegree(Angle As Integer) As Single
  Dim radian As Single
  pi = 3.14
  radian = Angle * (pi / 180)
  CosDegree = FormatNumber(Cos(radian), 2)
End Function

Function TanDegree(Angle As Integer) As Single
  Dim radian As Single
  pi = 3.14
  radian = Angle * (pi / 180)
  TanDegree = FormatNumber(Tan(radian), 2)
End Function

 

About these ads

One response to “Kumpulan Fungsi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s