Jump to content

While 1/WEnd For/Next & GuiGetMsg()


Recommended Posts

I'm working on a script to help me download stuff from my signature and maybe even release this to the public but I'm having a problem, this is farely straight forward code.

My problem is: Why is it constantly going through the For/Next loop even when I use GuiGetMsg()?

Global $Ini = @ScriptDir&"\Programs.ini"
$GetButtonCount = IniReadSection($Ini, "Programs")
Global $Buttons[$GetButtonCount[0][0] + 1], $Descriptions, $ProgramLinks, $ButtonPositionRight[6] = [0, 25, 50, 75, 100]

If Not FileExists($Ini) Then _FatalMsgbox(16, "Download Justin's Scripts", "This program requires the included Program.ini in the script directory.")

$GUI = GUICreate("Download Justin's Scripts", 632, 453)
_SetUp()

While 1
    Switch GUIGetMsg()
        Case - 3
            Exit
    EndSwitch
    $GetButtons = IniReadSection($Ini, "Programs")
    For $I = 1 To $GetButtons[0][0]
        If GUIGetMsg() = $GetButtons[$I][0] Then
            $GetDescriptions = IniReadSection($Ini, "Descriptions")
            For $I = 1 To $GetDescriptions[0][0]
                If $GetButtons[$I][0] = $GetDescriptions[$I][0] Then MsgBox(0, $GetDescriptions[$I][0], $GetDescriptions[$I][1])
            Next
        EndIf
    Next
WEnd

Func _SetUp ()
    Local $GetButtons = IniReadSection($Ini, "Programs")
    For $I = 1 To $GetButtons[0][0]
        $Buttons[$I] = GUICtrlCreateButton($GetButtons[$I][1], 0, $ButtonPositionRight[$I])
    Next
    GUISetState(@SW_SHOW, $GUI)
EndFunc

Func _FatalMsgbox($Icon, $Title, $Message)
    MsgBox($Icon, $Title, $Message)
    Exit
EndFunc

Edit:

Here is the Ini to be able to run the program correctly, place it in the same directory and name is Programs.ini.

[Programs]

Button1=MicroOS

Button2=Simple Web Browser

Button3=All In One Application

Button4=Dictionary

Button5=Dictionary File

[Descriptions]

Button1=MicroOS is a simple yet advanced explorer shell replacement with prebuilt applications.

Button2=Simple Web Browser is a small yet full featured web browser.

Button3=All In One application includes a Web Browser, Notepad, Music Player, Task Manager, and Misc.

Button4=Dictionary is an enter yourself dictionary with a bunch of cool features.

Button5=None Available

[ProgramLinks]

Button1=http://www.autoitscript.com/forum/index.php?showtopic=55076&st=0&start=0

Button2=http://www.autoitscript.com/forum/index.php?showtopic=52455&st=0&start=0

Button3=http://www.autoitscript.com/forum/index.php?showtopic=61059

Button4=http://www.autoitscript.com/forum/index.php?showtopic=63290&st=0#entry472129

Button5=http://www.autoitscript.com/forum/index.php?showtopic=63290&st=0#entry472129

Edited by JustinReno
Link to comment
Share on other sites

Suggestion would be to do your gui in on event mode 1 so your only calling the For/ Next loop when a button is pressed.

Atm your While 1 loop is firing the For/ Next loop constantly regardless if a button is pressed or not, hence the excess cpu use when not even clicking a thing (the excess cpu part is a guess as I haven't even run your code, but your codes layout suggests it to me all the same)

Cheers

Link to comment
Share on other sites

That whole while loop had to go. $GetButtons should have been populated elsewhere, so it isn't just needlessly re-reading the .ini file each time through the loop. "If GUIGetMsg() = $GetButtons[$I][0] Then", You are comparing a control ID to a string. GuiGetMsg() is returning 0 when you start the program, and the string becomes "0" on conversion, so that line of code becomes "If 0 = "String" Then.. " which becomes "If 0 = 0 Then.."

#include <IE.au3>

Global $Ini = @ScriptDir&"\Programs.ini"
$GetButtonCount = IniReadSection($Ini, "Programs")
Global $Buttons[$GetButtonCount[0][0] + 1], $Descriptions, $ProgramLinks, $ButtonPositionRight[6] = [0, 25, 50, 75, 100], $GetDescriptions

If Not FileExists($Ini) Then _FatalMsgbox(16, "Download Justin's Scripts", "This program requires the included Program.ini in the script directory.")

$GUI = GUICreate("Download Justin's Scripts", 632, 453)
_SetUp()

While 1
    $msg = GUIGetMsg()
        
    Switch $msg
        Case -3
            Exit
    EndSwitch
    
    For $I = 1 to UBound($Buttons) -1
        If $msg = $Buttons[$I] Then
            If Msgbox(1,$GetDescriptions[$I][0],$GetDescriptions[$I][1]) = 1 Then
                _IECreate($ProgramLinks[$I][1],0,1,0)
            EndIf
        EndIf
    Next
WEnd

Func _SetUp ()
    Local $GetButtons = IniReadSection($Ini, "Programs")
    For $I = 1 To $GetButtons[0][0]
        $Buttons[$I] = GUICtrlCreateButton($GetButtons[$I][1], 0, $ButtonPositionRight[$I])
    Next
    GUISetState(@SW_SHOW, $GUI)
    $GetButtons = IniReadSection($Ini, "Programs")
    $GetDescriptions = IniReadSection($Ini, "Descriptions")
    $ProgramLinks = IniReadSection($Ini,"ProgramLinks")
EndFunc

Func _FatalMsgbox($Icon, $Title, $Message)
    MsgBox($Icon, $Title, $Message)
    Exit
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...