Sign in to follow this  
Followers 0
jfcby

If EndIf Not Working Correctly

6 posts in this topic

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

[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 ****

  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                        





(adsbygoogle = window.adsbygoogle || []).push({});




                    
                
                    
                    
                    






    
    
        
Melba23   

    
        
    
             2,460
    
        
    

        
            
                Soy viejo, ¿cuál es tu excusa?
            
            

            
                

    
        
    

            
            Moderators
            
                
            
            
                

    
        
    
             2,460
    
        
    

                27,548 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #2 · 
            Posted 
            
            
            
        
    

    


            
        
            
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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 ****

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 ****

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0