473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Assigning a Value to a Structure Pointed to by a Tag ?

I know that this must be a really dumb question but I just can't find an
answer.

I want to associate some information with a RichTextBox. The Tag property
seems to be the intended way to "hang" some additional information on a
Control. I've created a structure, rtbAuxInfo, for the information. I
think that I have found the right syntax for assigning a pointer to the
structure to the Tag property of the RichTextBox, but I can't figure out how
to then assign a value to one of the fields of the structure.

' rtb1 is the RichTextBox

rtb1.Tag = New rtbAuxInfo ' at least this syntax seems OK

' now I want to set the URL field of the rtbAuxInfo structure ...

rtb1.Tag.URL = url ' doesn't work but I think that it shows what I am
trying to accomplish

CType(rtb1.Tag, rtbAuxInfo).URL = url ' doesn't work either

I'd sure appreciate it if someone could help me with this.

Thanks, Bob

Jan 24 '06 #1
2 1350
Bob,
a Structure is a value type, which means you get a copy each time you assign
it to an object "variable" (rtbl.Tag) and each time you retrieve it from an
object "variable". As it will be boxed (placed on the heap).

In this case when you access rtbl.Tag.Url you are setting a property on a
copy of your initial structure.

If rtbAuxInfo "needs" to be a structure (which IMHO obviously doesn't, as
you are using it as a reference type). You need to make a copy, set the
copy, then save the copy. Something like:

| rtb1.Tag = New rtbAuxInfo ' at least this syntax seems OK

Dim temp As rtbAuxInfo = DirectCast(rtbl.Tag, rtbAuxInfo)
temp.URL = url
rtbl.Tag = temp

If you simply make rtbAuxInfo a Class, then you can simply refer to it in
the Tag property:

DirectCast(rtb1.Tag, rtbAuxInfo).URL = url

As the Tag property is returning a reference to a single object on the heap,
no copies of values is being done.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"eBob.com" <fa******@totallybogus.com> wrote in message
news:uF**************@TK2MSFTNGP12.phx.gbl...
|I know that this must be a really dumb question but I just can't find an
| answer.
|
| I want to associate some information with a RichTextBox. The Tag property
| seems to be the intended way to "hang" some additional information on a
| Control. I've created a structure, rtbAuxInfo, for the information. I
| think that I have found the right syntax for assigning a pointer to the
| structure to the Tag property of the RichTextBox, but I can't figure out
how
| to then assign a value to one of the fields of the structure.
|
| ' rtb1 is the RichTextBox
|
| rtb1.Tag = New rtbAuxInfo ' at least this syntax seems OK
|
| ' now I want to set the URL field of the rtbAuxInfo structure ...
|
| rtb1.Tag.URL = url ' doesn't work but I think that it shows what I am
| trying to accomplish
|
| CType(rtb1.Tag, rtbAuxInfo).URL = url ' doesn't work either
|
| I'd sure appreciate it if someone could help me with this.
|
| Thanks, Bob
|
|
|
Jan 24 '06 #2
"eBob.com" <fa******@totallybogus.com> wrote in message
news:uF**************@TK2MSFTNGP12.phx.gbl...
The Tag property seems to be the intended way to "hang" some additional
information on a Control. I've created a structure, rtbAuxInfo, for the
information. I think that I have found the right syntax for assigning a
pointer to the structure to the Tag property of the RichTextBox, but I
can't figure out how to then assign a value to one of the fields of the
structure.


Start by washing your mouth out - "pointer" indeed. ;-))

The Tag property is typed "as Object" so that you can put /anything/
into it. To get that Object "back" to the right Type of variable, you
have to "cast" it before you can use it, as in

' No "New"; Structure is a Value Type, like Integer
rtb1.Tag = rtbAuxInfo

and to retreive it

Dim ai as rtbAuxInfo _
= DirectCast( rtb1.Tag, rtbAuxInfo )

ai.URL = url

HTH,
Phill W.
Jan 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Matthew Sims | last post by:
Python Newbie here. This is my first time learning object-oriented programming and trying to break out of the usual Korn/Perl/PHP style of programming. Having some difficulty understand some items....
13
by: - Kees van der Bent - | last post by:
/* With the following: */ typedef struct { unsigned char a : 1; unsigned char b : 1; } sss_t; sss_t sss; unsigned char ppp; main()
3
by: JJ_377 | last post by:
I made a user control to gather usa address information and would like to know why the following doesn't work (I am assigning the valid of textbox in a second instance of the control from the first...
7
by: Adrian Parker | last post by:
'function to convert null to nothing Function CheckDate(ByVal DRow As DataRow, ByVal strCol As String) As Date If DRow.Item(strCol) Is System.DBNull.Value Then Return Nothing Else Return...
2
by: Brent | last post by:
I have variables in a structure loaded into a list box. I thought I could use FieldInfo.SetValue to update the items value when the user clicks on it, but it is not working. .. .. .. Dim fi...
5
by: moni | last post by:
Hey, My buffer contains a short int, some char, and a structure in form of a byte array. Read the string as: TextBox4.Text = System.Text.Encoding.ASCII.GetString(buffer1, 0, 31); Read...
43
by: emyl | last post by:
Hi all, here's an elementary question. Assume I have declared two variables, char *a, **b; I can then give a value to a like a="hello world";
9
by: J. Peng | last post by:
I just thought python's way of assigning value to a variable is really different to other language like C,perl. :) Below two ways (python and perl) are called "pass by reference", but they get...
3
by: Chris Saunders | last post by:
My C skills are rather meager so forgive me if I do not express my question clearly enough. Here is a struct that is declared in Windows: typedef struct _REPARSE_GUID_DATA_BUFFER { DWORD...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.