Gantt Software VARCHART XGantt ActiveX

Started by Jean-pierre Leroy, March 16, 2011, 06:24:37 PM

Previous topic - Next topic

Jean-pierre Leroy

Dear FF users,

For my company I need to include a Gantt chart in one of our application.

I searched on Internet and found a module called VARCHART XGantt ActiveX from NETRONIC Software GmbH
http://www.netronic.com/gantt/gantt-software.html

For those interested, the demo of the ActiveX version is available here
http://www.netronic.com/gantt/gantt-software/free-gantt-chart.html#c37

This module seems very powerful; following the FireFly3 help file section called  "Working with OCX/ActiveX Controls" I was able to integrate the OCX and view the Gantt Chart (see the enclosed screen shot).

Now I have some difficulties to set some properties; here is the sample VB code I would like to translate to PB+FF:

Example Code from the Manual page 31/32:

Set dataTable = VcGantt1.DataTableCollection.DataTableByName("Maindata")
Set dataRecCltn = dataTable.DataRecordCollection
dataRecCltn.Add "1;Node 1;07.05.2007;;5"
dataRecCltn.Add "2;Node 2;14.05.2007;;5"
dataRecCltn.Add "3;Node 3;21.05.2007;;5"

Set dataTable =
VcGantt1.DataTableCollection.DataTableByName("Relations")
Set dataRecCltn = dataTable.DataRecordCollection
dataRecCltn.Add "1;1;2"
dataRecCltn.Add "2;2;3"
VcGantt1.EndLoading


I have also another question regarding the TypeLib Browser utility made by Jose Roca; which options need to be set ? what are the best practices ? for the "Events" code I get the error "ERROR 426: VARIABLE EXPECTED" if I don't tick the option "add prefix to parameter names".

Any guidance how to use this component will be helpful.

Thank you for your help.
Jean-Pierre

José Roca

Quote
I have also another question regarding the TypeLib Browser utility made by Jose Roca; which options need to be set ? what are the best practices ?

The only mandatory is the first one. The rest, depends on your preferences.

Quote
for the "Events" code I get the error "ERROR 426: VARIABLE EXPECTED" if I don't tick the option "add prefix to parameter names".

It must be a conflict with a PB keyword.

Quote
Example Code from the Manual page 31/32:

Very incomplete. How are we going to guess what kind of objects are dataTable, VcGantt1, etc.

Jean-pierre Leroy

#2
Hi Jose,

Thank you for your answers.

QuoteVery incomplete. How are we going to guess what kind of objects are dataTable, VcGantt1, etc.
Here is the complete VB code for the first example:


VERSION 5.00
Object = "{A4E79A23-C9E1-11CF-BDD7-02608C4302A9}#4.4#0"; "vcgantt.ocx"
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   9495
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   13275
   LinkTopic       =   "Form1"
   ScaleHeight     =   9495
   ScaleWidth      =   13275
   StartUpPosition =   3  'Windows-Standard
   WindowState     =   2  'Maximiert
   Begin VcGanttLib.VcGantt VcGantt1
      Height          =   9255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   13095
      _Version        =   262148
      _ExtentX        =   23098
      _ExtentY        =   16325
      _StockProps     =   64
      ConfigurationName=   "UserGuideSamples\XGantt_Tutorial01_App\VB Code\XGantt_Tutorial01_App.ini"
      InternalConfigurationContents=   "XGantt_Tutorial01_App.frx":0000
      InternalDataDefinitionContents=   "XGantt_Tutorial01_App.frx":7348
      BeginProperty DialogFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OLEDragMode     =   -1
      OLEDropMode     =   -1
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()

   VcGantt1.InsertNodeRecord ("1;Node 1;07.05.2010;;5")
   VcGantt1.InsertNodeRecord ("2;Node 2;14.05.2010;;5")
   VcGantt1.InsertNodeRecord ("3;Node 3;21.05.2010;;5")
   VcGantt1.InsertLinkRecord ("1;1;2")
   VcGantt1.InsertLinkRecord ("2;2;3")
   VcGantt1.EndLoading

   VcGantt1.OptimizeTimeScaleStartEnd (3)

   'calculate end date
   Dim node As VcNode

   For Each node In VcGantt1.NodeCollection
      SetNodeEndDate node
   Next
End Sub

Private Sub Form_Resize()
   Dim bottomMargin As Long
   Dim rightMargin As Long
   Dim tmpWidth As Long
   Dim tmpHeight As Long

   bottomMargin = 400
   rightMargin = 120

   tmpHeight = ScaleHeight - VcGantt1.Top - bottomMargin
   tmpWidth = ScaleWidth - VcGantt1.Left - rightMargin

   If tmpWidth > 0 And tmpHeight > 0 Then
      VcGantt1.Width = tmpWidth
      VcGantt1.Height = tmpHeight
   End If
End Sub

Private Sub SetNodeEndDate(ByVal node As VcNode)
    Dim tmpCal As VcCalendar
    Dim tmpDate As Date

    'Avoid empty duration or negative duration
    If node.DataField(4) = "" Or node.DataField(4) < 0 Then
        node.DataField(4) = "0"
    End If
    'Start date empty then end date should also be empty
    If node.DataField(2) = "31.12.1899 00:00:00" Then
        node.DataField(3) = ""
    Else
        'Precondition is property page nodes
        '"assign calendar to nodes" must be true
        Set tmpCal = VcGantt1.CalendarCollection.Active
        tmpDate = tmpCal.AddDuration(node.DataField(2), node.DataField(4))
        node.DataField(3) = tmpDate
        'Start date only in active times
        tmpDate = tmpCal.AddDuration(node.DataField(3), (-1) * node.DataField(4))
        node.DataField(2) = tmpDate
        node.UpdateNode
    End If
End Sub

Private Sub VcGantt1_OnNodeCreateCompleteEx(ByVal node As VcGanttLib.VcNode, ByVal creationType As VcGanttLib.CreationTypeEnum, ByVal isLastNodeInSeries As Boolean)
      Dim nodeCltn As VcNodeCollection

      node.DataField(1) = "Node " + node.DataField(0)
      node.MarkNode = False
      node.UpdateNode

      Set nodeCltn = VcGantt1.NodeCollection
      For Each node In VcGantt1.NodeCollection
         node.DataField(5) = 0
         node.UpdateNode
      Next
End Sub

Private Sub VcGantt1_OnNodeModifyCompleteEx(ByVal node As VcGanttLib.VcNode, ByVal modificationType As VcGanttLib.ModificationTypeEnum, ByVal isLastNodeInSeries As Boolean)
      SetNodeEndDate node
End Sub


I put also the complete VB project in the enclosed ZIP file.

Thanks,
Jean-Pierre

Robert Eaton

Hi Jean-Pierre,
Sorry but I can't claim to have 0.4% of clue about this stuff (less then 1/2 a clue  ;D  )
I have no need for this thing, but have been playing with it for several days to try to learn a little myself.

One thing I did just notice is that it looks like a lot of the variables that come out of the type lib browser conflict with PB variables. I believe that is the reason for the error you mentioned. For example:

  ' =====================================================================================
   Method KeyDown <-602> ( _
     ByRef KeyCode As Integer _                         ' [in] *KeyCode VT_I2 <Integer>
   , ByVal Shift As Integer _                           ' [in] Shift VT_I2 <Integer>
   )                                                    ' VOID

     ' *** Insert your code here ***

   End Method
   ' =====================================================================================


In the above "Shift" is being used as an integer variable but it is a PB keyword so it can't be used. So when you compile it throws the "Variable Expected" because it thinks the variable is missing.

It looks like there are lots of these. Might we worth going through the type lib code and renaming those to like xg_Shift, etc.

Of course, see my first statement, I might be totally wrong here  :o



Robert Eaton

Here is something else very odd.
I got 4 errors complaining of duplicate equates of ClsIDs. (Initially I had just commented them out.)

I finally deleted the project and started a new one. I discovered that with a project that is empty except for the gantt OCX control and just one of those ClsIDs in the include file I still get the error. Remove the control or that line and the error goes away.

So is this a Firefly error or a problem with the OCX?


José Roca

For conflicts with parameter names an keywords, check the option "Add prefix to parameter names". For conflicts with duplicate interface names, check the option "Use prefix in interface names".

It would be useful if somebody posts the output of the browser, with the interface definitions, etc. Otherwise, we are in the dark.

Robert Eaton

Jose, your guidance as always is greatly appreciated.
"Use prefix in interface names" did indeed fix dup problem.

Since it is rather large I have attached the include file (renamed to txt) that has the browser output with the events appended to the end.

Thanks,
Bob

José Roca

An OCX of the kind that I hate the most: only a dispatch interface and purposedly designed for VB.

Try this:


DIM VcGantt1 AS DISPATCH
VcGantt1 = OC_GetDispatch(HWND_FORM1_OCXCONTROL1)
DIM dataTableCollection AS DISPATCH
OBJECT GET VcGantt1.dataTableCollection TO dataTableCollection
DIM dataTable AS DISPATCH
DIM vPrm AS VARIANT
vPrm = "Maindata"
OBJECT CALL dataTableCollection.DataTableByName(vPrm) TO dataTable
DIM dataRecCltn AS DISPATCH
OBJECT GET dataTable.DataRecordCollection TO dataRecCltn
vprm = "1;Node 1;07.05.2007;;5"
OBJECT CALL dataRecCltn.Add(vPrm)
vprm = "2;Node 2;14.05.2007;;5"
OBJECT CALL dataRecCltn.Add(vPrm)
vprm = "3;Node 3;21.05.2007;;5"
OBJECT CALL dataRecCltn.Add(vPrm)


Robert Eaton

Thanks Jose.
I still get errors from what I earlier assumed to be a conflict with variable names and PB keywords.
Do you think I was correct about that?

José Roca

Remove all the interface definitions and keep only the constants and the event class (if you need it).

José Roca

Quote
Do you think I was correct about that?

Yes, of course, Reserved words can't be used as parameters.

Robert Eaton

Thanks again Jose.
I would have never guessed about leaving off the interface definitions.
This thing is a real exercise in "draining the swamp".

So it does compile now, but nothing is happening in the chart yet.
But this is at least a better starting point.
As I mentioned I'll never use this control myself. Just trying to learn a little bit.


Jean-pierre Leroy

Jose and Robert I complete the code ... but still nothing is displayed.

I don't know if the translation of the last VB Code line is correct.

VB CODE: VcGantt1.EndLoading
PB CODE: Object Call VcGantt1.EndLoading


'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long
   
    Dim VcGantt1            As Dispatch                     
    Dim vPrm                As Variant
    Dim dataTableCollection As Dispatch
    Dim dataTable           As Dispatch
    Dim dataRecCltn         As Dispatch
       
    VcGantt1 = OC_GetDispatch(HWND_FORM1_OCXCONTROL1)

    '------------------------------------------------------------------------
    ' VB:Object Let VcGantt1.DataTableCollection.DataTableByName = "Maindata"
    '------------------------------------------------------------------------       
    Object Get VcGantt1.dataTableCollection To dataTableCollection                       
    vPrm = "Maindata"   
    Object Call dataTableCollection.DataTableByName(vPrm) To dataTable
   
    '------------------------------------------------------------
    ' VB: Object Set dataRecCltn = dataTable.DataRecordCollection
    '------------------------------------------------------------   
    Object Get dataTable.DataRecordCollection To dataRecCltn
   
    '---------------------------------------------
    ' VB: dataRecCltn.Add "1;Node 1;07.05.2007;;5"
    '--------------------------------------------   
    vprm = "1;Node 1;07.05.2007;;5"
    Object Call dataRecCltn.Add(vPrm)

    '---------------------------------------------
    ' VB: dataRecCltn.Add "2;Node 2;14.05.2007;;5"
    '---------------------------------------------   
    vprm = "2;Node 2;14.05.2007;;5"   
    Object Call dataRecCltn.Add(vPrm)
   
    '---------------------------------------------
    ' VB: dataRecCltn.Add "3;Node 3;21.05.2007;;5"
    '---------------------------------------------
    vprm = "3;Node 3;21.05.2007;;5"
    Object Call dataRecCltn.Add(vPrm)
                                             
    '------------------------------------------------------------------------------
    ' VB: Set dataTable = VcGantt1.DataTableCollection.DataTableByName("Relations")
    '------------------------------------------------------------------------------
    Object Get VcGantt1.dataTableCollection To dataTableCollection                       
    vPrm = "Relations"   
    Object Call dataTableCollection.DataTableByName(vPrm) To dataTable
   
    '-----------------------------------------------------
    ' VB: Set dataRecCltn = dataTable.DataRecordCollection
    '-----------------------------------------------------   
    Object Get dataTable.DataRecordCollection To dataRecCltn
   
    '----------------------------
    ' VB: dataRecCltn.Add "1;1;2"
    '----------------------------   
    vprm = "1;1;2"   
    Object Call dataRecCltn.Add(vPrm)
   
    '----------------------------
    ' VB: dataRecCltn.Add "2;2;3"
    '----------------------------
    vprm = "2;2;3"   
    Object Call dataRecCltn.Add(vPrm)

    '------------------------
    ' VB: VcGantt1.EndLoading
    '------------------------
    Object Call VcGantt1.EndLoading                         

End Function

José Roca

IF the VB  code is


VB:Object Let VcGantt1.DataTableCollection.DataTableByName = "Maindata"


Then the PB code shoud be


Object Get VcGantt1.dataTableCollection To dataTableCollection                       
vPrm = "Maindata"   
Object Let dataTableCollection.DataTableByName = vPrm

   

Jean-pierre Leroy

#14
Jose and Robert thank you very much for your help.

This simple code is working perfectly; see the screenshot below.


'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long
   
    Dim VcGantt1            As Dispatch                     
    Dim vPrm                As Variant
       
    VcGantt1 = OC_GetDispatch(HWND_FORM1_OCXCONTROL1)
    vprm = "1;Node 1;07.05.2010;;5" : Object Call VcGantt1.InsertNodeRecord (vprm)         ' VB: VcGantt1.InsertNodeRecord ("1;Node 1;07.05.2010;;5")
    vprm = "2;Node 2;14.05.2010;;5" : Object Call VcGantt1.InsertNodeRecord (vprm)         ' VB: VcGantt1.InsertNodeRecord ("2;Node 2;14.05.2010;;5")
    vprm = "3;Node 3;21.05.2010;;5" : Object Call VcGantt1.InsertNodeRecord (vprm)         ' VB: VcGantt1.InsertNodeRecord ("3;Node 3;21.05.2010;;5")
    vprm = "1;1;2"                  : Object Call VcGantt1.InsertLinkRecord (vprm)         ' VB: VcGantt1.InsertLinkRecord ("1;1;2")                             
    vprm = "2;2;3"                  : Object Call VcGantt1.InsertLinkRecord (vprm)         ' VB: VcGantt1.InsertLinkRecord ("2;2;3")
                                      Object Call VcGantt1.EndLoading                      ' VB: VcGantt1.EndLoading
    vprm = 3                        : Object Call VcGantt1.OptimizeTimeScaleStartEnd(vprm) ' VB: VcGantt1.OptimizeTimeScaleStartEnd (3)       

End Function


This syntax don't work, I don't know why.


'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long

    Dim VcGantt1 As Dispatch
    VcGantt1 = OC_GetDispatch(HWND_FORM1_OCXCONTROL1)

    Dim dataTableCollection As Dispatch
    Dim dataTable           As Dispatch
    Dim dataRecCltn         As Dispatch
    Dim vPrm                As Variant
   
    '-----------------------------------------------------------------------------   
    ' VB: Set dataTable = VcGantt1.DataTableCollection.DataTableByName("Maindata")
    '-----------------------------------------------------------------------------       
    Object Get VcGantt1.dataTableCollection To dataTableCollection
    vPrm = "Maindata"            : Object Call dataTableCollection.DataTableByName(vPrm) To dataTable                                         

    Object Get dataTable.DataRecordCollection To dataRecCltn              ' VB: Object Set dataRecCltn = dataTable.DataRecordCollection   
    vprm = "1;Node 1;07.05.2007;;5"   : Object Call dataRecCltn.Add(vPrm) ' VB: dataRecCltn.Add "1;Node 1;07.05.2007;;5"
    vprm = "2;Node 2;14.05.2007;;5"   : Object Call dataRecCltn.Add(vPrm) ' VB: dataRecCltn.Add "2;Node 2;14.05.2007;;5"
    vprm = "3;Node 3;21.05.2007;;5"   : Object Call dataRecCltn.Add(vPrm) ' VB: dataRecCltn.Add "3;Node 3;21.05.2007;;5"

    '------------------------------------------------------------------------------
    ' VB: Set dataTable = VcGantt1.DataTableCollection.DataTableByName("Relations")
    '------------------------------------------------------------------------------
    Object Get VcGantt1.dataTableCollection To dataTableCollection                       
    vPrm = "Relations"           : Object Call dataTableCollection.DataTableByName(vPrm) To dataTable

    Object Get dataTable.DataRecordCollection To dataRecCltn              ' VB: Set dataRecCltn = dataTable.DataRecordCollection           
    vprm = "1;1;2"                    : Object Call dataRecCltn.Add(vPrm) ' VB: dataRecCltn.Add "1;1;2"
    vprm = "2;2;3"                    : Object Call dataRecCltn.Add(vPrm) ' VB: dataRecCltn.Add "1;1;2"
   
                                        Object Call VcGantt1.EndLoading                      ' VB: VcGantt1.EndLoading
    vprm = 3                          : Object Call VcGantt1.OptimizeTimeScaleStartEnd(vprm) ' VB: VcGantt1.OptimizeTimeScaleStartEnd (3)       
   
End Function


Jean-Pierre