Convert string to an object reference?

Convert string to an object reference?

Post by bullcha » Sat, 13 Aug 2005 09:37:50


I'm not sure if I'll be able to explain this correctly, but I'll try.
Here's what I have for an example (Not in valid RB syntax, just an
overview)...

I've also dragged in a text file into my project, so there is an item
in my project list called "mytextfile". I'm not positive, but I think
that RB refers to this now as a string constant (?) I can easily load
the contents of the "mytextfile" into a string with the obvious
string1=mytextfile. This works as I thought it would/should. The string
var now has the text file's text in it.

Here's the part I'm stuck on. If I have an editfield (editfield1), and
I want the user to type in a word, then match it to the filename of the
text file I have dragged in. That probably sounds much more confusing
that it should be ;)

So if the user types in "mytextfile", then the program should just
msgbox the actual "mytextfile"'s text data that's dragged into my
project (which again I'm assuming is now basically a text constant (?))
The problem is that when I pass the typed-in editfield text, it just
passes the actual text of what is in the editfield's text property that
the user typed in, and I can't make it reference the "mytextfile"
constant.

I'm looking to find out how to convert the string into the reference
object of the constant. While this should be an easy thing that I'm
overlooking, I just can't seem to figure it out for the life of me. Is
this some form of typecasting or ?

If that makes any sense to anyone, I'd appreciate any help. Thanks.

CB
 
 
 

Convert string to an object reference?

Post by bullcha » Sat, 13 Aug 2005 10:59:12

For an easier example, is there a way to convert something like a
string "true" to a boolean=true; without using something like an ** if
string1="true" then bool1=true ** type of thing?

This would help me figure out my problem in simpler terms I think...if
anyone has any ideas? Thanks again.

 
 
 

Convert string to an object reference?

Post by Joe Strou » Sat, 13 Aug 2005 12:02:11

In article < XXXX@XXXXX.COM >,



Yes, a Variant can do this.

Dim v as Variant = string1
bool1 = v

Best,
- Joe

,------------------------------------------------------------------.
| Joseph J. Strout Check out the Mac Web Directory: |
| XXXX@XXXXX.COM http://www.yqcomputer.com/ |
`------------------------------------------------------------------'
 
 
 

Convert string to an object reference?

Post by Joe Strou » Sat, 13 Aug 2005 12:03:50

In article < XXXX@XXXXX.COM >,



You'll need to use a Select Case statement for that. Or, you could load
all your string constants into a Dictionary, where the key is the name
and the value is the actual text.

Either way, you're going to have to write a line or two of code for each
such text block you have.

Best,
- Joe

,------------------------------------------------------------------.
| Joseph J. Strout Check out the Mac Web Directory: |
| XXXX@XXXXX.COM http://www.yqcomputer.com/ |
`------------------------------------------------------------------'
 
 
 

Convert string to an object reference?

Post by bullcha » Sat, 13 Aug 2005 13:06:32

Ok thanks - that's what I was looking for. I wasn't sure if I could cut
a corner somehow :)