Conversions d'angles

Description

Ce code sert à convertir un angle dans un autre format.
Type de conversion possible :
- Convertir des degrés décimaux en radians
- Convertir des degrés décimaux en degrés sexagésimaux
- Convertir des degrés sexagésimaux en degrés décimaux
- Convertir des degrés sexagésimaux en radians
- Convertir des radians en degrés décimaux
- Convertir des radians en degrés sexagésimaux

Source / Exemple :


Const PI = 3.14159265358979

Private Sub Angle_Change()
If Angle.ListIndex < 0 Then
Angle.ListIndex = 0
End If
End Sub

Private Sub Calculer_Click()
If Valeur.Text = "" Then
MsgBox "Vous devez entrer une valeur d'angle", vbInformation, "Valeur manquante"
Exit Sub
End If

If Angle.ListIndex = 0 Then
DegréRadian
End If
If Angle.ListIndex = 1 Then
DegréSexa
End If
If Angle.ListIndex = 2 Then
    If Deg.Text < 0 Then
    MsgBox "La valeur DEGRE de l'angle ne peut être négative", vbInformation, "Valeur incorrecte"
    Exit Sub
    End If
    If Min.Text > 60 Then
    MsgBox "La valeur MINUTE de l'angle ne peut être supérieure à 60", vbInformation, "Valeur incorrecte"
    Exit Sub
    End If
    If Sec.Text > 60 Then
    MsgBox "La valeur SECONDE de l'angle ne peut être supérieure à 60", vbInformation, "Valeur incorrecte"
    Exit Sub
    End If
SexaRadian
End If
If Angle.ListIndex = 3 Then
    If Deg.Text < 0 Then
    MsgBox "La valeur DEGRE de l'angle ne peut être négative", vbInformation, "Valeur incorrecte"
    Exit Sub
    End If
    If Min.Text > 60 Then
    MsgBox "La valeur MINUTE de l'angle ne peut être supérieure à 60", vbInformation, "Valeur incorrecte"
    Exit Sub
    End If
    If Sec.Text > 60 Then
    MsgBox "La valeur SECONDE de l'angle ne peut être supérieure à 60", vbInformation, "Valeur incorrecte"
    Exit Sub
    End If
SexaDegré
End If
If Angle.ListIndex = 4 Then
RadianDegré
End If
If Angle.ListIndex = 5 Then
RadianSexa
End If
End Sub

Private Sub Angle_Click()
If Angle.ListIndex = 0 Then
Frame2.Caption = "Résultat en radian"
Valeur.Visible = True
Deg.Visible = False
Min.Visible = False
Sec.Visible = False
Label4.Visible = False
Label6.Visible = False
Label7.Visible = False
Valeur.Text = 0
Reponse.Text = 0
degres.Text = ""
minutes.Text = ""
secondes.Text = ""
SecInter.Text = ""
ValInter.Text = ""
Deg.Text = 0
Min.Text = 0
Sec.Text = 0
End If
If Angle.ListIndex = 1 Then
Frame2.Caption = "Résultat en degré sexagésimal"
Valeur.Visible = True
Deg.Visible = False
Min.Visible = False
Sec.Visible = False
Label4.Visible = False
Label6.Visible = False
Label7.Visible = False
Valeur.Text = 0
Reponse.Text = 0
degres.Text = ""
minutes.Text = ""
secondes.Text = ""
SecInter.Text = ""
ValInter.Text = ""
Deg.Text = 0
Min.Text = 0
Sec.Text = 0
End If
If Angle.ListIndex = 2 Then
Frame2.Caption = "Résultat en radian"
Valeur.Visible = False
Deg.Visible = True
Min.Visible = True
Sec.Visible = True
Label4.Visible = True
Label6.Visible = True
Label7.Visible = True
Valeur.Text = 0
Reponse.Text = 0
degres.Text = ""
minutes.Text = ""
secondes.Text = ""
SecInter.Text = ""
ValInter.Text = ""
Deg.Text = 0
Min.Text = 0
Sec.Text = 0
End If
If Angle.ListIndex = 3 Then
Frame2.Caption = "Résultat en degré décimal"
Valeur.Visible = False
Deg.Visible = True
Min.Visible = True
Sec.Visible = True
Label4.Visible = True
Label6.Visible = True
Label7.Visible = True
Valeur.Text = 0
Reponse.Text = 0
degres.Text = ""
minutes.Text = ""
secondes.Text = ""
SecInter.Text = ""
ValInter.Text = ""
Deg.Text = 0
Min.Text = 0
Sec.Text = 0
End If
If Angle.ListIndex = 4 Then
Frame2.Caption = "Résultat en degré décimal"
Valeur.Visible = True
Deg.Visible = False
Min.Visible = False
Sec.Visible = False
Label4.Visible = False
Label6.Visible = False
Label7.Visible = False
Valeur.Text = 0
Reponse.Text = 0
degres.Text = ""
minutes.Text = ""
secondes.Text = ""
SecInter.Text = ""
ValInter.Text = ""
Deg.Text = 0
Min.Text = 0
Sec.Text = 0
End If
If Angle.ListIndex = 5 Then
Frame2.Caption = "Résultat en degré sexagésimal"
Valeur.Visible = True
Deg.Visible = False
Min.Visible = False
Sec.Visible = False
Label4.Visible = False
Label6.Visible = False
Label7.Visible = False
Valeur.Text = 0
Reponse.Text = 0
degres.Text = ""
minutes.Text = ""
secondes.Text = ""
SecInter.Text = ""
ValInter.Text = ""
Deg.Text = 0
Min.Text = 0
Sec.Text = 0
End If
End Sub

Private Sub SexaDegré()
Reponse.Text = Deg.Text + ((Min.Text * 60) + Sec.Text) / 3600
End Sub

Private Sub SexaRadian()
Reponse.Text = Deg.Text + ((Min.Text * 60) + Sec.Text) / 3600
Reponse.Text = (Reponse.Text * PI) / 180                     
End Sub

Private Sub Deg_KeyPress(KeyAscii As Integer)
If InStr("1234567890" & Chr(8), Chr$(KeyAscii)) = 0 Then 
KeyAscii = 0
End If
End Sub

Private Sub Form_Load()
Angle.ListIndex = 0
End Sub

Private Sub Min_KeyPress(KeyAscii As Integer)
If InStr("1234567890" & Chr(8), Chr$(KeyAscii)) = 0 Then 
KeyAscii = 0
End If
End Sub

Private Sub Sec_KeyPress(KeyAscii As Integer)
If InStr("1234567890" & Chr(8), Chr$(KeyAscii)) = 0 Then 
KeyAscii = 0
End If
End Sub

Private Sub Valeur_KeyPress(KeyAscii As Integer)
If InStr("1234567890," & Chr(8), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub

Private Sub DegréRadian()
Reponse.Text = (Valeur.Text * PI) / 180 
End Sub

Private Sub RadianDegré()
Reponse.Text = (Valeur.Text * 180) / PI 
End Sub

Private Sub DegréSexa() 
Dim Trouver As String
Dim Virgule

Virgule = ","
Trouver = InStr(Valeur.Text, Virgule)
Valeur.SetFocus
Valeur.SelStart = Trouver - 1
Valeur.SelLength = 3 
Clipboard.SetText (Valeur.SelText)
minutes.SetFocus
minutes.SelText = Clipboard.GetText
minutes.SetFocus
minutes.SelStart = 0
minutes.SelLength = 1
Clipboard.SetText (minutes.SelText)      
minutes.SelText = ""                
minutes.Text = (minutes.Text * 60) / 100
SecInter.Text = minutes.Text
minutes.Text = Left$(minutes.Text, 2)

Virgule = ","
Trouver = InStr(SecInter.Text, Virgule)
SecInter.SetFocus
SecInter.SelStart = Trouver - 1
SecInter.SelLength = 3 
Clipboard.SetText (SecInter.SelText)
secondes.SetFocus
secondes.SelText = Clipboard.GetText
secondes.SetFocus
secondes.SelStart = 0 
secondes.SelLength = 1
Clipboard.SetText (secondes.SelText)              
secondes.SelText = ""
secondes.Text = (secondes.Text * 60) / 10

degres.Text = Valeur.Text
Virgule = ","
Trouver = InStr(degres.Text, Virgule)
degres.SetFocus
degres.SelStart = Trouver - 1
degres.SelLength = 255
Clipboard.SetText (degres.SelText)
degres.SelText = ""

Reponse.Text = degres.Text & "°" & minutes.Text & "'" & secondes.Text & "''" 
End Sub

Private Sub RadianSexa()
Dim Trouver As String
Dim Virgule

ValInter = (Valeur.Text * 180) / PI

Virgule = ","
Trouver = InStr(ValInter, Virgule)
ValInter.SetFocus
ValInter.SelStart = Trouver - 1
ValInter.SelLength = 3
Clipboard.SetText (ValInter.SelText)
minutes.SetFocus
minutes.SelText = Clipboard.GetText
minutes.SetFocus
minutes.SelStart = 0
minutes.SelLength = 1
Clipboard.SetText (minutes.SelText)
minutes.SelText = ""
minutes.Text = (minutes.Text * 60) / 100
SecInter.Text = minutes.Text
minutes.Text = Left$(minutes.Text, 2)

Virgule = ","
Trouver = InStr(SecInter.Text, Virgule)
SecInter.SetFocus
SecInter.SelStart = Trouver - 1
SecInter.SelLength = 3
Clipboard.SetText (SecInter.SelText)
secondes.SetFocus
secondes.SelText = Clipboard.GetText
secondes.SetFocus
secondes.SelStart = 0
secondes.SelLength = 1
Clipboard.SetText (secondes.SelText)
secondes.SelText = ""
secondes.Text = (secondes.Text * 60) / 10

degres.Text = ValInter.Text
Virgule = ","
Trouver = InStr(degres.Text, Virgule)
degres.SetFocus
degres.SelStart = Trouver - 1
degres.SelLength = 255
Clipboard.SetText (degres.SelText)
degres.SelText = ""

Reponse.Text = degres.Text & "°" & minutes.Text & "'" & secondes.Text & "''" 
End Sub

Conclusion :


Ce petit programme est en réalité une partie d'un autre programme de math beaucoup plus grand actuellement en préparation

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.

Du même auteur (visualstar)