Representation graphique des intervalles

Contenu du snippet

Ce code doit representer des intervalles en utilisant des lignes horizontales dans Excel. Par exemple, pour representer les intervalles [1, 2] et [1.5, 3] on obtient une representation comme:

........1<................>2
................1.5.<.....................>3

Les nombres 1, 2, 1.5, 3 sont lu dans des cellules de Excel.

Source / Exemple :


Sub Macro3()

ActiveSheet.Lines.Delete

Dim haut As Double
Dim inf1 As Double
Dim sup1 As Double
Dim inf2 As Double
Dim sup2 As Double
Dim position As Double

haut = 65
inf1 = Range("A1").Value
sup1 = Range("A2").Value
inf2 = Range("B1").Value
sup2 = Range("B2").Value

If (inf1 <= 10) And (inf2 <= 10) Then
    inf1 = inf1 * 50
    inf2 = inf2 * 50
    sup1 = sup1 * 50
    sup2 = sup2 * 50

    Else

    If (10 < inf1) And (inf1 < 100) And (10 < inf2) And (inf2 < 100) Then
        inf1 = inf1 * 5
        inf2 = inf2 * 5
        sup1 = sup1 * 5
        sup2 = sup2 * 5
 
        Else
 
            If (100 <= inf1) And (inf1 < 1000) And (100 <= inf2) And (inf2 < 1000) Then
                inf1 = inf1 / 5
                inf2 = inf2 / 5
               sup1 = sup1 / 5
               sup2 = sup2 / 5
 
            End If
        End If
End If
 

ActiveSheet.Shapes.AddLine(inf1#, haut, sup1#, haut).Select
Selection.ShapeRange.Line.Weight = 1.5
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.DashStyle = msoLineSquareDot
Selection.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadOpen
Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadOpen
Selection.ShapeRange.Line.BeginArrowheadWidth = msoArrowheadWidthMedium
Selection.ShapeRange.Line.BeginArrowheadLength = msoArrowheadLengthMedium
Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
Selection.ShapeRange.Line.Visible = msoTrue
If inf1 < inf2 Then
    position = inf1 + Abs(inf1 - inf2)
    ActiveSheet.Shapes.AddLine(position, haut + 12.5, position + Abs(position - sup2), haut + 12.5).Select
    Else
        position = inf1 - Abs(inf1 - inf2)
        ActiveSheet.Shapes.AddLine(position, haut + 12.5, position + Abs(position - sup2), haut + 12.5).Select
End If
Selection.ShapeRange.Line.Weight = 1.5
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.DashStyle = msoLineSquareDot
Selection.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadOpen
Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadOpen
Selection.ShapeRange.Line.BeginArrowheadWidth = msoArrowheadWidthMedium
Selection.ShapeRange.Line.BeginArrowheadLength = msoArrowheadLengthMedium
Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
Selection.ShapeRange.Line.Visible = msoTrue

End Sub

Conclusion :


Ce code marche pour les intervalles qui ne sont pas très grands, mais il y a encore pas mal de problèmes:

1. Je n'ai pas encore réussi à représenter les intervalles du genre [a, b] avec a<0 et b>0.
2. Comme le tracé d'une ligne dépend des deux extrémités qui sont exprimés en coordonnées (x1, y1) et (x2, y2), ceci pose beaucoup de problème pour faire une echelle convenable.

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.