convert string to number

Got a problem you cannot solve? Try here.
Post Reply
jenlin0703
Posts: 5
Joined: Wed Jan 26, 2011 12:52 am

convert string to number

Post by jenlin0703 »

Hello,

I get a string value form "Read Registry" function, and I want to convert it to a number value.
Because I want to do operations of addition.
What function can I use?

Thanks! :")
bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: convert string to number

Post by bokkie »

Jenlin, I know what you are asking but I'm not sure why you need to convert it to a number first. Let me explain. I read an existing REG_SZ (string) value from my registry using the same read registry plugin as you did. I then created another variable which I initialised to a numeric value in my MSIcode script and I added them both together using the Mathematics plugin. In other words, the value coming from the registry was good to use without any other manipulation. If I tried the same using a text string like "ABC" then the Mathematics function returns a null (empty) result.

Unless I've misunderstood your question you should be able to use Mathematics immediately on the values. Does that explain what you can do?
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP
jenlin0703
Posts: 5
Joined: Wed Jan 26, 2011 12:52 am

Re: convert string to number

Post by jenlin0703 »

Hi bokkie,

Sorry! I was not clear.

This is my MSICode:

Code: Select all

~InstallAware Clipboard Data~
~Write Registry~
~{022C2ADA-97ED-444F-A2ED-C15EBBE392BD}~
~0~
~0~
~.aaa~
~File Instance~
~$szFileInstance$~
~TRUE~
~FALSE~
~Mathematics~
~{06C93CD9-9E9B-4BF1-8FE8-41BE618CD8AB}~
~$szFileInstance$~
~$nvTemp$~
~0~
~szFileInstance~
~Read Registry~
~{4E0D8C91-B340-4221-B18B-03DA3A3D64E8}~
~szFileInstance~
~0~
~.aaa~
~~
~Set Variable~
~{9D05D223-356D-4D72-B211-EEA2659D31FB}~
~nvTemp$MYAH$MYAH$FALSE~
~1~
~Set Variable~
~{5FDD0211-FA7C-4998-8722-CEF318D92898}~
~szFileInstance$MYAH$MYAH$FALSE~
~~
The default value of szFileInstance is a blank.
"szFileInstance = $szFileInstance$ + $nvTemp$" is not success...
value of szFileInstance is still a blank!
Can I convert a blank to a integer 0? then do operations of addition?

thanks!!

Jen
bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: convert string to number

Post by bokkie »

You could check for a null string using an "if" statement and then set its value to 0? I'm not sure though if you have to delete the existing registry item before you write the new value? Also, the write registry function is a "purple" command so you'll need to do the apply install before it takes affect? The delete registry function is a "black" command so it will take place on demand when it's executed. That's the best I can think of.

Code: Select all

~InstallAware Clipboard Data~
~End~
~{355302A2-5F55-4092-B314-371A20DCF54A}~
~Set Variable~
~{49084EE8-63B0-4316-B047-7765AAFE065A}~
~szFileInstance$MYAH$MYAH$FALSE~
~0~
~If~
~{C59CA394-28EA-466E-89B8-96A301939656}~
~szFileInstance~
~0~
~~
~FALSE~
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP
jenlin0703
Posts: 5
Joined: Wed Jan 26, 2011 12:52 am

Re: convert string to number

Post by jenlin0703 »

Hi bokkie,

It's a good idea!
Thanks for your reply :D

Jen
Post Reply