Jordinelson Posted March 1, 2010 Share Posted March 1, 2010 Hi guys, I am very new to programing and I am trying to finish my first script. In the example below, how can I make it understand that $qty_300 is a variable and not a string? That means, in the first msg box, I want to get the result "5" and not "$Qty_300" $Qty_300 = 5 $mger = 300 MsgBox (0, "wrong message", "$Qty_" & $mger) I would appreciate a lot any help. Link to comment Share on other sites More sharing options...
omikron48 Posted March 1, 2010 Share Posted March 1, 2010 You'll need to add this somewhere at the start of your script to get what you want: Opt("ExpandVarStrings", 1) However, why are you doing things this way? Why do you need to manipulate strings to process your variables? In most newbie cases, it's primarily because they don't know about or don't know how to use arrays. Are you the same or is it something else? Link to comment Share on other sites More sharing options...
therks Posted March 1, 2010 Share Posted March 1, 2010 I agree with omikron, it looks like you'd be better off using an array, but for the sake of argument, you can also use Eval() to derive a variable from a string. Dim $a_b = 12 $s = Eval("a" & "_" & "b") ; $s is set to 12 $s =Eval("c") ; $s = "" and @error = 1 My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
jchd Posted March 1, 2010 Share Posted March 1, 2010 The OP is confused and answers so far contribute to confuse him/her only more. Variable names start with a $ and can contain any combination of A-Z, a-z 0-9 and _. From this, you see that $Qty_300 is a valid variable name. You use it as such in your $Qty_300 = 5 assignment. Then why do you dissect the name in your MsgBox statement? $Qty_300 = 5 MsgBox (0, "Message", $Qty_300) If you want something a little more informative, try: $Qty_300 = 5 MsgBox (0, "Message", "The variable $Qty_300 currently holds value " & $Qty_300) If you want to get rid of the dependency on this particular variable name, try: $Qty_300 = 5 MsgBox (0, "Message", "There are currently " & $Qty_300 & "yellow wrodignocks in stock.") Now if you need to manipulate,say, items stock for a complete inventory, then previous allusions to arrays will make more sense. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Malkey Posted March 1, 2010 Share Posted March 1, 2010 $Qty_300 = 5 $mger = 300 MsgBox(0, "a message", 'variable "$Qty_' & $mger & '" contains ' & Execute("$Qty_" & $mger)) Welcome to the AutoIt forums. Link to comment Share on other sites More sharing options...
Jordinelson Posted March 2, 2010 Author Share Posted March 2, 2010 Thanks all for the help. Malkey, "Execute" worked like a charm !! Tks. Omikron48 and RobSaunders , I believe I didn`t get it, but I am trying. Spammer, tks! Maybe I could use an array, but I can`t figure out yet how to do it. Anyway, "execute" made the job. That`s is more exactly what I am doing: expandcollapse popup;define limits $mman = InputBox("Testing", "Enter the limit of days for man. Can be 100, 150, 200, 250 or 300", "", " M3") $msup = InputBox("Testing", "Enter the limit of days for sup. Can be 100, 150, 200, 250 or 300", "", " M3") $madmin = InputBox("Testing", "Enter the limit of days for admin. Can be 100, 150, 200, 250 or 300", "", " M3") ; the part below runs into a loop after it reads each line of the spreadsheet. I am simplifying it here. ;open spreadsheet Send("#r", 0) Sleep(500) Send("C:\Temp\temp1.xls{ENTER}", 0) Sleep(1500) WinActivate("Microsoft Excel non-commercial use - temp1.xls [Compatibility Mode]") WinWaitActive("Microsoft Excel non-commercial use - temp1.xls [Compatibility Mode]") Sleep(150) ; get the values in the spreadsheet Send("^{HOME}", 0) Send("{END}{LEFT}", 0) Send("{LEFT}{LEFT}{LEFT}{LEFT}", 0) ; this is a number Send("^c", 0) Sleep(150) $Qty_100 = Number(ClipGet()) ; this is a number Send("{RIGHT}", 0) Send("^c", 0) Sleep(150) $Qty_150 = Number(ClipGet()) ; this is a number Send("{RIGHT}", 0) Send("^c", 0) Sleep(150) $Qty_200 = Number(ClipGet()) ; this is a number Send("{RIGHT}", 0) Send("^c", 0) Sleep(150) $Qty_250 = Number(ClipGet()) ; this is a number Send("{RIGHT}", 0) Send("^c", 0) Sleep(150) $Qty_300 = Number(ClipGet()) ; this variable is an e-mail address Send("{RIGHT}", 0) Send("^c", 0) Sleep(150) $admin =(ClipGet()) ; this variable is an e-mail address Send("{RIGHT}", 0) Send("^c", 0) Sleep(150) $sup =(ClipGet()) ; this variable is an e-mail address Send("{RIGHT}", 0) Send("^c", 0) Sleep(150) $man =(ClipGet()) ;this part runs in the CC: field of an e-mail client. It is actually copying the manager, supervisor and administratos, depending how bad is the problem. If Execute("$Qty_" & $mman) > 0 Then Send($man, 0) Send("{ENTER}", 0) Send($sup, 0) Send("{ENTER}", 0) Send($admin, 0) Send("{ENTER}", 0) ElseIf Execute("$Qty_" & $msup) > 0 Then Send($sup, 0) Send("{ENTER}", 0) Send($admin, 0) Send("{ENTER}", 0) ElseIf Execute("$Qty_" & $madmin) > 0 Then Send($admin, 0) Send("{ENTER}", 0) EndIf Link to comment Share on other sites More sharing options...
jchd Posted March 2, 2010 Share Posted March 2, 2010 You're making it overly complex. First, use the Excel UDF to pick up values in your Excel sheet. That will be robust, while Send() and friends will cheerfully fail if ever any window or dialog pops up while your script is running (they work on the active window and if Excel is not the currently active one, then ... plonk!). Have "badness" level limit values entered for your three levels, preferably from listbox (and check they are in increasing values!). Now, pick up your "problem badness" values in the sheet row. I understand that only one will get non-zero, right? Anyway, keep only the worst (largest) and then: Select Case $badness >= $ManagerLimit ; code to CC to manager ContinueCase Case $badness >= $SupervisorLimit ; code to CC to supervisor ContinueCase Case $badness > $AdminLimit ; code to CC to admin ContinueCase Case Else ; common action if needed EndSelect This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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