AutoHotkey Community

It is currently May 27th, 2012, 2:15 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: February 5th, 2010, 7:27 am 
Code:
;file.ini

[section]
my_var=myheight-100


Code:
myheight := 500
IniRead, myvar, file.ini, section, my_var
MsgBox, %myvar%  ;// displays the string "myheight-100"


how can i evaluate the contents to get the result 400?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 7:33 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Pending there will only be one set of digits...

Code:
myheight := 500
IniRead, myvar, file.ini, section, my_var
RegExMatch(myvar,"-?\d+",m)
MsgBox % myheight + m

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 7:41 am 
thanks, but the INI could contain any number of variables that are inside the program. and it might not be minus, it might be plus, etc, you get the idea.

Code:
;file.ini
[section]
;any of these could exist
my_var=myheight-100
my_var=800-myheight
my_var=otherVar+9


so i need to treat the string as an expression


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 7:58 am 
however u also need to understand the purpose for INI is for storing raw data, not for calculating math formulas to begin with


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 8:09 am 
thats like saying AHK's purpose is mainly creating quick macro hotkey scripts, not for writing full blown windows applications

both statements are debatable, but its irrelevant anyway. it doesnt have to be an IniRead. i just want to evaluate the expression in a string

Code:
myheight := 500
myvar := "myheight-100"
MsgBox, %myvar%


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 8:18 am 
washing clothes in a dish washer
sure it can be done, but it will be messy

actually ur question has been raised few times recently, so might as well point u to that thread, see if u can find a solution:

http://www.autohotkey.com/forum/topic53 ... ht=dynamic


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 8:34 am 
now we're getting somewhere with the analogies hehe :)

thanks, ill look into those

i also found this which looks more like it
http://www.autohotkey.com/forum/topic5060.html


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 2:11 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
So what exactly about my solution doesn't work for you? It extracts the digits and does the math, yes?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 5:52 pm 
it only extracts the digits. what about the variable name (which is not fixed as myheight)? see the extra ini examples i posted.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2010, 6:39 pm 
Laszlo's Eval() functions from the thread i linked does the job. about midway through he posted updated ones using RegEx
http://www.autohotkey.com/forum/post-107547.html#107547

this code all works, just include the two Eval funcs above

Code:
;file.ini
[section]
my_var1=myheight-100
my_var2=800-myheight
my_var3=otherVar+9


Code:
myheight := 500
otherVar := 10

IniRead, myvar1, file.ini, section, my_var1
IniRead, myvar2, file.ini, section, my_var2
IniRead, myvar3, file.ini, section, my_var3

MsgBox, % Eval(myvar1)     ;// "myheight-100" = 400
MsgBox, % Eval(myvar2)     ;// "800-myheight" = 300
MsgBox, % Eval(myvar3)     ;// "otherVar+9" = 19

MsgBox, % Eval("otherVar+myheight")

return


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher, LazyMan, nimda, poserpro, rbrtryn, sjc1000, Yahoo [Bot] and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group