Program to Address each Memoryblock in a set of 10

In VB6 it is possible to address a ‘Control’ using the ControlName(item). I want to do the Xojo equivalent, when addressing each of the MemoryBlocks in a set of 10 Memory Blocks. Which MemoryBlock, to be accessed, is determined by the program. How can this be done?

I’m not sure what you’re after, in the end, but you could use an array of MemoryBlocks:

Var m() as MemoryBlock dim intMax as Integer = 10 for intCycle as Integer = 0 to intMax m.AddRow( new MemoryBlock ) next

Or you could use a dictionary:

Var d as New Dictionary d.Value( "memBlock1" ) = new MemoryBlock d.Value( "memBlock2" ) = new MemoryBlock

Untested code, should get you started if not where you want to be.

Many thanks you Antony
I’m going to try the Dictionary Option.

I’ll feed-back on the outcome.

Hello again Anthony

I have spent some time trying to achieve what I want, using the dictionary approach. Currently I’m not making much progress.

I will restate my problem, to see if you can give me a more targeted response:

I have 10 off Binary Strings (91 bytes Length), that I want to process individually (each string has the identical structure but, varying values). Speed is important in my application so I want to use a separate MemoryBlock to be the repository for each string. The strings are updated every 100ms via a serial link. In a background Thread, I want to process each string as they arrive so that a set of program variables is updated and the program can deliver the overall performance required.

The simplest approach would be to create 10-off MemoryBlocks, with 10 separate processing methods and then use a Select Case with 10 Cases to provide the relevant method. However the programming overhead is 10(?) times greater than theoretically needed because it is necessary to pick the required method (the Case) from a set of ten methods and 10 separately defined MemoryBlocks.

I want to use a For Each… loop to enable my program to use an adaptable, single method, applied to each MemoryBlock. I believe this should be possible if only I can use an ‘indirect addressing’ approach. My need is to have a processing method that adapts to the needs of the Binary String, based on its String ‘Number’. The program would create a “String” that would be used to select the relevant MemoryBlock and processing Method based on the Binary String number.

Any further comment(s), please?

Many thanks, in anticipation of your advice

Andrew Morrell

From what you’re describing, if you want to retain the order of the data, then you should use an array of MemoryBlocks. You’d probably be better off using an indexed For loop rather than For Each since you need to have the index.

Var m() as MemoryBlock 'Populate m() Array Var maxIndex as Integer = m.LastRowIndex For currentIndex as Integer = 0 to maxIndex 'Process data Next

You can then pass the index and data from that element of the array to your processing method, or process directly in the loop. If you need to retain the data in memory for accessing later/elsewhere, then you should store it somewhere accessible like in a module as a global property.

Unless I’m completely misinterpreting what you’re asking.

Have you considered using a Structure. It might make programming easier since you won’t be fiddling with offsets into a memoryblock. Also, I would recommend putting your processing into a method and pass each string into it individually. There is definitely no need for a large select case that addresses each string separately.

Hello and thank you Anthony and Tim.

I’ll work through your suggestions, and see if I can get where I need to.

Best regards

Andrew