Initializing the ScriptControl

As you’ve seen elsewhere in this chapter, you need to initialize some aspects of the ScriptControl before you can use them. In this case, since I want to be able to access the grid from the ScriptControl, I need to create a reference to the MSFlexGrid control using the AddObject method. Since this needs to be done only once, I do it in the Form_Load event, as shown in Listing 13.15. Note that there is no requirement for the name inside the scripting engine to be the same as the name of the real object, so this time I called the internal name Grid rather than typing all of those characters.

Listing 13.15: Form_Load Event in Charter

Private Sub Form_Load()
NewChart
Set fso = New FileSystemObject
Picture1.Width = Printer.Width
Picture1.Height = Printer.Height
ScriptControl1.AddObject “Grid”, MSFlexGrid1
ScriptControl1.AddCode _
      “Function Eval(r, c)” & vbCrLf & _
      “If IsNumeric(Grid.TextMatrix(r,c)) Then” & vbCrLf & _
      “   Eval = CDbl(Grid.TextMatrix(r,c))” & vbCrLf & _
      “Else” & vbCrLf & _
      “   Eval = CDbl(0)” & vbCrLf & _
      “End If “ & vbCrLf & _
      “End Function” & vbCrLf
MSFlexGrid1.Visible = True
MSChart1.Visible = False
Picture1.Visible = False
HScroll1.Visible = False
VScroll1.Visible = False
Command1.Visible = False
MSFlexGrid1.ZOrder 0
End Sub

The other thing I want to do when the program first starts is to create a short function that will allow me to access the contents of a cell as a Double. This function will also return a value of 0 if the cell is empty or contains a non-numeric value.

© 1998 SYBEX Inc. All rights reserved.