Jump to content

Iniread Into An Array


Recommended Posts

Creating a toolbox type app where a user can customize it if they wish. The customization is in the form of a ini file. Trying to figure out how to read the Key's of the inifile as the name of the button and the value of each key to its appropriate execution of the button. I'm a noob but have progressed quite a bit. Keep having trouble with arrays.

I've tried doing an _arraycreate and _arrayadd inside the For...Next section but that didn't seem to help. I may be looking at this the wrong way. Just need some direction.

Thanks

Here's what the code looks like so far.

#include <GuiConstants.au3>
#include <inet.au3>
#include <array.au3>
#include <file.au3>
Dim $value[7],$button[7]
$var = inireadsection("c:\config.ini","buttons")

If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To Ubound($var[0][0],1)-1
    $button = $button & $var[$i][0]
    $value = _arraycreate($var[$i][1])
    Next
EndIf
_arraydisplay($button,"Buttons")
_arraydisplay($value,"Values")
GuiCreate("Shortcut Toolbar", 325, 55,(@desktopwidth/2)-130,2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS),$WS_EX_TOOLWINDOW)

$Button_2 = GuiCtrlCreateButton($button[0], 5, 5, 75, 20)
$Button_3 = GuiCtrlCreateButton($button[1], 5, 30, 75, 20)
$Button_4 = GuiCtrlCreateButton($button[2], 85, 5, 75, 20)
$Button_5 = GuiCtrlCreateButton($button[3], 85, 30, 75, 20)
$Button_6 = GuiCtrlCreateButton($button[4], 165, 5, 75, 20)
$Button_7 = GuiCtrlCreateButton("Send Email", 165, 30, 75, 20)
$Button_8 = GuiCtrlCreateButton($button[5],245,5,75,20)
$Button_9 = GuiCtrlCreateButton($button[6],245,30,75,20)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $button_2
        run($value[0])
    Case $msg = $Button_3
        run($value[0])
    Case $msg = $Button_4
        run($value[1])
    Case $msg = $Button_5
        run($value[2])
    Case $msg = $Button_6
        run($value[3])
    Case $msg = $Button_7
        _Inetmail("","Enter Subject","")
    Case $msg = $Button_8
        run($value[4])
    Case $msg = $Button_9
        run($value[5])
    EndSelect
WEnd
Exit

The config.ini is nothing more than a standard ini file.

[buttons]
Google="explorer http://www.google.com"
Explorer="explorer"
Notepad="notepad"
Link to comment
Share on other sites

  • Moderators

You already created the array... with inireadsection.. Why are you trying to recreate it?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You already created the array... with inireadsection.. Why are you trying to recreate it?

I need to have the buttons show the Key of the inifile and in the Case statements execute the Data of the key.

Maybe I should ask it this way. How do I assign variables from the inifile as such so that I can create multiple buttons using the Key's from an ini file and assign each buttons 'click' to its appropriate Data.

Edited by powaking
Link to comment
Share on other sites

  • Moderators

Here try this:

#include <GuiConstants.au3>
#include <inet.au3>
Dim $var = IniReadSection("c:\config.ini","buttons")
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
EndIf
$Main = GUICreate("Shortcut Toolbar", 325, 55, (@DesktopWidth/2)-130,2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS),$WS_EX_TOOLWINDOW)
$Button_2 = GUICtrlCreateButton($var[1][0], 5, 5, 75, 20)
$Button_3 = GUICtrlCreateButton($var[2][0], 5, 30, 75, 20)
$Button_4 = GUICtrlCreateButton($var[3][0], 85, 5, 75, 20)
$Button_5 = GUICtrlCreateButton($var[4][0], 85, 30, 75, 20)
$Button_6 = GUICtrlCreateButton($var[5][0], 165, 5, 75, 20)
$Button_7 = GUICtrlCreateButton("Send Email", 165, 30, 75, 20)
$Button_8 = GUICtrlCreateButton($var[6][0],245,5,75,20)
$Button_9 = GUICtrlCreateButton($var[7][0],245,30,75,20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_2
            Run($var[1][1])
        Case $msg = $Button_3
            Run($var[2][1])
        Case $msg = $Button_4
            Run($var[3][1])
        Case $msg = $Button_5
            Run($var[4][1])
        Case $msg = $Button_6
            Run($var[5][1])
        Case $msg = $Button_7
            _Inetmail ("","Enter Subject","")
        Case $msg = $Button_8
            Run($var[6][1])
        Case $msg = $Button_9
            Run($var[7][1])
    EndSelect
WEnd
Exit
Edit:

Forgot to change $value to $var on a couple of them

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Here try this:

#include <GuiConstants.au3>
#include <inet.au3>
Dim $var = IniReadSection("c:\config.ini","buttons")
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
EndIf
$Main = GUICreate("Shortcut Toolbar", 325, 55, (@DesktopWidth/2)-130,2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS),$WS_EX_TOOLWINDOW)
$Button_2 = GUICtrlCreateButton($var[1][0], 5, 5, 75, 20)
$Button_3 = GUICtrlCreateButton($var[2][0], 5, 30, 75, 20)
$Button_4 = GUICtrlCreateButton($var[3][0], 85, 5, 75, 20)
$Button_5 = GUICtrlCreateButton($var[4][0], 85, 30, 75, 20)
$Button_6 = GUICtrlCreateButton($var[5][0], 165, 5, 75, 20)
$Button_7 = GUICtrlCreateButton("Send Email", 165, 30, 75, 20)
$Button_8 = GUICtrlCreateButton($var[6][0],245,5,75,20)
$Button_9 = GUICtrlCreateButton($var[7][0],245,30,75,20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_2
            Run($var[1][1])
        Case $msg = $Button_3
            Run($var[2][1])
        Case $msg = $Button_4
            Run($var[3][1])
        Case $msg = $Button_5
            Run($var[4][1])
        Case $msg = $Button_6
            Run($var[5][1])
        Case $msg = $Button_7
            _Inetmail ("","Enter Subject","")
        Case $msg = $Button_8
            Run($var[6][1])
        Case $msg = $Button_9
            Run($var[7][1])
    EndSelect
WEnd
Exit
Edit:

Forgot to change $value to $var on a couple of them

Thanks. Progress. Buttons now populate the Keys but when I click ona button I get

Error: Unable to execute the external program.

And it references to run($var[1][1])

Edit: I think its with my INI file and how the data field is configured. Some of the buttons work, ironically, the ones that are NOT explorer shortcuts. Will test more but I think I have it now. Thanks!!!!!!!!

Edited by powaking
Link to comment
Share on other sites

  • Moderators

Your ini needs to look like this:

[buttons]Google=http://www.google.com

Explorer=explorer.exe

Notepad=notepad.exe

And your file like this (pay attention to the one that you call the URL on)
#include <GuiConstants.au3>
#include <inet.au3>
Dim $var = IniReadSection("c:\config.ini","buttons")
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
EndIf
$Main = GUICreate("Shortcut Toolbar", 325, 55, (@DesktopWidth/2)-130,2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS),$WS_EX_TOOLWINDOW)
$Button_2 = GUICtrlCreateButton($var[1][0], 5, 5, 75, 20)
$Button_3 = GUICtrlCreateButton($var[2][0], 5, 30, 75, 20)
$Button_4 = GUICtrlCreateButton($var[3][0], 85, 5, 75, 20)
$Button_5 = GUICtrlCreateButton($var[4][0], 85, 30, 75, 20)
$Button_6 = GUICtrlCreateButton($var[5][0], 165, 5, 75, 20)
$Button_7 = GUICtrlCreateButton("Send Email", 165, 30, 75, 20)
$Button_8 = GUICtrlCreateButton($var[6][0],245,5,75,20)
$Button_9 = GUICtrlCreateButton($var[7][0],245,30,75,20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_2
            Run(@ComSpec & " /c Start " & $var[1][1], '', @SW_HIDE)
        Case $msg = $Button_3
            Run($var[2][1])
        Case $msg = $Button_4
            Run($var[3][1])
        Case $msg = $Button_5
            Run($var[4][1])
        Case $msg = $Button_6
            Run($var[5][1])
        Case $msg = $Button_7
            _Inetmail ("","Enter Subject","")
        Case $msg = $Button_8
            Run($var[6][1])
        Case $msg = $Button_9
            Run($var[7][1])
    EndSelect
WEnd
Exit

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Your ini needs to look like this:

And your file like this (pay attention to the one that you call the URL on)

#include <GuiConstants.au3>
#include <inet.au3>
Dim $var = IniReadSection("c:\config.ini","buttons")
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
EndIf
$Main = GUICreate("Shortcut Toolbar", 325, 55, (@DesktopWidth/2)-130,2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS),$WS_EX_TOOLWINDOW)
$Button_2 = GUICtrlCreateButton($var[1][0], 5, 5, 75, 20)
$Button_3 = GUICtrlCreateButton($var[2][0], 5, 30, 75, 20)
$Button_4 = GUICtrlCreateButton($var[3][0], 85, 5, 75, 20)
$Button_5 = GUICtrlCreateButton($var[4][0], 85, 30, 75, 20)
$Button_6 = GUICtrlCreateButton($var[5][0], 165, 5, 75, 20)
$Button_7 = GUICtrlCreateButton("Send Email", 165, 30, 75, 20)
$Button_8 = GUICtrlCreateButton($var[6][0],245,5,75,20)
$Button_9 = GUICtrlCreateButton($var[7][0],245,30,75,20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_2
            Run(@ComSpec & " /c Start " & $var[1][1], '', @SW_HIDE)
        Case $msg = $Button_3
            Run($var[2][1])
        Case $msg = $Button_4
            Run($var[3][1])
        Case $msg = $Button_5
            Run($var[4][1])
        Case $msg = $Button_6
            Run($var[5][1])
        Case $msg = $Button_7
            _Inetmail ("","Enter Subject","")
        Case $msg = $Button_8
            Run($var[6][1])
        Case $msg = $Button_9
            Run($var[7][1])
    EndSelect
WEnd
Exit
Just realized taht I have to use the comspec. Could put a check for each case if it contains a url then use the run command with comspec otherwise just a normal run.
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...