2 Replies - 1159 Views - Last Post: 28 March 2013 - 11:55 AM Rate Topic: -----

#1 aswa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-February 13

drawing a pie chart

Posted 28 March 2013 - 09:12 AM

I have this code that is supposed to draw a pie chart-


Public angle1, angle2 As Double

 Option Explicit
-------------------------
Private Sub Form_Load()
       Dim timediff, personAtotal,personBtotal As Integer
       
       personAtotal=0
	personBtotal=0 

        
        Picture1.ScaleMode = vbPixels
        Set cn = New ADODB.connection
        cn.Open "Provider=Microsoft.Jet.Oledb.4.0; data source =" & cnDir & "\Database\db.mdb; Persist Security Info=False;Jet OLEDB:"
	Set rs = New ADODB.Recordset
	rs.Open "Select * from Log", cn, adOpenStatic, adLockOptimistic
        rs.MoveFirst
        
        With rs
            While .EOF = False
                timediff = DateTime.DateDiff("n", .Fields(4).value, .Fields(3).value)
                'MsgBox "diff value-" & timediff
                    If .Fields(0).value = "aswa" Then
                        personAtotal = personAtotal + timediff
                    ElseIf .Fields(0).value = "sharon" Then
                        personBtotal = personBtotal + timediff
                     EndIf    

		.MoveNext
            Wend
        End With
        
        
        MsgBox "total for person A-" & personAtotal
        MsgBox "for person B-" & personBtotal
        
            angle1 = personAtotal * 100 / (personAtotal + personBtotal)
	    angle2 = personBtotal * 100 / (personAtotal + personBtotal)
            
            
        MsgBox "angle 1-" & angle1
            MsgBox "angle 2-" & angle2
            
'            
 End Sub
---------------------
 Private Sub DrawPiePiece(lColor As Long, fStart As Double, fEnd As Double)

        
        Dim PI As Double
        Dim CircleEnd As Double
        PI = 3.14159265359
        CircleEnd = -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 (100, 100), 60, , dStart, dEnd
 End Sub


--------------------
Private Sub Option1_Click()
 Call DrawPiePiece(QBColor(1), 0.001, angle1)
        	Call DrawPiePiece(QBColor(4), angle1, 99.999)          

      
End Sub



when i run this, it says Byref type mismatch, and option1 function gets highlighted.

but if i change option1_click to this, it works-
Private Sub Option1_Click()

	Dim funcangle As Double
	MsgBox "angle 1-" & angle1
	funcangle = angle1		\\it works if i do this. but if i directly use angle1 it doesn't
        
        	Call DrawPiePiece(QBColor(1), 0.001, funcangle)
        	Call DrawPiePiece(QBColor(4), funcangle, 99.999)          

      
End Sub     



also,
i get the value when i print it in option1..so the value does get passed.
what am i doing wrong?
Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: drawing a pie chart

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,755
  • Joined: 26-March 09

Re: drawing a pie chart

Posted 28 March 2013 - 10:57 AM

Angle1 is declared as a variant in your code, the DrawPie function expects a double

Public angle1, angle2 As Double


To declare them both as double you need to explicitly define them

Public angle1 As Double, angle2 As Double

This post has been edited by maj3091: 28 March 2013 - 10:58 AM

Was This Post Helpful? 0
  • +
  • -

#3 aswa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-February 13

Re: drawing a pie chart

Posted 28 March 2013 - 11:55 AM

View Postmaj3091, on 28 March 2013 - 10:57 AM, said:

Angle1 is declared as a variant in your code, the DrawPie function expects a double

Public angle1, angle2 As Double


To declare them both as double you need to explicitly define them

Public angle1 As Double, angle2 As Double


Thank yo so much!
It works now :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1