Jump to content

Pulling info from List


 Share

Recommended Posts

So I'm trying to make logging in a little easier for the ladies in my office. We log into one of our programs with a number ID rather then a user name. The program isn't used too often so they keep forgetting the number and have to come to me to look it up for them. The automation part of the script I can get down just fine, but I've got a few questions on input and such.

First off, here's my script

#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Example()
Func Example()
    Global $ListBox, $LoginButton, $Password
    GUICreate("BoxStor Login", 300, 250)
    GUISetFont(9, 300)
GUICtrlCreateLabel("User Name", 30, 25)
$ListBox = GUICtrlCreateList("", 30, 50, 150, 100)
$LoginButton = GUICtrlCreateButton("Login", 230, 155, 50, 25)
GUICtrlCreateLabel("Password", 30, 150)
$Password = GUICtrlCreateInput("", 30, 170, 100, 20, $ES_PASSWORD)
;Add Users
_GUICtrlListBox_BeginUpdate($ListBox)
  _GUICtrlListBox_AddString($ListBox, "144589. Chris")
  _GUICtrlListBox_AddString($ListBox, "110897. Dawn")
  _GUICtrlListBox_AddString($ListBox, "004789. Jean")
_GUICtrlListBox_EndUpdate($ListBox)
    GUISetState()
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $LoginButton
    Login()
  EndSelect
WEnd
  
EndFunc

Func Login()
Local $SelectedUser, $LoginInfo
; This whole section is just a mockup for the test. It will have automation for the logging in process once I figure this out.

$SelectedUser = _GUICtrlListView_ClickItem($ListBox)
$LoginInfo = "User: " & $SelectedUser " Password: " & GUICtrlRead($Password)
FileWrite('test.inf', $LoginInfo)
EndFunc

What I'm trying to get it to do is a user will select their name from the list (the list will be bigger, just for right now I'm only using three for testing) and type their password into the box and hit the Log in button. The Login button will then send the appropriate information to the log in screen on our program.

I've got two questions. First off, I'm not really 100% sure how to pull the information from the list and the password box and be able to use it again later. Is what I'm doing correct? And if so, I keep getting an error that I don't know how to fix.

Secondly, I don't want to send the whole string "144589. Chris" to the log in program, I just want to send the "144589", how would I go about doing this?

Thanks a lot for the help.

Edited by Zamphire
Link to comment
Share on other sites

Instead of using a Listbox you might consider using a ComboBox just for ease of use. Also, to get just the number from the string you can use StringLeft and grab the 6 characters starting from the left and send the result of that to whatever it is you're logging in to.

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

Link to comment
Share on other sites

zamphire,

I keep getting an error that I don't know how to fix.

what is the error?

See _GUICtrlListBox_GetSelItemsText and related items for listbox processing.

You have not said that the user will select an entry by clicking on it, I am asumming that this is the case.

kylomas

Edit: for something this simple follow BrewmanNH's suggestion...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Ok, I looked into Combo Boxes and that doesn't really seem to be what I want. The example that the helpfile has just makes a drop down list that you can edit? I don't want them editing it. Maybe I'm misunderstanding the use of the Combobox?

Anyway, I went ahead and looked up the other suggestions and I think I've got it figured out except for one thing. Here's the code:

#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Example()
Func Example()
    Global $ListBox, $LoginButton, $Password
    GUICreate("BoxStor Login", 300, 250)
    GUISetFont(9, 300)
GUICtrlCreateLabel("User Name", 30, 25)
$ListBox = GUICtrlCreateList("", 30, 50, 150, 100)
$LoginButton = GUICtrlCreateButton("Login", 230, 155, 50, 25)
GUICtrlCreateLabel("Password", 30, 150)
$Password = GUICtrlCreateInput("", 30, 170, 100, 20, $ES_PASSWORD)
;Add Items
_GUICtrlListBox_BeginUpdate($ListBox)
  _GUICtrlListBox_AddString($ListBox, "144589. Chris")
  _GUICtrlListBox_AddString($ListBox, "110897. Dawn")
  _GUICtrlListBox_AddString($ListBox, "004789. Jean")
_GUICtrlListBox_EndUpdate($ListBox)
    GUISetState()
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $LoginButton
    Login()
  EndSelect
WEnd 
  
EndFunc
 
Func Login()
Local $SelectedUser, $LoginInfo, $result

$SelectedUser = _GUICtrlListBox_GetSelItemsText($ListBox)
$result = StringLeft($SelectedUser, 6)
$LoginInfo = "User: " & $result " Password: " & GUICtrlRead($Password)
FileWrite('test.inf', $LoginInfo)
EndFunc

When I run it and select something and type in a password I get the following error:

==> Error in expression.:
$LoginInfo = "User: " & $result " Password: " & GUICtrlRead($Password)
$LoginInfo = ^ ERROR

What am I doing wrong? It looks like that should work to me.

Link to comment
Share on other sites

zamphire,

FYI - while the user can alter the data in a combo box the content do NOT change...I'm sure there is a way to prevent the user from altering what is displayed but don't know what it is offhand...

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

zamphire,

$LoginInfo = "User: " & $result & " Password: " & GUICtrlRead($Password)

missing one concatenation char...

kylomas

Woot! Almost working! No errors.

Got one small problem though, the test.inf file is missing the user information. All it says is

User:  Password: asdf

Any ideas?

Link to comment
Share on other sites

I got it working with Combo box!

In case you're wondering, here's the code I went with.

#include <GuiComboBox.au3>
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Example()
Func Example()
    Global $ListBox, $LoginButton, $Password
    GUICreate("BoxStor Login", 300, 250)
    GUISetFont(9, 300)
GUICtrlCreateLabel("User Name", 30, 25)
$ListBox = GUICtrlCreateCombo("", 30, 50, 150, 100)
$LoginButton = GUICtrlCreateButton("Login", 230, 155, 50, 25)
GUICtrlCreateLabel("Password", 30, 150)
$Password = GUICtrlCreateInput("", 30, 170, 100, 20, $ES_PASSWORD)
;Add Items
_GUICtrlComboBox_BeginUpdate($ListBox)
  _GUICtrlComboBox_AddString($ListBox, "144589. Chris")
  _GUICtrlComboBox_AddString($ListBox, "110897. Dawn")
  _GUICtrlComboBox_AddString($ListBox, "004789. Jean")
_GUICtrlComboBox_EndUpdate($ListBox)
    GUISetState()
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $LoginButton
    Login()
  EndSelect
WEnd 
  
EndFunc
 
Func Login()
Local $SelectedUser, $LoginInfo, $result

$SelectedUser = _GUICtrlComboBox_GetEditText($ListBox)
$result = StringLeft($SelectedUser, 6)
$LoginInfo = "User: " & $result & " Password: " & GUICtrlRead($Password)
FileWrite('test.inf', $LoginInfo)
EndFunc

Seems to work great. I appriciate all your help Kylomas

(Bte, Woot was just me being excited that I was making progress lol. Gotta appreciate the little victories.)

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...