Jump to content

While statement in a Switch/Array Help


Recommended Posts

So like this?

EDIT: OK what was here was completely wrong.

I got it now to what its supposed to be but now i get a new error:

Posted Image

I would like to stick with just IniRead() since i know it works and its already there. I just wanted to use a constant for $Progs to make sure it stayed the same.

You declared the $Name_ array with only one element, which is [0]. So the first reference you make to it with $i = 1 gives you $Name_[1], which is out of range. Did the version I posted last (post #19) run?

:)

Edited by PsaltyDS
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

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

New Error:

Posted Image

Guessing it doesnt like a variable in the new variable name?

You are declaring an array with $i elements (has to be at least 1), and there is a special format to initialize an array. For example:

Global $MyOddArray[5] = [1, 3, 5, 7, 9]
Global $MyEvenArray[5] = ["zero", "two", "four", "six", "eight"]

Changed $i=0 and ini starts at 0 instead of 1

EDIT: Ya your script works except its doing that thing in the tray and closing again

What is "that thing in the tray"?

:)

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

remember before it opened then closed really fast in the tray

EDIT: I dont really want these to be arrays, i just thought it was the only way i could have it change the name of a variable

I just need it to be able to create $Name_## for how many programs there are.

Sorry for the confusion

Edited by Mast3rpyr0
Link to comment
Share on other sites

remember before it opened then closed really fast in the tray

EDIT: I dont really want these to be arrays, i just thought it was the only way i could have it change the name of a variable

I just need it to be able to create $Name_## for how many programs there are.

Sorry for the confusion

You can do that with Assign() and Eval(), but don't think that will turn out to be easier than proper arrays... :)

If you want to continue tweaking the script from post #19, add this debug line to help find out why it's exiting:

;Create Window
MsgBox(64, "Debug", "$Progs = " & $Progs) ; <-- Add this line to see if it is reading $Progs correctly
If $Progs > 0 Then

:)

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

Ok it works...kinda. Heres the script now with the problems commented out:

#include <GUIConstants.au3>
#include <Constants.au3>
#include <array.au3>

;Set Vars
Global $ScriptDir = @ScriptDir & "GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"
Global $ver = IniReadSection($ScriptDir & $ConfigINI, "Version")
Global $Progs = IniReadSection($ScriptDir & $ConfigINI, "Progs")
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ScriptDir & $ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_")
Global $Path_ = IniReadSection($ScriptDir & $ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_")

;Create Window
MsgBox(64, "Debug", "$Progs = " & $Progs) ; <-- Add this line to see if it is reading $Progs correctly
If $Progs > 0 Then
    $i = 1 ; program number
    $s = 80 ; top of buttons
    $MainWindow = GUICreate("Game Launcher v1.0", 415, 290)
    $Tab1 = GUICtrlCreateTab(0, 0, 417, 273)
    $Programs = GUICtrlCreateTabItem("Games");===>Games Tab
    MsgBox(64, "Debug", "$Path = " & $Path_) ; <-- Add this line to see if it is reading $Path correctly
    Do
        ;$Program_[$i] = GUICtrlCreateButton($Name_[$i], 237, $s, 120, 17)   <==== Problem 1
        $i = $i + 1
        $s = $s + 20
    Until $i > $Progs
    GUISetState(@SW_SHOW)

    ;Launch a Program
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE)
            ;Case $Exit  <===== Problem 2
                ExitLoop
        EndSwitch
        For $p = 1 To $Progs
            If $nMsg = $Program_ Then
                Run($Path_)
                Sleep(3000)
                ExitLoop
            EndIf
        Next
    WEnd
EndIf

The INI:

[Version]
ver=1.0

[Progs]
num=1

[Name]
1=IE
2=WMP


[Path]
1=C:\Program Files\Internet Explorer\iexplore.exe
2=C:\Program Files\Windows Media Player\wmplayer.exe

and what the program creates which is the problem, no buttons(But i think thats what is commented out It is exactly what im trying to do though). try compiling that and running it see if you can figure anything out that i cant.

Posted Image

Link to comment
Share on other sites

;Set Vars
Global $ScriptDir = @ScriptDir & "GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"
Global $ver = IniReadSection($ScriptDir & $ConfigINI, "Version")
Global $Progs = IniReadSection($ScriptDir & $ConfigINI, "Progs")
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ScriptDir & $ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_")
Global $Path_ = IniReadSection($ScriptDir & $ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_")oÝ÷ Ûú®¢×¢Ûh²Ú)é©x(Ú(¶«¶§Ë§¶)mçâ®Ëm)à³
+}ÓꮢԵV«²«¨¶Ç¶*'Æë¢G¨§jwg¢Øb¥±ì"(®K§¶)m«b±ø±yÖ§vWµø±yÒè¢HhÃMúIÊâ¦×b®+)­ê^×¢{h¶´ß ¨ø  Ò)jØS+(¡jËhmçhãF§w*.q©ãºËky÷«¶ayø¥y«4ß ¨ø  Ò®­éè­Â§­æx-â
#MúIÊâ¦Ðâ®+z)ài×^u¨vëy©"az­8^­íý²z0k+ajجv+)¬¢azè¥êÝjÖ¶Ø^µé©¢¶«È
ëk â²ZÉ׺-jצz{liº/xp¢}ýµÚ((¡Ûh'º{bØb²+,¶¶¢IºËkº{az+*'méhÁ©Ý±ç­«b·
+Æòv+)¬¢azè¥êÈ4(ק¶Àèm¶¼­¡§]¢·^nè-êÞ²Ú¶¬r¸©¶éí[aÊZ®Ü(®K¢ºÞrÙrjëh×6#include <GUIConstants.au3>
#include <Constants.au3>
#include <array.au3>

;Set Vars
Global $ScriptDir = @ScriptDir & "GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"
Global $ver = IniReadSection($ConfigINI, "Version")
Global $Progs = IniReadSection($ConfigINI, "Progs")
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_")
Global $Path_ = IniReadSection($ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_")
MsgBox(64, "Debug", "$ver = " & $ver" & @CRLF & $Progs = " & $Progs)

:)

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

Ok thanks, fixed a few little bugs in there and then it gets to

Global $Program_[$Progs + 1] ; Array to hold button control IDs

And stops. It doesnt liek $Progs beign in the name.

;Set Vars
Global $ScriptDir = @ScriptDir & "\GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"
MsgBox(64, "Debug", "$ConfigINI = " & $ConfigINI)
Global $ver = IniReadSection($ConfigINI, "Version")
Global $Progs = IniReadSection($ConfigINI, "Progs")
Global $Program_[$Progs] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_")
Global $Path_ = IniReadSection($ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_")
MsgBox(64, "Debug", "$ver = " & $ver & @CRLF & "$Progs = " & $Progs)
Link to comment
Share on other sites

Ok thanks, fixed a few little bugs in there and then it gets to

Global $Program_[$Progs + 1] ; Array to hold button control IDs

And stops. It doesnt liek $Progs beign in the name.

Hmm... Does the $ConfigINI come up correctly in your debug message? Let's move the other debug check back where you see what you are getting for $Progs before using it:

;Set Vars
Global $ScriptDir = @ScriptDir & "\GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"
MsgBox(64, "Debug", "$ConfigINI = " & $ConfigINI) ; <-- Temporary debug message
Global $ver = IniReadSection($ConfigINI, "Version")
Global $Progs = IniReadSection($ConfigINI, "Progs")
MsgBox(64, "Debug", "$ver = " & $ver & @CRLF & "$Progs = " & $Progs) ; <-- Temporary debug message
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_") ; <-- Temporary debug message
Global $Path_ = IniReadSection($ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_") ; <-- Temporary debug message

Post what you get at each of those four debug messages.

:)

Edited by PsaltyDS
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

First one shows the correct path to the INI

next shows prog and ver variables but they are blank for some reason

then it stops at Global $Program_[$Progs + 1] ; Array to hold button control IDs

Link to comment
Share on other sites

This works for me:

#include <GUIConstants.au3>
#include <Constants.au3>
#include <array.au3>

;Set Vars
Global $ScriptDir = @ProgramFilesDir & "\multimedia"
Global $ConfigINI = "c:\temp\Config.ini"
Global $Programs
Global $btn[2]
Global $ver = IniReadSection($ConfigINI, "Version")
_ArrayDisplay($ver,"$ver")
Global $Progs[2][2]
$Progs = IniReadSection($ConfigINI, "Progs")
_ArrayDisplay($Progs,"$progs")
Global $Program_[2] ; Array to hold button control IDs
Global $Location_[2]
Global $Name_[2][2] ; = IniReadSection($ConfigINI, "Name")
$Name_ = IniReadSection($ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_")
Global $Path_[2][2]
$Path_ = IniReadSection($ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_")

;Create Window
MsgBox(64, "Debug", "$Progs = " & $Progs[1][1]) ; <-- Add this line to see if it is reading $Progs correctly
If $Progs[1][1] > 0 Then
    $i = 1 ; program number
    $s = 80 ; top of buttons
    $MainWindow = GUICreate("Program Launcher v1.0", 415, 290)
    $Tab1 = GUICtrlCreateTab(0, 0, 417, 273)
    $Programs = GUICtrlCreateTabItem("Multimedia");===>Games Tab
    _ArrayDisplay($Programs,"$Programs")
    MsgBox(64, "Debug", "$Path = " & $Path_[$i][1]) ; <-- Add this line to see if it is reading $Path correctly
    Do
        MsgBox(1,"$name[$i]",$Name_[$i][1])
        $Program_[$i] = $Name_[$i][1]
        $Location_[$i] = $Path_[$i][1]
        $btn[$i] = GUICtrlCreateButton($Program_[$i], 237, $s, 120, 17)   ;<==== Problem 1
        $i = $i + 1
        $s = $s + 20
        ReDim $Program_[$i + 1]
        ReDim $Location_[$i + 1]
        ReDim $Progs[$i + 1][2]
        ReDim $Name_[$i + 1][2]
        ReDim $btn[$i + 1]
        MsgBox(1,"$i",$i)
    Until $i > $Progs[1][1]
    GUISetState(@SW_SHOW)

    ;Launch a Program
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE)
        EndSwitch
        For $p = 1 To $Progs[1][1]
            If $nMsg = $btn[$p] Then
                Run($Location_[$p])
                Sleep(3000)
                ExitLoop
            EndIf
        Next
    WEnd
EndIf
Edited by jefhal
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

First one shows the correct path to the INI

next shows prog and ver variables but they are blank for some reason

then it stops at Global $Program_[$Progs + 1] ; Array to hold button control IDs

Gahh! Just noticed something - you use IniRead for a single value. IniReadSection returns an array and is only for reading and entire section. The $ver and $Progs reads got changed to IniReadSection and should be IniRead:

;Set Vars
Global $ScriptDir = @ScriptDir & "\GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"
MsgBox(64, "Debug", "$ConfigINI = " & $ConfigINI) ; <-- Temporary debug message
Global $ver = IniRead($ConfigINI, "Version", "ver")
Global $Progs = IniRead($ConfigINI, "Progs", "num")
MsgBox(64, "Debug", "$ver = " & $ver & @CRLF & "$Progs = " & $Progs) ; <-- Temporary debug message
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_") ; <-- Temporary debug message
Global $Path_ = IniReadSection($ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_") ; <-- Temporary debug message

When that runs, you should get $ver and $Progs in regular string variables, and $Name_ and $Path_ should be arrays.

:)

P.S. IniRead needs the parameter for the value to read, too...

Edited by PsaltyDS
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

still comes up blank on the ver and progs msgbox but the script doesnt stop till its done

Tweaked, see my previous post...

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

i had already fixed that, i think its the problem with the "Default" part of the function. you hvae to put something there

Right you are. So does it work now?

;Set Vars
Global $ScriptDir = @ScriptDir & "\GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"
MsgBox(64, "Debug", "$ConfigINI = " & $ConfigINI) ; <-- Temporary debug message
Global $ver = IniRead($ConfigINI, "Version", "ver", "")
Global $Progs = IniRead($ConfigINI, "Progs", "num", 0)
MsgBox(64, "Debug", "$ver = " & $ver & @CRLF & "$Progs = " & $Progs) ; <-- Temporary debug message
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ConfigINI, "Name")
_ArrayDisplay($Name_, "Name_") ; <-- Temporary debug message
Global $Path_ = IniReadSection($ConfigINI, "Path")
_ArrayDisplay($Path_, "Path_") ; <-- Temporary debug message

:)

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

Shows:

ver=

Progs= 0

I dont think the default part should be part of this function

The default is only presented when something goes wrong with the INI read. This is not deep juju here. Something very basic is screwed up in your INI here. Run this as a separate script. This is more like how I code my scripts, with massive error checking at every step:

#include <array.au3>
;Set Vars
Global $ScriptDir = @ScriptDir & "\GLaunch\Launcher Files"
Global $ConfigINI = $ScriptDir & "\Info Files\Config.ini"

If FileExists($ConfigINI) Then
    Global $ver = IniRead($ConfigINI, "Version", "ver", "")
    Global $Progs = IniRead($ConfigINI, "Progs", "num", 0)
    MsgBox(64, "Debug", "$ver = " & $ver & @CRLF & "$Progs = " & $Progs) ; <-- Temporary debug message
Else
    MsgBox(16, "Error", "File not found: " & $ConfigINI)
    Exit
EndIf

Global $Program_[$Progs + 1] ; Array to hold button control IDs

Global $Name_ = IniReadSection($ConfigINI, "Name")
If @error Then
    MsgBox(16, "Error", "Could not read [Name] section: " & $ConfigINI)
    Exit
EndIf
Global $Path_ = IniReadSection($ConfigINI, "Path")
If @error Then
    MsgBox(16, "Error", "Could not read [Path] section: " & $ConfigINI)
    Exit
EndIf
_ArrayDisplay($Name_, "Name_") ; <-- Temporary debug message
_ArrayDisplay($Path_, "Path_") ; <-- Temporary debug message

:)

Edited by PsaltyDS
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

What does the whole code look like now? The code I posted (whole thing) works and the buttons work too...

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
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...