dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] how to use mschart

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,112

    Resolved [RESOLVED] how to use mschart

    hey
    i have a form that called expenses
    that caulculates the money in spend lets say a tv or a car
    now i know there is a funcion in vb called ms chart that shows the grafh
    what i want to do is to make a graph with the months of the year
    and will show me how much i spend in may , april june and so on
    i relly need this to my projecct.
    this is the code for the of the form

    Code:
    Private Sub BttnDelete_Click()
        LsVw.SetFocus
        If MsgBox("?Delete", vbInformation + vbDefaultButton2 + vbYesNo, LsVw.SelectedItem) = vbNo Then Exit Sub
        
        Dim NewIdx As Long
        Set RS = CN.Execute("DELETE * FROM Expenses WHERE ExpID= " & LsVw.SelectedItem.Tag)
        With LsVw
            NewIdx = IIf(.SelectedItem.Index = .ListItems.Count, .ListItems.Count - 1, .SelectedItem.Index)
            .ListItems.Remove .SelectedItem.Index
            If .ListItems.Count > 0 Then Set .SelectedItem = .ListItems(NewIdx)
        End With
    End Sub
    
    Private Sub bttnreport_Click()
    Set dtrrpt.DataSource = CN.Execute("select * from expenses ")
    dtrrpt.show 1
    End Sub
    
    Private Sub Form_Load()
     
     
         Me.WindowState = 2
        LsVw.ColumnHeaders(1).Icon = "asc"
        Set RS = CN.Execute("SELECT * FROM Expenses ORDER BY ExpDate")
        While Not RS.EOF
            Set Itm = LsVw.ListItems.Add(, , Format(RS!ExpDate, "dd/mm/yyyy"), , "dolar")
            Itm.Tag = RS!ExpID
            Itm.SubItems(1) = RS!ExpType
            Itm.SubItems(2) = RS!ExpQuantity
            Itm.SubItems(3) = RS!ExpCost
            RS.MoveNext
        Wend
        ListRTL LsVw
            mLVClrHdr.HookToLV LsVw.hwnd, True
        mLVClrHdr.glHdrBkClr = &HD1B499
        mLVClrHdr.glHdrTextClr = vbWhite
        m_hookedLV = True
    End Sub
    
    Private Sub BttnBack_Click()
        Unload Me
    End Sub
    
     
    
    Private Sub BttnEdit_Click()
        NewRec = False
        LsVw.SetFocus
        FrmNewExpense.show 1
    End Sub
    
    Private Sub BttnNew_Click()
        NewRec = True
        LsVw.SetFocus
        FrmNewExpense.show 1
    End Sub
    
    Private Sub LsVw_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
        If ColumnHeader.Index = 1 Then
            LsVw.ListItems.clear
            ColumnHeader.Icon = IIf(ColumnHeader.Icon = "asc", "desc", "asc")
        
            If ColumnHeader.Icon = "asc" Then
                Set RS = CN.Execute("SELECT * FROM Expenses ORDER BY ExpDate")
            Else
                Set RS = CN.Execute("SELECT * FROM Expenses ORDER BY ExpDate DESC")
            End If
        
            LsVw.ListItems.clear
            While Not RS.EOF
                Set Itm = LsVw.ListItems.Add(, , Format(RS!ExpDate, "dd/mm/yyyy"), , "dolar")
                Itm.Tag = RS!ExpID
                Itm.SubItems(1) = RS!ExpType
                Itm.SubItems(2) = RS!ExpQuantity
                Itm.SubItems(3) = RS!ExpCost
                RS.MoveNext
            Wend
        End If
    End Sub
    
    Private Sub lvButtons_H5_Click()
    
    End Sub
    
    Private Sub refresh_Click()
    LsVw.refresh
    End Sub
    
    Private Sub report_Click()
    
    End Sub
    
    Private Sub Tmr_Timer()
     If LsVw.ListItems.Count = 0 Then
            BttnEdit.Enabled = False
            BttnDelete.Enabled = False
            TxtQuantity.text = 0
            TxtCost.text = FormatCurrency(CStr(0), 2)   
            Exit Sub
        Else
            BttnEdit.Enabled = True
            BttnDelete.Enabled = True
        End If
        Set RS = CN.Execute("SELECT SUM(ExpQuantity) as SumQ, SUM(ExpCost) as SumC FROM Expenses")
        If RS.EOF Then
            TxtQuantity.text = 0
            TxtCost.text = CStr(0)
        Else
            TxtQuantity.text = RS!SumQ
            TxtCost.text = CStr(RS!SumC)
        End If
        TxtCost.text = FormatCurrency(TxtCost.text, 2)
     
    
    
    
     
    End Sub
    Private Sub Form_Resize()
    If MDImain.WindowState <> 2 Then Exit Sub
        
        With LsVw
            .Width = Me.Width - 500
            .Height = Me.Height - 1800
            .Left = ((Me.Width - .Width) / 2) - 50
            For I = 1 To 4
                .ColumnHeaders(I).Width = .Width / 4 - 110
            Next
        
            bttnreport.Top = .Top + .Height + 200
            lvButtons_H2.Top = .Top + .Height + 300
            BttnDelete.Top = .Top + .Height + 200
            lvButtons_H3.Top = .Top + .Height + 300
            BttnEdit.Top = .Top + .Height + 200
            lvButtons_H1.Top = .Top + .Height + 300
            BttnNew.Top = .Top + .Height + 200
            lvButtons_H4.Top = .Top + .Height + 300
            Label1.Top = .Top + .Height + 100
            Label2.Top = .Top + .Height + 600
            TxtQuantity.Top = .Top + .Height + 100
            TxtCost.Top = .Top + .Height + 500
            TxtQuantity.Left = .Left + 10
            TxtCost.Left = .Left + 10
            Label1.Left = .Left + 1850
            Label2.Left = .Left + 2100
    
        End With
        DoEvents
    End Sub
    im just looking for guidnes and some pointers
    tnx for the help
    Last edited by salsa31; Jun 11th, 2013 at 02:50 PM.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: how to use mschart

    Quote Originally Posted by salsa31 View Post
    im just looking for guidnes and some pointers
    See Using the MSChart Control.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,112

    Re: how to use mschart

    i know that
    but how to start coding it?

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: how to use mschart

    Quote Originally Posted by salsa31 View Post
    i know that
    but how to start coding it?
    Did you read the given article? It has plenty of explanations, examples and diagrams to help you get going. It is much more comprehensive than anything I can give you in a single post. If you still feel that that article is incomplete, I'm sure Google will help you find more tutorials about that control.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,112

    Re: how to use mschart

    i am reading this yes
    but it dosnt say anything about months of the year

  6. #6
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: how to use mschart

    After learning how to use the ChartData property of the MSChart control from the given example in the online documentation (this is the first time I've played with this control), I came up with the following simple example which you can modify to suit your needs:

    Code:
    Option Explicit     'Add an MSChart control to a blank Form
    
    Private Sub Form_Activate()
        Dim i As Integer, vntArray(1 To 12, 1 To 2) As Variant
    
        For i = 1 To 12
            vntArray(i, 1) = Choose(i, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
            vntArray(i, 2) = i
        Next
    
        MSChart1.ChartData = vntArray
    End Sub
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,112

    Re: how to use mschart

    tnx bonnie
    1 problem
    i need the months to be from right to left and to show me in another language.
    do i need to set something there like format months or something like that?

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: how to use mschart

    The Adding Labels to the Chart section of the article linked to in post #2 shows you how to achieve that:

    Quote Originally Posted by MSDN
    Adding Labels to the Chart

    When you create a multi-dimensioned array, the first series can be assigned a string; when the array is assigned to the ChartData property, the strings become the labels for the rows. The following code shows this feature. Read more...
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,112

    Re: how to use mschart

    tnkyou

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width