Sign in to follow this  
Followers 0
Champak

combo box ini read

10 posts in this topic

#1 ·  Posted (edited)

I found this script and 3 HOURS AGO and have been messing with it trying to adapt it to my needs, but every turn I make I'm ending up with the default data. Someone please help me. I've changed everything back to the original state, except one part so it is easier to understand what I'm trying to do(THE PART IN THE SECOND CASE STATMENT). Originally what this did was look for a file and then displayed the files after it, or something like that.

I want this to

1/ look inside an ini file and display the sections

2/ when I click on the section, box1 gets populated with the value under "User" and box2 gets populated with the value under "Pass".

3/ I want to exclude 2 specific sections from showing up in the combo box.(or do I need two seporate inis)

4/ A button that will connect to the internet and log in using the values in the inputs(I believe I can do this one on my own)

NOTE: the whole putting the values in an input box isn't going to be the end thing, this is just so I can see it for now, I am going to put it to a variable.

This is what I have

#include <GUIConstants.au3>
#Include <Array.au3>

$Form1 = GUICreate("Test Form", 273, 209, 387, 194)
$Profiles = GUICtrlCreateCombo("", 16, 24, 105, 21)
$Input1 = GUICtrlCreateInput($User, 152, 24, 105, 21)
$Input2 = GUICtrlCreateInput($Pass, 152, 64, 105, 21)

$Search = FileFindFirstFile("The.ini")
$ProfileArray = _ArrayCreate($Search)

While 1
    $File = FileFindNextFile($Search)
    If @error Then ExitLoop
    _ArrayAdd($ProfileArray, $File)
WEnd

FileClose($Search)

For $r = 1 To UBound($ProfileArray, 1) - 1
    GUICtrlSetData($Profiles, StringTrimRight($ProfileArray[$r], 4))
Next

$Current_Profile = GUICtrlRead($Profiles)

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case GUICtrlRead($Profiles) <> $Current_Profile
        $User = GUICtrlSetData($Input1, IniRead($Search, GUICtrlRead($Profiles), "User", "default"))
        $Pass = GUICtrlSetData($Input2, IniRead($Search, GUICtrlRead($Profiles), "Pass", "default"))
        $Current_Profile = GUICtrlRead($Profiles)
    Case Else
        ;;;;;;;
    EndSelect
WEnd
Exit

And yes I was trying it with iniread and inireadsection and sectionnames. Any help please.

Edited by Champak

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$Search = FileFindFirstFile("The.ini")
$ProfileArray = _ArrayCreate($Search)

While 1
    $File = FileFindNextFile($Search)
    If @error Then ExitLoop
    _ArrayAdd($ProfileArray, $File)
WEnd
Looks like it's your problem... You're not giving the actual directory... do this so you can see what I'm saying, you'll not see the entire path, and I doubt the ini is in the same directory if your using filefind otherwise you already know what's there.

$Search = FileFindFirstFile("The.ini")
$ProfileArray = _ArrayCreate($Search)

While 1
    $File = FileFindNextFile($Search)
    If @error Then ExitLoop
    _ArrayAdd($ProfileArray, $File)
WEnd
_ArrayDisplay($ProfileArray, 'Are the complete paths here?')

$PathToDirectory & '\' & $File is probably what you need.

Edit:

I also think that $Search is a handle ... so your _ArrayCreate() doesn't quite look right as well.

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

I don't think you got me...well maybe you did and we are mixed up.

1/ filefindnextfile...I basically know what that does, I just put the script back close to it's original state because I thought it may be easier for someone to help me from there.

2/ Is it really needed to put the path in, or did you say that because you thought I was looking for the file? I thought that is only needed if the extra files were in a different directory. With my other scripts I have not put the path in when the files were in the same folder and they work fine. (anyway, I put it in, but clarify this for me please)

3/ Here is what I really have that I feel should work, but it just wont, maybe this will be a better indication of where I'm stuck. The value will not post to the input boxes(or variables which is what I'll need later), even though the file and section are being read correctly with the test msgbox I set up. The default values keep popping up. Yes the ini is set up correctly.

#include <GUIConstants.au3>
#Include <Array.au3>

$Form1 = GUICreate("Test Form", 273, 309, 387, 194)
;$Profiles = GUICtrlCreateCombo("", 16, 24, 105, 21)
$Profiles2 = GUICtrlCreateCombo("", 16, 224, 105, 21)
$Input1 = GUICtrlCreateInput("", 152, 24, 105, 21, -1, $WS_EX_CLIENTEDGE)
$Input2 = GUICtrlCreateInput("", 152, 64, 105, 21, -1, $WS_EX_CLIENTEDGE)

$Sections = IniReadSectionNames("C:\Documents and Settings\Money\Desktop\Gui test\script\The.ini")

    For $i = 1 To UBound($Sections, 1) - 1
        GUICtrlSetData($Profiles2, $Sections[$i])
    Next

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case GUICtrlRead($Profiles2) 
        MsgBox(16, "test", GUICtrlRead($Profiles2)
        GUICtrlSetData($Input1, IniRead($Sections, GUICtrlRead($Profiles2), "User", "default"))
        GUICtrlSetData($Input2, IniRead($Sections, GUICtrlRead($Profiles2), "Pass", "default"))
    EndSelect
WEnd
Exit

Thanks.

Share this post


Link to post
Share on other sites

I don't think you got me...well maybe you did and we are mixed up.

1/ filefindnextfile...I basically know what that does, I just put the script back close to it's original state because I thought it may be easier for someone to help me from there.

2/ Is it really needed to put the path in, or did you say that because you thought I was looking for the file? I thought that is only needed if the extra files were in a different directory. With my other scripts I have not put the path in when the files were in the same folder and they work fine. (anyway, I put it in, but clarify this for me please)

3/ Here is what I really have that I feel should work, but it just wont, maybe this will be a better indication of where I'm stuck. The value will not post to the input boxes(or variables which is what I'll need later), even though the file and section are being read correctly with the test msgbox I set up. The default values keep popping up. Yes the ini is set up correctly.

#include <GUIConstants.au3>
#Include <Array.au3>

$Form1 = GUICreate("Test Form", 273, 309, 387, 194)
;$Profiles = GUICtrlCreateCombo("", 16, 24, 105, 21)
$Profiles2 = GUICtrlCreateCombo("", 16, 224, 105, 21)
$Input1 = GUICtrlCreateInput("", 152, 24, 105, 21, -1, $WS_EX_CLIENTEDGE)
$Input2 = GUICtrlCreateInput("", 152, 64, 105, 21, -1, $WS_EX_CLIENTEDGE)

$Sections = IniReadSectionNames("C:\Documents and Settings\Money\Desktop\Gui test\script\The.ini")

    For $i = 1 To UBound($Sections, 1) - 1
        GUICtrlSetData($Profiles2, $Sections[$i])
    Next

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case GUICtrlRead($Profiles2) 
        MsgBox(16, "test", GUICtrlRead($Profiles2)
        GUICtrlSetData($Input1, IniRead($Sections, GUICtrlRead($Profiles2), "User", "default"))
        GUICtrlSetData($Input2, IniRead($Sections, GUICtrlRead($Profiles2), "Pass", "default"))
    EndSelect
WEnd
Exit

Thanks.

I made something similar where it read an ini file. Grabed the section names and put it in the one drop down list. When I selected this section name it populated another drop down box of the contents of that section. Let me know if this is something along the lines you want. Here is some of the code without giving too much away as it was work related.

#include <GUIConstants.au3>
#include <process.au3>
#include <file.au3>
#include <array.au3>
#include <date.au3>

Dim $newvalue, $newvalue2, $tech, $actt[20]
Global $tech, $var, $mgr2, $file
AutoItSetOption("WinTitleMatchMode", 2)
AutoItSetOption("SendKeyDelay", 15)
$file = "manager.ini"
GUICreate("InfoCenter Ticket Summary", 275, 335, (@DesktopWidth - 275) / 2, (@DesktopHeight - 335) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUICtrlCreateGroup( "Manager/Associate Selection ", 10, 10, 256, 80)
GUICtrlCreateLabel( "Site Manager:", 45, 30, 70,20)
$mgr = GUICtrlCreateCombo("", 120, 27, 120)
GUICtrlCreateLabel( "Site Associate:", 45, 66, 70,20)
$tech = GUICtrlCreateCombo("", 120, 62, 120)
$mgrlist = inireadsectionnames ($file)

If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $mgrlist[0]
        $newvalue = $newvalue & $mgrlist[$i] & "|"
    Next
    GUICtrlSetData($mgr, StringTrimRight($newvalue, 1))
EndIf

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks, but I'm getting the same problem with that. I can't get the key to tranfer into the variable to be read by the iniread. It can be read by a test mebox, but not by the iniread. That's what's wierd to me. Any other help?

Edited by Champak

Share this post


Link to post
Share on other sites

Thanks, but I'm getting the same problem with that. I can't get the key to tranfer into the variable to be read by the iniread. It can be read by a test mebox, but not by the iniread. That's what's wierd to me. Any other help?

Can you post your INI for us.

Share this post


Link to post
Share on other sites

Can you post your INI for us.

[Tester]

User=nyrl

Pass=JustMe

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

[Tester]

User=nyrl

Pass=JustMe

Try this. Add more sections to your ini with User and Pass keys. I'm sure someone can tear this apart but it should get you started.

#include <GUIConstants.au3>
#include <GuiStatusBar.au3>
#Include <Array.au3>

Local $a_PartsRightEdge[1] = [274]
Local $a_PartsText[1] = ["This area for sale"]

$file = "the.ini"
Dim $newvalue, $userlist, $pass, $userlist[10], $passlist[10]
$sections = IniReadSectionNames("the.ini")
$Form1 = GUICreate("Test Form", 273, 209, 387, 194)
$profiles = GUICtrlCreateCombo('', 16, 24, 105, 21)
$user = GUICtrlCreateInput('', 152, 24, 105, 21)
$pass = GUICtrlCreateInput('', 152, 64, 105, 21)
$btn = GUICtrlCreateButton("Log In", 140, 90, 80, 30)
$StatusBar1 = _GUICtrlStatusBarCreate($Form1, $a_PartsRightEdge, $a_PartsText, $SBT_TOOLTIPS)
_GUICtrlStatusBarSetMinHeight($StatusBar1, 10)
$sections = IniReadSectionNames($file)
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $sections[0]
        $newvalue = $newvalue & $sections[$i] & "|"
    Next
    GUICtrlSetData($profiles, StringTrimRight($newvalue, 1))
EndIf

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $profiles
            $userlist = IniRead($file, GUICtrlRead($profiles), "User", "")
            GUICtrlSetData($user, $userlist)
            $passlist = IniRead($file, GUICtrlRead($profiles), "Pass", "")
            GUICtrlSetData($pass, $passlist)
        Case $msg = $btn
            MsgBox(4096, "Log in", "This is what you will log in with" & @CRLF & "Username: " & GUICtrlRead($user) & @CRLF & "Password: " & GUICtrlRead($pass))
        Case Else
    ;;;;;;;
    EndSelect
WEnd
Exit

The.ini

[Tester]
User=nyrl
Pass=JustMe

[More]
User=Superfly
Pass=Snuka

[Yoyo]
User=Jose
Pass=HoseB
Edited by powaking

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Oh, I see. The ini has to be read FIRST to be set in, it can't be done during the "function". I wouldn't have thought that would be necessary, simple enough. Thanks for your help.

EDIT: Oh, one more thing, how do I tell the combo box alone NOT to look at two particular sections, so they don't show up in the combo box? But reading those sections in the ini is still possible for the rest of the script....if that's possible.

Or maybe, put the sections I don't want read at the beginning of the ini, and tell the combo box to skip over the first two or three sections.

Also, what is this:

$userlist[10], $passlist[10]

What are those 10s in the brackets for? ...so I understand how this thing is working,

Edited by Champak

Share this post


Link to post
Share on other sites

Oh, I see. The ini has to be read FIRST to be set in, it can't be done during the "function". I wouldn't have thought that would be necessary, simple enough. Thanks for your help.

EDIT: Oh, one more thing, how do I tell the combo box alone NOT to look at two particular sections, so they don't show up in the combo box? But reading those sections in the ini is still possible for the rest of the script....if that's possible.

Or maybe, put the sections I don't want read at the beginning of the ini, and tell the combo box to skip over the first two or three sections.

Also, what is this:

$userlist[10], $passlist[10]

What are those 10s in the brackets for? ...so I understand how this thing is working,

The [#] are the size of the arrays. You can play around with them. Don't really need to use any array calls since when working with ini's they are treated as arrays anyway.

You can probably do If's to check if a section contains a name. Or better yet. Take the ini, copy it to a temp file, delete the inisections that you don't want then read the rest of the sections.

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