Pointers?

  • Thread starter Marco Trapanese
  • Start date
M

Marco Trapanese

Hello again,

I have four arrays:

Dim InputA(20) as Integer
Dim InputB(15) as Boolean
Dim InputC(6) as Single
Dim InputD(30) as Integer

They represent the physical input of four external boards. So I have
four classes, one for each board. They acquire via the serial port the
data and store the value in those arrays.

Now I want to create a single array which represent the logical input of
my application. Something like this:

Dim Inputs(71) as Object

Each element of this array is strictly related to another element of the
previous arrays. Ok, no problem at all.

The real problem is I don't want to update manually the Inputs() array
when one value of the others changes. It would be nice if I can define a
pointer to a variable... so I could write:

Inputs(3) = *InputB(7)

How to do that in VB.NET?

Thanks!
Marco / iw2nzm
 
C

Chris Dunaway

Hello again,

I have four arrays:

Dim InputA(20) as Integer
Dim InputB(15) as Boolean
Dim InputC(6) as Single
Dim InputD(30) as Integer

They represent the physical input of four external boards. So I have
four classes, one for each board. They acquire via the serial port the
data and store the value in those arrays.

Now I want to create a single array which represent the logical input of
my application. Something like this:

Dim Inputs(71) as Object

Each element of this array is strictly related to another element of the
previous arrays. Ok, no problem at all.

The real problem is I don't want to update manually the Inputs() array
when one value of the others changes. It would be nice if I can define a
pointer to a variable... so I could write:

Inputs(3) = *InputB(7)

How to do that in VB.NET?

Thanks!
Marco / iw2nzm

You could try using Array.Copy, I'm not sure if that's what you want.

Chris
 
M

Marco Trapanese

Chris said:
You could try using Array.Copy, I'm not sure if that's what you want.


It's useful to copy manually the values. But I'm looking for a way to
avoid this.

Example:

Dim A(4) as Integer
Dim B(1) as Boolean
Dim C(7) as Object

Array.Copy(A, C, 5)
Array.Copy(A, 0, C, 5, 2)

Now C contains A and B.
But if I set:

A(2) = 20

I have to do the copy again in order to have also C(2) = 20.

Bye
Marco / iw2nzm
 
A

Armin Zingler

Marco Trapanese said:
Hello again,

I have four arrays:

Dim InputA(20) as Integer
Dim InputB(15) as Boolean
Dim InputC(6) as Single
Dim InputD(30) as Integer

They represent the physical input of four external boards. So I have
four classes, one for each board. They acquire via the serial port
the data and store the value in those arrays.

Now I want to create a single array which represent the logical
input of my application. Something like this:

Dim Inputs(71) as Object

Each element of this array is strictly related to another element of
the previous arrays. Ok, no problem at all.

The real problem is I don't want to update manually the Inputs()
array when one value of the others changes. It would be nice if I
can define a pointer to a variable... so I could write:

Inputs(3) = *InputB(7)

How to do that in VB.NET?


Maybe you could declare Inputs as a structure:

structure item
public sourcearray as array
public index as integer
public sub New(sourcearray as array, index as integer)
me.sourcearray = sourcearray
me.index = index
end sub
public property value as object
get
return sourcearray.getvalue(index)
end get
end property
end structure

dim inputs as item()
...
inputs(3) = new item(inputB, 7)


Later you can access "Inputs(3).value"




Armin
 
B

Blake

Have a look at the ArraySegment class

You could can define a single large array first,
and then use segments of the large array for the
individual lists. This should mean that you can
use a single memory location for each stored value.
 
M

Marco Trapanese

Blake said:
Have a look at the ArraySegment class

You could can define a single large array first,
and then use segments of the large array for the
individual lists. This should mean that you can
use a single memory location for each stored value.


Great! It's just I was looking for!
Thank you :)

Marco / iw2nzm
 
M

Marco Trapanese

Blake said:
Have a look at the ArraySegment class

You could can define a single large array first,
and then use segments of the large array for the
individual lists. This should mean that you can
use a single memory location for each stored value.

Today I've used the ArraySegment class and now all works fine.
However, I'm wondering why I must add the offset to the index of the
segment manually.

Marco / iw2nzm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top