Senin, 27 Februari 2012

[belajar-access] multiple calculator [2 Attachments]

 
[Attachment(s) from lukas ramos included below]

Saya lg bikin program dengan access tapi mentok di bagian calculator nya, saya menemukan dari internet program  dari VB6 (terlampir), di bawah ini adalah kode dari program VB tersebut. Prinsipnya sama dengan kebutuhan saya tapi sudah diulik2 ke access belum berhasil :-(||> menyerah, Suhu2 bisakan memberi pencerahan agar cara ini dapat dijalankan di Access atau mungkin juga dengan cara yang berbeda, inginnya tanda kurung,perkalian,pembagian,penjumlahan ikut tersimpan didalam data base.
Trims


kode didalam Program VB nya spt ini:

Option Explicit

Function DCr() As String
    DCr = Mid(1 / 2, 2, 1)
End Function

Function SCr() As String
    SCr = Mid(FormatNumber(1000, 0), 2, 1) 'find thousand separator
End Function

Function FormatNumberAuto(Str As String) As String
    Dim Temp1 As String, Temp2 As String
   
    If InStr(Str, "E") Or Str = "0" Then
        FormatNumberAuto = Str
        Exit Function
    End If
   
    If InStr(Str, DCr) Then
        Temp1 = Split(Str, DCr)(0)
        Temp2 = DCr & Split(Str, DCr)(1)
           
        If Temp1 <> "-0" Then Temp1 = Format(Temp1, "#,#")
       
        Do Until Right(Temp2, 1) <> "0"
            Temp2 = Left(Temp2, Len(Temp2) - 1)
        Loop
       
        If Temp2 = DCr Then Temp2 = ""
       
        Str = Temp1 & Temp2
       
        If Left(Str, 1) = DCr Then Str = "0" & Str
       
    Else
        Str = Format(Str, "#,#")
    End If
           
   
    FormatNumberAuto = Str
End Function

Sub Calc()
    On Error GoTo Ero
   
    Dim Temp1 As String, Temp2 As String, Temp3 As String
    Dim TempF As String
    Dim i As Integer

    If Cmb.Text = "" Then Exit Sub
   
    Temp1 = Replace(Cmb.Text, SCr, "")
    Temp1 = Replace(Temp1, DCr, ".")
    Temp1 = Replace(Temp1, " ", "")
   
    Txt = FormatNumberAuto(Script.Eval(Temp1))
   
    Temp2 = Replace(Cmb.Text, " ", "")
    Temp2 = Replace(Temp2, "+", " + ")
    Temp2 = Replace(Temp2, "-", " - ")
    Temp2 = Replace(Temp2, "*", " * ")
    Temp2 = Replace(Temp2, "/", " / ")
    Temp2 = Replace(Temp2, "^", " ^ ")
    Temp2 = Replace(Temp2, "(", "( ")
    Temp2 = Replace(Temp2, ")", " )")
   
    For i = 0 To UBound(Split(Temp2, " "))
        TempF = Split(Temp2, " ")(i)
        If IsNumeric(TempF) Then TempF = FormatNumberAuto(TempF)
           
        Temp3 = Temp3 & TempF & " "
    Next
   
    Temp3 = Left(Temp3, Len(Temp3) - 1)
    Temp3 = Replace(Temp3, "( ", "(")
    Temp3 = Replace(Temp3, " )", ")")
   
    'write history
    For i = 0 To Cmb.ListCount - 1
        If Cmb.List(i) = Temp3 Then
            Cmb.RemoveItem (i)
            Exit For
        End If
    Next
    Cmb.AddItem Temp3
   
    Cmb.Text = Temp3
   
Ero:
    If Err.Number <> 0 Then MsgBox Err.Description, , "Kalkulator"
    Cmb.SetFocus
End Sub

Private Sub Cmb_Click()
    SendKeys "{enter}"
End Sub

Private Sub cmb_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 48 To 57 'number
        Case 43, 45, 42, 47, 94 'function
        Case 40, 41 '( )
        Case 44, 46
            KeyAscii = 0
            Cmb.SelText = DCr
        Case 8 'bs
        Case 13 'enter
            KeyAscii = 0
            Calc
        Case Else
            KeyAscii = 0
    End Select
End Sub

Private Sub Form_Load()
    Cmb.Text = "5000+200000-(45*340)/2"
End Sub
 





__._,_.___

Attachment(s) from lukas ramos

1 of 1 Photo(s)

1 of 1 File(s)

Recent Activity:
SPAM IS PROHIBITED
.

__,_._,___

Tidak ada komentar:

Posting Komentar