Aask
  • Aask
  • Newbie Topic Starter
2018-11-14T09:15:15Z
I have the following code:
Quote:

Private Sub UserForm_Activate()
iGrid1.ColCount = 20
iGrid1.RowCount = 20
Dim b(8, 😎 As Variant
For i = 2 To 9
For j = 2 To 9
b(i - 1, j - 1) = ActiveSheet.Cells(i, j).Value
Next
Next
Dim DirArray As Variant
DirArray = Array(Range("a2:h9").Value)
DirArray2 = [a1:a5].Value2
iGrid1.LoadFromArray 1, 1, b, False ' Works
'iGrid1.LoadFromArray 1, 1, DirArray, False ' Fails
'iGrid1.LoadFromArray 1, 1, DirArray, False ' Fails
End Sub

This is from Excel VBA. I'd like to understand why, of the last 3 lines in the subroutine, why the latter two fail and possibly what the resolution is.
Thanks.
Igor/10Tec
2018-11-15T11:38:47Z
Yes, really, there is a problem with the LoadFromArray function when you use it with an array returned by the Range().Value call in Excel VBA. Before doing its main work, LoadFromArray checks whether a correct array with 1 or 2 dimensions is passed to the method. This check is based on low-level API calls and the COM SafeArray type used internally by the VB runtime to work with arrays. It turned out, that this approach does not work in Excel VBA - at least, in the latest versions of Excel.

I implemented another approach to get the number of array dimensions and compiled a new interim build of iGrid with this bug fix. It has been already sent to you in a private email. Test this new build of iGrid and let us know whether it works correctly.

One comment to the following code snippet:

Dim DirArray As Variant
DirArray = Array(Range("a2:h9").Value)
iGrid1.LoadFromArray 1, 1, DirArray, False

There is no need to wrap the Range().Value call with the Array() function. Doing so you create an array with 1 item, and this item contains a 2-dimensional array returned by Range().Value. It will be an array nested into another array. To make this code work with the LoadFromArray method in iGrid, use the following syntax:

DirArray = Range("a2:h9").Value
Aask
  • Aask
  • Newbie Topic Starter
2018-11-15T12:55:29Z
Igor,

Thanks for the response.

The code snippet is not exemplary - it is the result of various things I had been trying - but I think it does the job of explaining the issues I was having.

I could not work out whether it was the Variant data type or the By Ref that was the root cause.

Variant data type are a little problematic in the sense that, in the same scope or context, you can create two Variant arrays using alternative pathways and one is 0-based and the other is 1-based.

By Ref usually means that iGrid (the server) can change a variable in my application (the client). That is not the case with the LoadFromArray method.

It turns out that the problem was a flaw in iGrid and it was neither 0-based nor By Ref.

The new version works!

Thank you very much.
Gkir
2018-11-20T15:45:19Z
How do I access the new version? On the download page?
Igor/10Tec
2018-11-20T16:24:48Z
The fixed version of the method will be available soon in the next public update of the control. If you need it urgently, send us a letter with your registration data to check whether the latest interim build of the control is available for you for free during the paid maintenance period.
Igor/10Tec
2018-11-26T16:37:02Z
The fixed version of the LoadFromArray method is available in iGrid ActiveX 7.0 released today.
Troy
2019-05-04T21:33:19Z
I just purchased Version 7.00.0015 of ActiveX iGrid as I was having issues with loadfromarray in 6.X. Seems like there was a known bug in 6.X but was resolved in 7.X. My error wasn't necessarily the Range() issue, it just simply failed.

To test 7.X, I added two new 7.X grids, configured them with identical columns, loaded the first grid the normal way, then ran this code (from the example in the chm document):


Dim arr(1 To 10, 1 To 5) As Variant
frmMain.iGrid1.LoadIntoArray 1, 1, arr
frmMain.iGrid2.Clear
frmMain.iGrid2.LoadFromArray 1, 1, arr

I can see that iGrid1 loads correctly and all the expected data is loaded.

I thought maybe it was the dimension of the array so I tried several combinations trying to match the exact number of columns and such, but no luck. On the frmMain.iGrid2.LoadFromArray line, I get the Subscript out of range error.

What might I be doing wrong?

Thanks.

Troy
Igor/10Tec
2019-05-06T06:44:44Z
Troy, can you publish here or send us a sample demonstrating this issue?
Users browsing this topic