From: Nobody on
One way, but I don't like it, is swapping pointers via CopyMemory, but could
lead to crashes if you are not careful. Also search the newsgroups for
SysAllocStringLen/SysAllocString.


From: Henning on

"xytsrm" <xytsrm(a)discussions.microsoft.com> skrev i meddelandet
news:527FC413-4CF6-4AC2-B7C9-F8BF7EA6D3F2(a)microsoft.com...
> Problem"
> Lets say that I have several variables defined:
>
> Dim A As String
> Dim B As String
> Dim C As String
>
> In the program I want to retain the references A,B and C, but I would like
> to assign values to A, B and C by indexing. In other words what I would
> like
> to create is an array of pointers [ie. Dim X(3)] to A, B, and C, such that
> by
> equating X(1) = "message 1", then A = "message 1". VarPtr can be used to
> make X(1) reference A by X(1) = VarPtr(A), but I'm not sure how to
> indirectly
> assign "message1" to A via X(1). Perhaps there's an easier way? Can
> anyone
> help?
>
> X.
>

This all seems as a lot of trouble to avoid a Select Case to select what var
to use out of an index.
There might be some other struggle not known ofcause.

/Henning


From: Bob Butler on

"xytsrm" <xytsrm(a)discussions.microsoft.com> wrote in message
news:527FC413-4CF6-4AC2-B7C9-F8BF7EA6D3F2(a)microsoft.com...
> Problem"
> Lets say that I have several variables defined:
>
> Dim A As String
> Dim B As String
> Dim C As String
>
> In the program I want to retain the references A,B and C, but I would like
> to assign values to A, B and C by indexing. In other words what I would
> like
> to create is an array of pointers [ie. Dim X(3)] to A, B, and C, such that
> by
> equating X(1) = "message 1", then A = "message 1". VarPtr can be used to
> make X(1) reference A by X(1) = VarPtr(A), but I'm not sure how to
> indirectly
> assign "message1" to A via X(1). Perhaps there's an easier way? Can
> anyone
> help?

If you created a class to hold the string you could declare A, B, and C as
instances of the class and also add them to a collection or an array to
reference them by index. It's a lot more overhead than some sort of Union
equivalent but might suit your needs.


From: Nobody on
Also, one alternative solution is using string arrays like others suggested,
but use Enum values as index. VB's intellisense would show you the list of
values in this case. Example:

Dim s(1 To 3) As String

Private Enum str
strA
strB
strC
End Enum

Usage:

s(str.strA) = "ABC"

When you type "str" followed by ".", VB shows the list of values, so you
don't have to remember them.



From: Dee Earley on
On 11/10/2009 02:23, Ralph wrote:
> Also notice that StrPtr() and ValPtr() do not report the same item when used
> on a VB String variable.

They won't.

The variable has a location which you can get with VarPtr (I assume you
meant VarPtr, not ValPtr) which, for numbers is the data itself.
For a string, this will be another pointer which refers to the start of
the string data (which you can get via StrPtr).

Essentially, if you copy 4 bytes of data from varptr(stringvar), you
should end up with the same value as strptr(stringvar).

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: ItemData screwed up after sort ???
Next: ReDim'ed Array size