Simple string conversion but...

06-09-2005, 05:14 AM
hi all,

i've a simple (if you know how to..) problem here, text1 is a textbox:

text1 = chr(56) & chr(57) ' OK if you type it directly => text1 = "89"

how to do the same assigning the right side to a string variable ?

s = "chr(56) & chr(57)"
text1 = s ' in this case text1.text = "chr(20) & chr(30)" no good

what i need is : text1 = "89"

please let me know...
thanks !!

06-09-2005, 05:17 AM
take out the quotes around "chr(56) & chr(57)", you can set a string equal to just plain o'l chr(56) & chr(57) and it will still be valid.

06-09-2005, 06:05 AM
Thanks Jeffy,

the problem is that i cannot remove the quotes since that string returns from a function as string...VB should only execute it..

please reply..

06-09-2005, 06:11 AM
You could use the Replace$() function to remove the quotes:

Debug.Print Replace$("chr(56) & chr(57)", Chr$(34), "")

06-09-2005, 06:23 AM
the way I would do it would be to use a class that has a function call MyChar

That takes in a number and returns the value.


public function MyChar(Num as long) as string
MyChar = char(num)
end function

then in your code use callbyname

IE text2 = CallByName(YourClass,"MyChar",56) & CallByName(YourClass,"MyChar",57)

hope this is what you want

06-09-2005, 06:39 AM
Thanks Diurnal,

your code run fine but ...still i'm NOT getting what i need:

pout = StrConv(s1) ' here pout = " chr(56) & chr(57)"
pp = Trim(Replace$(pout, Chr$(34), ""))

here pp = "chr(56) & chr(57)" quotes are still there in the variable but thery are removed if the string is typed directly in the editor...

p7 = pp ' here p7 = "chr(56) & chr(57)" like pp...

... how to get p7= "89" ?

please reply..

06-09-2005, 06:46 AM
Thanks Anthony,

your idea looks good but i'm NOT familiar with classes .. could you please give me some more details on how to include your code into my example..?

(please note that i would like to use the string format AS IS since extracting 56,57 will be too time consuming for long strings...)

thanks !

06-09-2005, 07:17 AM
Yesss I got it !!!
I dimly recalled wanting to do this before, but couldn't remember how until just now...
CallByName is not good enough, since you can't use it to call internal functions, it always needs an object.
What you need is [tadaaah] SCRIPTING SUPPORT.
And, nice as the people at Microsoft are, we already have that as one of the VB standard components (MSScript).

So, what you need to do is the following

1. Project -> Components -> Microsoft Script Control 1.0
2. Place the newly available Control on your form
3. Pass the string you want evaluated to its Eval function, like so:

MsgBox ScriptControl1.Eval("Chr(56) & Chr(57)")

Yep, it indeed gives us "89" :) :) :)

06-10-2005, 01:03 AM
Great TeraBlight !

thanks a lot ! :D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum