Commentçamarche.net
CodeS-SourceS
Rechercher un code, un tuto, une réponse

Calculette pour programmeur

0/5 (5 avis)

Vue 4 567 fois - Téléchargée 556 fois

Description

Calculatrice et des petites fonctions bien pratique tel que faire du copier/coller de code ASCII ou HEX. pour des programmeur débutant comme moi !
C'est ma première source, alors soyez indulgent, je suis timide ...

Source / Exemple :


Option Explicit
Dim Test
Dim Opérande, Mémoire, X, TextFormat, BTPoint
Dim DEC_Width_Plus, DEC_Width_Moins
Dim ValeurBTDécimale, CDE

Private Sub Bt0_Click()
Test = Test + "0"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt1_Click()

Test = Test + "1"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt2_Click()
Test = Test + "2"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt3_Click()

Test = Test + "3"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt4_Click()
Test = Test + "4"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt5_Click()
Test = Test + "5"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt6_Click()
Test = Test + "6"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt7_Click()
Test = Test + "7"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt8_Click()
Test = Test + "8"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub Bt9_Click()
Test = Test + "9"
TxtEdit2 = Test
TxtEdit3 = 0

End Sub

Private Sub BtAide_Click()

MsgBox ("Désoler, pas d'aide disponible ! Dépendant de MenuRtf ")

End Sub

Private Sub BtAlphabet_Click(Index As Integer)
Dim A, B, X, T1, T2
A = BtAlphabet(Index).Caption
Text4 = BtAlphabet(Index).Caption
    B = Asc(A)
        X = Hex(B)
            T1 = "CDE1() =" + Chr(34) + BtAlphabet(Index).Caption + Chr(34) + ": "
            T2 = "CDE2() =" + Chr(34) + "\'" + X + Chr(34)
Text1.Text = T1 + T2
Text2.Text = "chr(" + Str(B) + ")"
CDE = "\'" + X

End Sub

Private Sub BtClear_Click()

TxtEdit1 = 0
TxtEdit2 = 0
TxtEdit3 = 0
TxtEdit4 = ""

Test = ""
Opérande = ""
BTPoint = True

Mémoire = 0

End Sub

Private Sub BtDécimal_Click()

    MenuDécimal.Visible = True
Me.Caption = "          Fonctions pour programmeur"

End Sub

Private Sub BtDivise_Click()
On Error GoTo ErreurTrouver
If Opérande = "" Then
    TxtEdit1 = TxtEdit2: Opérande = "/"
    TxtEdit3 = 0
    Else
    TxtEdit3 = Val(TxtEdit1) / Val(TxtEdit2)
    End If

Test = "": TxtEdit4 = " / ": TxtEdit2 = 0: BTPoint = True

ErreurTrouver:

End Sub

Private Sub BtEgale_Click()
Dim Calc

If Opérande = "+" Then TxtEdit3 = Val(TxtEdit1) + Val(TxtEdit2): Calc = 1
If Opérande = "X" Then TxtEdit3 = Val(TxtEdit1) * Val(TxtEdit2): Calc = 1
If Opérande = "/" Then TxtEdit3 = Val(TxtEdit1) / Val(TxtEdit2): Calc = 1
If Opérande = "-" Then TxtEdit3 = Val(TxtEdit1) - Val(TxtEdit2): Calc = 1
    
If Calc = 1 Then
    TxtEdit5 = TxtEdit4
        TxtEdit4 = " = "
            End If
        
        
Test = "": Opérande = "": BTPoint = True

End Sub

Private Sub BTEsc_Click()

Unload Me

End Sub

Private Sub BtLog_Click()
On Error GoTo ErreurTrouver

    Opérande = "Log"
    TxtEdit1 = 0
    TxtEdit3 = 0
    TxtEdit3 = Log(Val(TxtEdit2))

Test = "": TxtEdit4 = "log": TextFormat = 1: BTPoint = True

ErreurTrouver:
End Sub

Private Sub BtMoins_Click()

If Opérande = "" Then
    TxtEdit1 = TxtEdit2: Opérande = "-"
    TxtEdit3 = 0
    Else
    TxtEdit3 = Val(TxtEdit1) - Val(TxtEdit2)
    End If

Test = "": TxtEdit4 = " - ": TxtEdit2 = 0: BTPoint = True

End Sub

Private Sub BtMultiple_Click()
If Opérande = "" Then
    TxtEdit1 = TxtEdit2: TxtEdit3 = 0
    ElseIf Opérande = "Pi" Then
    TxtEdit1 = TxtEdit2: TxtEdit3 = 0
    TxtEdit3 = Val(TxtEdit1) * Val(TxtEdit2): TextFormat = 1
    Else
    TxtEdit3 = Val(TxtEdit1) * Val(TxtEdit2)
    End If

Test = "": TxtEdit4 = " X ": Opérande = "X": TxtEdit2 = 0: BTPoint = True

End Sub

Private Sub BtPi_Click()
TxtEdit2 = "3.1415926535897932384626433832795"
Test = ""
TextFormat = 1
Opérande = "Pi"
BTPoint = True

End Sub

Private Sub BtPlus_Click()

If Opérande = "" Then
    TxtEdit1 = TxtEdit2: Opérande = "+"
    TxtEdit3 = 0
    Else
    TxtEdit3 = Val(TxtEdit1) + Val(TxtEdit2)
    End If

Test = "": TxtEdit4 = " + ": TxtEdit2 = 0
BTPoint = True

End Sub

Private Sub BtPourcent_Click()
Opérande = "%"
    X = Val(TxtEdit1) * Val(TxtEdit2)
    TxtEdit3 = X / 100

Test = "": TxtEdit4 = "%": BTPoint = True

End Sub

Private Sub BtRacineCarré_Click()
On Error GoTo ErreurTrouver
    Opérande = "RaCarré"
    TxtEdit1 = 0
    TxtEdit3 = 0
    TxtEdit3 = Sqr(TxtEdit2)

Test = "": TxtEdit4 = "RC": TextFormat = 1: BTPoint = True

ErreurTrouver:

End Sub

Private Sub BtRnd_Click()
Randomize
X = Int((Rnd) * 1000)
TxtEdit3 = X
TxtEdit1 = 0
TxtEdit2 = 0
TextFormat = 1
BTPoint = True

End Sub

Private Sub BtSecante_Click()
On Error GoTo ErreurTrouver
    Opérande = "Cos"
    TxtEdit1 = 0
    TxtEdit3 = 0
    TxtEdit3 = Cos(Val(TxtEdit2))

Test = "": TxtEdit4 = "cos": TextFormat = 1: BTPoint = True

ErreurTrouver:

End Sub

Private Sub BtSinus_Click()
On Error GoTo ErreurTrouver
    Opérande = "Sin"
    TxtEdit3 = Sin(Val(TxtEdit2))
    
TxtEdit1 = 0: Test = "": TxtEdit4 = "sin": TextFormat = 1: BTPoint = True

ErreurTrouver:

End Sub

Private Sub BtTan_Click()
On Error GoTo ErreurTrouver
    Opérande = "Tan"
    TxtEdit1 = 0
    TxtEdit3 = 0
    TxtEdit3 = Tan(Val(TxtEdit2))

Test = "": TxtEdit4 = "tan": TextFormat = 1: BTPoint = True

ErreurTrouver:

End Sub

Private Sub BtVirgule_Click()
    If BTPoint = False Then Exit Sub
    Test = Test + "."
    TxtEdit2 = Test
    BTPoint = False
End Sub

Private Sub Command1_Click()

Menu.ActiveForm.ActiveControl.SelText = Text4.Text

End Sub

Private Sub Command2_Click()
Frame1.Visible = False
Frame2.Visible = True

End Sub

Private Sub Command3_Click()
Frame1.Visible = True
Frame2.Visible = False

End Sub

Private Sub Command4_Click()
Clipboard.Clear
 Clipboard.SetText Text1.Text

End Sub

Private Sub Command5_Click()
Clipboard.Clear
 Clipboard.SetText Text2.Text

End Sub

Private Sub Command6_Click()
Menu.ActiveForm.ActiveControl.SelText = CDE

End Sub

Private Sub Command7_Click()
MenuDécimal.Visible = False
Me.Caption = "          Calculatrice active ..."

End Sub

Private Sub Form_Load()
Left = (Screen.Width - Width) / 2
Top = (Screen.Height - Height) / 2

Opérande = "": Test = "": Mémoire = ""

TxtEdit1.Text = 0
TxtEdit2.Text = 0
TxtEdit3.Text = 0

BTPoint = True
ValeurBTDécimale = False

DEC_Width_Moins = Width
DEC_Width_Plus = Width * 2

On Error GoTo ErrorTrouver

'Menu.ActiveForm.ActiveControl.SelText = Text4.Text
'Menu.ActiveForm.ActiveControl.SelText = CDE

ErrorTrouver:
Command1.Enabled = False
Command6.Enabled = False
Exit Sub

End Sub

Private Sub Form_Unload(Cancel As Integer)
Test = ""

End Sub

Private Sub Text3_Change()
If Len(Text3) > 2 Then Text3 = ""

Dim A, B, X, T1, T2
If Len(Text3) > 0 Then
    A = Text3:    B = Asc(A): X = Hex(B)
        T1 = "CDE1() =" + Chr(34) + Text3 + Chr(34) + ": "
        T2 = "CDE2() =" + Chr(34) + "\'" + X + Chr(34)
        Text1.Text = T1 + T2
        Text2.Text = "chr(" + Str(B) + ")"
        
        End If

End Sub

Private Sub Text5_Change()
If Len(Text5) > 1 Then Text3 = ""

Dim A, B, X, T1, T2
If Len(Text5) > 0 Then
    A = Text5:    B = Asc(A): X = Hex(B)
        T1 = "CDE1() =" + Chr(34) + Text5 + Chr(34) + ": "
        T2 = "CDE2() =" + Chr(34) + "\'" + X + Chr(34)
        Text1.Text = T1 + T2
        Text2.Text = "chr(" + Str(B) + ")"
        
        End If

End Sub

Private Sub TxtEdit1_Change()
TxtEdit1 = Format(TxtEdit1, "### ### ### ### ##0.00#")

End Sub

Private Sub TxtEdit2_Change()
Dim Y, X, Z
If TextFormat = 1 Then
    TxtEdit2 = Format(TxtEdit2, "### ### ### ### ##0.00# ###")
    ElseIf InStr(Test, ".") > 0 Then
    X = InStr(Test, "."): Y = Len(Test): Z = X + 1
    If (X + 1) = Y Then TxtEdit2 = Test
    If (X + 1) > Y Then TxtEdit2 = Format(TxtEdit2, "### ### ### ### ##0.00# ###")
    Else
        TxtEdit2 = Format(TxtEdit2, "###0.00")
    End If

TextFormat = 0
   
End Sub

Private Sub Txtedit3_Change()

If TextFormat = 1 Then
    TxtEdit3 = Format(TxtEdit3, "### ### ### ### ### ##0.00#")
    Else
    TxtEdit3 = Format(TxtEdit3, "### ### ### ### ### ##0.00#")
    End If
    
TextFormat = 0
    
End Sub

Conclusion :


Vous aurez fais mieux j'en suis sur mais bon, faut bien un début à tout ! Critique accepté !

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.