CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: VB6 - Pie Chart

  1. #1
    Join Date
    Feb 2011
    Posts
    4

    Smile VB6 - Pie Chart

    I have written the following code to draw a pie chart in picture box and the code is working fine if it is put inside button click. But the same code is not working in form load. Neither it is throwing some error. Can anyone tel why it is like that?

    Private Sub Form_Load()

    Picture1.BackColor = &H8000000E
    Picture1.ScaleMode = vbPixels

    Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    With conn
    .Provider = "Microsoft.JET.OLEDB.4.0"
    .Open "C:\Class database\CLASS.mdb"
    End With

    Dim sql As String
    If rs.State = adStateOpen Then rs.Close
    sql = "Select * from "
    rs.Open sql, conn, adOpenStatic, adLockBatchOptimistic

    Dim rs1 As New ADODB.Recordset
    If rs1.State = adStateOpen Then rs.Close
    sql = "Select * from "
    rs1.Open sql, conn, adOpenStatic, adLockBatchOptimistic

    Dim rs2 As New ADODB.Recordset
    If rs2.State = adStateOpen Then rs.Close
    sql = "Select * from "
    rs2.Open sql, conn, adOpenStatic, adLockBatchOptimistic

    Dim rs3 As New ADODB.Recordset
    If rs3.State = adStateOpen Then rs.Close
    sql = "Select * from "
    rs3.Open sql, conn, adOpenStatic, adLockBatchOptimistic

    Dim rs4 As New ADODB.Recordset
    If rs4.State = adStateOpen Then rs.Close
    sql = "Select * from "
    rs4.Open sql, conn, adOpenStatic, adLockBatchOptimistic

    Dim w, x, y, z, z1 As Double
    w = rs.RecordCount
    x = rs1.RecordCount
    y = rs2.RecordCount
    z = rs3.RecordCount
    z1 = rs4.RecordCount


    Dim xx, yy, zz, uu As Double
    If w = 0 Then MsgBox "There are no records for" & DateTime.Date & "to be displayed"
    If w > 0 Then
    xx = (x * 100) / w
    yy = xx + (y * 100) / w
    zz = yy + (z * 100) / w
    uu = zz + (z1 * 100) / w
    Call DrawPiePiece(QBColor(1), 0.001, xx)
    Call DrawPiePiece(QBColor(6), xx, yy)
    Call DrawPiePiece(QBColor(3), yy, zz)
    Call DrawPiePiece(QBColor(5), zz, uu)
    End If


    End Sub

    Public Sub DrawPiePiece(lColor As Long, ByVal fStart As Double, ByVal fEnd As Double)
    Const PI As Double = 3.14159265359
    Const CircleEnd As Double = -2 * PI
    Dim dStart As Double
    Dim dEnd As Double
    Picture1.FillColor = lColor
    Picture1.FillStyle = 0
    dStart = fStart * (CircleEnd / 100)
    dEnd = fEnd * (CircleEnd / 100)
    Picture1.Circle (170, 150), 100, , dStart, dEnd
    End Sub

  2. #2
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Re: VB6 - Pie Chart

    If there is no error being generated then I am assuming that the picture box is 'blank' if you run from form load.

    Have you tried setting the AutoRedraw property of the picturebox to True?

    Picture1.AutoRedraw = True at the start of Form_Load event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured