Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get around 64k limit in Visual Basic 6

Tags:

vb6

I need to update this old code in VB and I have run into a problem. I have added fields to this structure and now when I try to compile I get this error:

enter image description here

From reading online most people suggest to break up the structure. The issue with that is I am receiving the data in this format from the firmware. So I would like to keep it as is, but find a way to get around this.

My structure looks like this:

Public Type DATA_V2_T
    1_offsets(6399) As Single
    2_offsets(6399) As Single
    init_d_offsets(1199) As Single
    init_a_offsets(1199) As Single
    e_offsets(999)   As Single
    d_offsets(749) As Single
    a_offsets(1199) As Single
    final_e_offsets(6399) As Single
End Type

The fields that I have now added are 1_offsets and 2_offsets which cause the error to occur. It seems like this code was getting around this somewhat because the following is defined as a global:

Global data_v2 AS DATA_V2_T

Can I do something like this for the structure as well?

Edit: I have tried to make a class. I Was able to define my variables like this:

    Private 1_offsets(6399) As Single
    Private 2_offsets(6399) As Single
    Private init_d_offsets(1199) As Single
    Private init_a_offsets(1199) As Single
    Private e_offsets(999)   As Single
    Private d_offsets(749) As Single
    Private a_offsets(1199) As Single
    Private final_e_offsets(6399) As Single

I created property get methods to access these private variables like so:

Property Get p1_offsets() As Single()
    p1_offsets = 1_offsets
End Property

The compiler doesn't seem to be complaining about this. But I also need to be able to set the values of the arrays and I am running into trouble with property set. How can I do this?

like image 390
Dan Avatar asked Apr 16 '20 21:04

Dan


2 Answers

The easiest way is to define your data as Variant. Here's an example:

Option Explicit

Private Sub Command1_Click()
   Dim one_offsets(6399) As Single
   one_offsets(0) = 33
   one_offsets(1) = 44

   Dim d As Data
   Set d = New Data
   d.one_offsets = one_offsets
End Sub

and then in your Data class:

Option Explicit

Private m_1_offsets As Variant
Private m_2_offsets As Variant
Private m_init_d_offsets As Variant
Private m_init_a_offsets As Variant
Private m_e_offsets As Variant
Private m_d_offsets As Variant
Private m_a_offsets As Variant
Private m_final_e_offsets As Variant

Public Property Get one_offsets() As Variant
   one_offsets = m_1_offsets
End Property

Public Property Let one_offsets(ByVal Value As Variant)
   m_1_offsets = Value
End Property

If you then inspect m_1_offsets in the Watch window, you will see it is defined as Variant/Single(0 to 6399).

like image 51
Brian M Stafford Avatar answered Oct 17 '22 18:10

Brian M Stafford


I haven't tested that this works yet, but I've made a class like this:

Public 1_offsets As Variant

Private Sub Class_Initialize()
    ReDim 1_offsets(0 To 6399)
End Sub

And everything compiled

Got this from here: Creating VB array that is public, within class module

like image 30
Dan Avatar answered Oct 17 '22 17:10

Dan