Elephant007

Read INI Create Combo Read Output **Solved**

6 posts in this topic

#1 ·  Posted (edited)

I'm attempting to me a quick GUI that will read an ini file and make a drop down combo box displaying the printer name, select a printer name, click the button and display the printer path

The problem is when I click the button, I all the printer paths or just the last printer path

 

Printers.INI file sample

[PRINTERS]
Printer 1 = \\PRINTSERVER\PRINTER1
Printer 2 = \\PRINTSERVER\PRINTER2
Printer 3 = \\PRINT01\BW_PRINTER_1

Thank you in advance for your help

EDIT

Here's my script in it's ugly glory... I'm just tying to get it going first

#include <GUIConstantsEx.au3>

Local $APRINTERS = IniReadSection("Printers.ini", "PRINTERS")
Local $SPRINTERS = ""
For $I = 1 To $APRINTERS[0][0]
    $SPRINTERS &= "|" & $APRINTERS[$I][0]
Next
GUICreate("My GUI combo")
$Button = GUICtrlCreateButton('PrinterPath', 10, 40, 100, 100)
If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.")
$combo = GUICtrlCreateCombo("", 10, 10, 100, 40)
GUICtrlSetData(-1, $SPRINTERS)


GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            For $I = 1 To $APRINTERS[$I][1]
            Next
            MsgBox(0, '', $APRINTERS[$I][1])
    EndSwitch
WEnd

 

Edited by Elephant007

Share this post


Link to post
Share on other sites



Where's your script?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Where's your script?

Edit my op to show the script

Share this post


Link to post
Share on other sites

Here's one way to do it.

#include <GUIConstantsEx.au3>
Global $sIniFile = "Printers.ini"
Global  $APRINTERS = IniReadSection($sIniFile, "PRINTERS")
If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") ; Moved this line to where it should have been
Global $SPRINTERS = ""
For $I = 1 To $APRINTERS[0][0]
    $SPRINTERS &= "|" & $APRINTERS[$I][0]
Next
GUICreate("My GUI combo")
$Button = GUICtrlCreateButton('PrinterPath', 10, 40, 100, 100)
$combo = GUICtrlCreateCombo("", 10, 10, 100, 40)
GUICtrlSetData(-1, $SPRINTERS)


GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            MsgBox(0, '', IniRead($sIniFile, "Printers", GUICtrlRead($combo), "Error"))
    EndSwitch
WEnd

Ask if you have any questions.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

That worked perfect, thank you

The only question I have is, how does clicking the button know how to read and display the printer path?

Share this post


Link to post
Share on other sites

The GUICtrlRead reads the contents of the combobox, the IniRead takes that text and uses it as the key to read from in the INI file.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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