Shenghi Posted July 1, 2006 Share Posted July 1, 2006 Ok first of all, sorry if there already is a thread about this, but it's kinda hard to search for. If there already is a thread concerning this, please post the link and close this thread. Now the problem. I'd like to supply a range of numbers for a function, for example _Rand(1-3) would pick a random number between 1 and 3. The _Rand() function is just used as an example in this case. My problem is that when using the following (logic) code... Func _Rand($n) msgbox(0,"",$n) EndFunc ...and calling it for example like... _Rand(1-3) ...the messagebox will display '-2.' The obvious question is: "How can I get $n to be treated as plain text in AutoIt?" Thanks in advance. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 1, 2006 Moderators Share Posted July 1, 2006 (edited) MsgBox(64, 'Info:', 'The Help File has a "Random Function": ' & Random(1, 3, 1)) Edit: Or if it absolutely has to be that way then:$blah = _Ran('1-3') MsgBox(64, 'Info:', $blah) Func _Ran($iRandom) Local $aSplit = StringSplit($iRandom, '-') Return Random(Number($aSplit[1]), Number($aSplit[2]), 1) EndFunc Edited July 1, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Shenghi Posted July 1, 2006 Author Share Posted July 1, 2006 (edited) MsgBox(64, 'Info:', 'The Help File has a "Random Function": ' & Random(1, 3, 1)) Like I said, the _Rand thingie was just an example, to throw it to the case where I really need it: I am writing AutoIt UDF's for mIRC scripting 'Token Identifiers.' Some of them accept a range of tokens (like for example token 1 to 3) and the easiest way of supplying such a range (as you don't _have_ to supply one) would be the suggested method (1-3, for example). Thus the question remains: "How would I treat a supplied parameter in a function as plain text?" Edit: So I supose the only way is to supply it as a string.. A nuisance but oh well, can live with it Edited July 1, 2006 by Shenghi Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 1, 2006 Moderators Share Posted July 1, 2006 Like I said, the _Rand thingie was just an example, to throw it to the case where I really need it: I am writing AutoIt UDF's for mIRC scripting 'Token Identifiers.' Some of them accept a range of tokens (like for example token 1 to 3) and the easiest way of supplying such a range (as you don't _have_ to supply one) would be the suggested method (1-3, for example). Thus the question remains: "How would I treat a supplied parameter in a function as plain text?"Edit:So I supose the only way is to supply it as a string.. A nuisance but oh well, can live with it I think I answered that with my edit? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Shenghi Posted July 1, 2006 Author Share Posted July 1, 2006 Yes you did, I was just secretly hoping that it would be possible without supplying it as a string :] Thanks anyway Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 1, 2006 Moderators Share Posted July 1, 2006 Yes you did, I was just secretly hoping that it would be possible without supplying it as a string :]Thanks anywayHmm, if your getting it from ControlGetText() or whatever method your getting it as and storing it as a variable, it's comming in as a string anyway. Otherwise, there is no need for the function I provided. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 1, 2006 Share Posted July 1, 2006 Hmm, if your getting it from ControlGetText() or whatever method your getting it as and storing it as a variable, it's comming in as a string anyway. Otherwise, there is no need for the function I provided....and if you get a number as a string, that you need as a number, use Int() or Number().(SmOke_N was about to say that, I just wanted to beat him to it! ) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now