jfcby Posted April 5, 2010 Share Posted April 5, 2010 Hi, I have a script below with an If statement that is not counting correctly. When I run the script I need it to begin with the $BeginCount thru the $EndCount. If I run the script with numbers in the varibles $i, $BeginCount, and $EndCount it works right but when I use and ini file it skips over the first $BeginCount number. Why does my script skip over the first $BeginCount number when using the ini file? IfTest.ini File expandcollapse popup [count] icount=4 ;=> Begin Count (CHANGE) bcount=4 ;=> End Count (CHANGE) ecount=10 [code=auto:0] AutoIt Script [code=auto:0] #include <GUIConstantsEx.au3> #include <GuiButton.au3> Opt("MustDeclareVars", 1) Global $btn, $sIni, $i, $BeginCount, $EndCount $sIni = @ScriptDir & "\IfTest.ini" $i = IniRead($sIni, "count", "icount", "NotFound") ;4 $BeginCount = IniRead($sIni, "count", "bcount", "NotFound") ;4 $EndCount = IniRead($sIni, "count", "ecount", "NotFound") ;10 MsgBox(0, "Debug 1", "$i = " & $i & @CRLF & "$BeginCount = " & $BeginCount & @CRLF & "$EndCount = " & $EndCount) _Main() Func _Main() GUICreate("If Test", 510, 400) $btn = GUICtrlCreateButton("Next", 10, 10, 100, 50) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn MsgBox(0, "Debug 1", "Test If statement - $i = " & $i) If $i >= $BeginCount And $i <= $EndCount Then MsgBox(0, "Debug 2", "Test If statement - $i = " & $i) ;<<= Here will not start with 4... EndIf $i += 1 EndSwitch WEnd Exit EndFunc ;==>_Main [code=auto:0] Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options... Moderators Melba23 Posted April 5, 2010 Melba23 Moderators 31.1k 477 I'm old, what's your excuse? Moderators Share Posted April 5, 2010 jfcby,Your problem is arising because the returns from the IniRead lines are strings, not numbers. So the comparisons are using the ASCII values of the first characters and not the numerical values.Just change the IniRead lines like this:$i = Number(IniRead($sIni, "count", "icount", "NotFound")) ;4 $BeginCount = Number(IniRead($sIni, "count", "bcount", "NotFound")) ;4 $EndCount = Number(IniRead($sIni, "count", "ecount", "NotFound")) ;10And all will work as you thought it would. Not having typed variables is one of AutoIt's strengths - and one of its weaknesses. You just have to be careful - it cannot read your mind, so you have to make sure at times. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jfcby Posted April 5, 2010 Author Share Posted April 5, 2010 jfcby, Your problem is arising because the returns from the IniRead lines are strings, not numbers. So the comparisons are using the ASCII values of the first characters and not the numerical values. Just change the IniRead lines like this: $i = Number(IniRead($sIni, "count", "icount", "NotFound")) ;4 $BeginCount = Number(IniRead($sIni, "count", "bcount", "NotFound")) ;4 $EndCount = Number(IniRead($sIni, "count", "ecount", "NotFound")) ;10 And all will work as you thought it would. Not having typed variables is one of AutoIt's strengths - and one of its weaknesses. You just have to be careful - it cannot read your mind, so you have to make sure at times. M23 Thank you Melbay23 worked like a charm. I looked in the help file and did not find any examples that matched your code. Where can I find examples of your code for future reference? Thanks, jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 5, 2010 Moderators Share Posted April 5, 2010 jfcby,Those lines are nested functions:$i = Number( IniRead($sIni, "count", "icount", "NotFound") ) ^1 ( ^2 ) )The 2 functions are Number and IniRead.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jfcby Posted April 5, 2010 Author Share Posted April 5, 2010 jfcby, Those lines are nested functions: $i = Number( IniRead($sIni, "count", "icount", "NotFound") ) ^1 ( ^2 ) ) The 2 functions are Number and IniRead. M23 Melba23 Thank you for your help. Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 5, 2010 Moderators Share Posted April 5, 2010 jfcby,A pleasure. By the way, when you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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