Hi all,

I’m pretty new to memory blocks. I managed to set up a memory block and populate it with two strings in a row&column pattern like this

```
. S T R I N G A .
S . . . . . . . .
T . . . . . . . .
R . . . . . . .
I . . . . . . . .
N . . . . . . . .
G . . . . . . . .
B . . . . . . . .
. . . . . . . . . // <- for diagonal sums
. . . . . . . . . // <- for weighted diagonal sums
```

Now what I want to achieve is a 1 where column and row have the same letter

```
. S T R I N G A .
S 1 0 0 0 0 0 0 .
T 0 1 0 0 0 0 0 .
R 0 0 1 0 0 0 0 .
I 0 0 0 1 0 0 0 .
N 0 0 0 0 1 0 0 .
G 0 0 0 0 0 1 0 .
B 0 0 0 0 0 0 0 .
. 0 0 0 0 0 0 0 6 // <- for diagonal sums
. . . . . . . . . // <- for weighted diagonal sums
```

For the weighted diagonal sums each row has a weight multiplier:

```
. S T R I N G A .
S 1 0 0 0 0 0 0 . // *1
T 0 1 0 0 0 0 0 . // +1
R 0 0 1 0 0 0 0 . // +1
I 0 0 0 1 0 0 0 . // +1
N 0 0 0 0 1 0 0 . // +2
G 0 0 0 0 0 1 0 . // +3
B 0 0 0 0 0 0 0 . // +5
. 0 0 0 0 0 0 0 6 // <- for diagonal sums
. 0 0 0 0 0 0 0 9 // <- for weighted diagonal sums
```

How would I most efficiently do this?

TiA

Markus

Ok, I now have

[code]

for col as integer = 1 to LineLength-1

for row as integer = 1 to 10

```
if mb.StringValue(col, 1) = mb.StringValue( row * LineLength , 1 ) then
mb.StringValue( col + row*LineLength, 1 ) = "1"
else
mb.StringValue( col + row*LineLength, 1 ) = "0"
end if
next row
```

next col[/code]

which seems to work but I have the suspicion there is a more elegant solution

Yes, that’s basically it. But I wonder why you didn’t choose a multi-dimensional array instead? If your goal is raw speed, this will be faster, but for convenience, an array is better.

If your goal *is* raw speed, there are ways to make this code faster too.

Yup, speed is why I’m trying my hand at memoryblocks. I already have multi-dimensional arrays.

I feel there are better ways to do this (like get/set values, compare them, add them up) but it is still very much trial and error for me, like in this pseudo code

Mb.booleanvalue = ( mb.stringvalueA = mb.stringvalueB)

Use a Ptr to the MemoryBlock, then get and set Byte values. I assume 0 or 1 are just flags, so maybe something like this:

```
dim p as Ptr = mb
dim lastCol as integer = LineLength-1
for col as integer = 1 to lastCol
for row as integer = 1 to 10
dim rowIndex as Integer = row * LineLength
if p.Byte(col) = p.Byte(rowIndex) then
p.Byte(col + rowIndex) = 1
// Assuming you started with a new MemoryBlock, you wouldn't need the Else
end if
next row
next col
```

Thanks Kem, will try it when I’m back at my computer (I need Xojo on iPad!)