VISUAL BASIC_6
 

5. Projects using Intrinsic and Professional ActiveX Controls(4)


2. Project for Drawing  a Piechart:

The Piechart application uses the Circle method to draw pie charts with connected arcs.   Because a connected arc is a closed shape, it can also be filled with a pattern or a solid color as specified by the FillStyle and FillColor properties.

The program generates 10 random numbers in the range 20 to 100, stores them in the piedata() array, and then calculates the arc that corresponds to each number.   Because the total must be a full circle, each element of the piechart() array corresponds to an arc of 2*pi*piedata()/total.   Each slice’s starting angle is the ending angle of the previous slice, and its ending angle is the starting angle plus the angle corresponding to the element in the piedata array.

Drag two check boxes and three command buttons from the Toolbox, caption them, size them and position them as shown in the figure 3.   Open the code window of the command buttons and enter the codes as shown in the figure 4a..   Save and run the application.   The run mode window will appear as in the figure 4.


              Figure 3

Private Sub Command1_Click()

Dim pieData(10) As Integer

Form1.Cls

For i = 0 To 9

pieData(i) = 20 + Rnd() * 100

Total = Total + pieData(i)

Next

Form1.DrawWidth = 3

For i = 0 To 9

arc1 = arc2

arc2 = arc1 + 6.28 * pieData(i) / Total

If Check1.Value Then

Form1.FillStyle = 2 + (i Mod 5)

Else

Form1.FillStyle = 0

End If

If Check2.Value Then

Form1.FillColor = QBColor(8 + (i Mod 6))

Else

Form1.FillColor = QBColor(9)

End If

Form1.Circle (Form1.ScaleWidth / 2, Form1.ScaleHeight / 2), Form1.ScaleHeight / 2.5, , -arc1, -arc2

Next

End Sub

 

Private Sub Command2_Click()

End

End Sub

 

Private Sub Command3_Click()

Form1.Cls

End Sub

    Figure 4a 


                                Figure 4


 

Copyright © 2001 Selfonline-Education. All rights reserved.