Sign in to follow this  
Followers 0
king9072

HELP! Left clicking a listbox item and input not working correctly

2 posts in this topic

#1 ·  Posted (edited)

Hey all brief summary of my situation, I own a franchise and instead of keeping customer loyalty cards (as we previously did which got very hectic with 2000+ cards to track), I have decided to write a program that I can catalog all customers and update their current count.

So, since I am learning this language as I go since yesterday you will probably see that I have done some mindless things in my script which could have been avoided using complex variables and functions etc, but I don't mind writing more code than needed if it gets the job done.

Now my issue, I have everything working almost as necessary but when I search for a customer if only one name matches the search it will pop open a dialog for me to edit that one users details which works well. BUT my issue is that when a search returns more than one name, I have it display the results in a listbox. Now what I wish to do from there is be able to simply double click an entry and from there popup an input box similar to the one which comes up when only one name is returned.

To see what I mean, run my script and search for "dave" since the customer db only has one dave, it pops up the proper dialog so that person can be edited. Now search for steve and it will load the listbox with all the steves.

Also, for the program to work (again back to me being a rookie at this) it requires 3 text files, one for customers, 1 for how many cards, and 1 for how many total cards they have completed. Yes I know I could eliminate this with a proper array, but that stuff is a little beyond me at this point and this system works fine for me now. These files need to be in scriptdir.

Edit: You will notice that I have an edit customer button, I origonally planned for this but now that I am thinking about it, it would practically be identical to the search button. So if it makes it any easier, it would be nice of clicking that button edited the highlighted item in the listbox thanks!

EDIT: Just letting you know I have spent all day searching the forums looking for answers as well as I am continuing to do that now. Another additional bug that I cant seem to completely fix is

if you remove the sleep (search my code) for some reason the search quits working all together, it simply exits the input and remains at the gui... doing nothing.... but simply adding a sleep INSTANTLY fixes it, it is also fixed if instead of putting the sleep I do a _arraydisplay, I guess just having the script pause a second seems to get the script working properly. But without that pause it does not work.

#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <String.au3>
#include <GuiConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>


Dim $db
Dim $customers
Dim $cards
Dim $cardcount
Dim $splitme
Dim $splitter
Dim $customerloc
Dim $customerloc2
$listmessage = ""





$Form1 = GUICreate("AForm1", 242, 220, 374, 198)
$List1 = GUICtrlCreateList($listmessage, 8, 24, 113, 188)
$Button1 = GUICtrlCreateButton("Search", 128, 24, 105, 25, 0)
$Button2 = GUICtrlCreateButton("Edit Existing", 128, 56, 105, 25, 0)
$Button3 = GUICtrlCreateButton("Add New Customer", 128, 88, 105, 25, 0)
$Button4 = GUICtrlCreateButton("MVC", 128, 184, 105, 25, 0)
$Button5 = GUICtrlCreateButton("Total Customers", 128, 152, 105, 25, 0)
$Label1 = GUICtrlCreateLabel("", 24, 8, 178, 17)
GUISetState(@SW_SHOW)

If Not _FileReadToArray(@ScriptDir & "/customers.txt", $customers) Then
    
    MsgBox(4096, "Error", " Error reading customers file    error:" & @error)
    Exit
EndIf

If Not _FileReadToArray(@ScriptDir & "/cards.txt", $cards) Then
    
    MsgBox(4096, "Error", " Error reading card count file   error:" & @error)
    Exit
EndIf


If Not _FileReadToArray(@ScriptDir & "/cardcount.txt", $cardcount) Then
    
    MsgBox(4096, "Error", " Error reading customers file    error:" & @error)
    Exit
EndIf



While 1
    
    $msg = GUIGetMsg()
    Select
        
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop


;;;;;;;;;;; SEARCH BUTTON;;;;;;;;;;;;;;;;;;;
        Case $msg = $Button1
;================================================================================================


============================================================


            If Not IsDeclared("input1") Then Local $input1
            $input1 = InputBox("Customer Search", "Enter the full name of the customer:", "", " ", "215", "120", "-1", "-1")

;$List1 = GUICtrlCreateList("", 8, 24, 113, 188)
            $customerloc = _arrayfindall ($customers, $input1, 1, $customers[0], 0, 1)
            $customerstring = _ArrayToString($customerloc, ",")
            $customerloc2 = StringSplit($customerstring, ",")



            Sleep(3000)

            Select
                
                Case @error = 0;OK - The string returned is valid

                    
    ; If only one customer is found then proceed here, otherwise "else"
                    If $customerloc2[0] = 1 Then
                        
        ; Check to see if the customer is able to redeem yet
                        If $cards[$customerloc2[1]] >= 10 Then
                            $redeemmsg = "This customer currently has enough stamps to redeem their free smoothie, if they wish to use their free smoothie credit this visit please enter 0 into the box below. Otherwise, just press OK. "
                            $1height = "315"
                        Else
                            $redeemmsg = ""
                            $1height = "250"
                        EndIf
                        
                        If Not IsDeclared("foundinput") Then Local $foundinput
                        $foundinput = InputBox("Customer found! " & $customers[$customerloc2[1]], "The customer you were searching for has been found. Their current count's are listed below, to add MULTIPLE stamps, to their current stamp count total edit the number in the box below. Otherwise, just press ok and 1 stamp will be added to their total." & @CR & @CR & "Customer name: " & $customers[$customerloc2[1]] & @CR & "Current stamp count: " & $cards[$customerloc2[1]] & @CR & "Total cards filled: " & $cardcount[$customerloc2[1]] & @CR & @CR & $redeemmsg, $cards[$customerloc2[1]], " ", "-1", $1height, "-1", "-1")
                        
                        Select
                            
                            Case @error = 0;OK - The string returned is valid

                                If $foundinput = 0 Then
                                    $cardcount[$customerloc2[1]] = $cardcount[$customerloc2[1]] + 1
                                    _FileWriteFromArray(@ScriptDir & "/cardcount.txt", $cardcount, 1)
                                Else
                                    $cards[$customerloc2[1]] = $cards[$customerloc2[1]] + 1
                                    _FileWriteFromArray(@ScriptDir & "/cards.txt", $cards, 1)
                                EndIf
                                
                                
                            Case @error = 1;The Cancel button was pushed

                            Case @error = 3;The InputBox failed to open
                        EndSelect

                    Else
                        
                        If $customerloc2[0] > 1 Then
                            
                            $update = 0
                            $x = 1
                            
                            _GUICtrlListBox_BeginUpdate ($List1)
                            _GUICtrlListBox_ResetContent ($List1)
                            _GUICtrlListBox_EndUpdate ($List1)

                            While $update < $customerloc2[0]
                                
                                _GUICtrlListBox_BeginUpdate ($List1)
                                _GUICtrlListBox_InsertString ($List1, $customers[$customerloc2[$x]], -1)
                                _GUICtrlListBox_EndUpdate ($List1)
                                $update = $update + 1
                                $x = $x + 1
                            WEnd
                        EndIf
                    EndIf
                    



                Case @error = 1;The Cancel button was pushed
                Case @error = 3;The InputBox failed to open

            EndSelect
            #EndRegion --- CodeWizard generated code End ---





;;;;;;;;;;; TOTAL CUSTOMERS BUTTON;;;;;;;;;;
        Case $msg = $Button5

            MsgBox(0, "Total Customers", " The total amount of customers in our database is: " & $customers[0])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;; MVC BUTTON;;;;;;;;;;;;;;;;;;;;;;
        Case $msg = $Button4
            $maxloc = _ArrayMaxIndex($cardcount)
            $max = _ArrayMax($cardcount, 1)
            $maxloc = $maxloc - 1
            $truemax = $max * 10 + $cards[$maxloc]
            $mvcmessage = $customers[$maxloc] & @CR & "This customer has earned a total of " & $truemax & " stamps"
            MsgBox(0, "Our most valuable customer is...", $mvcmessage)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


            
;;;;;;;;;;;;; Edit Current Customer;;;;;;;;;;;;;;;;;;;;;;;


            
        Case $msg = $Button2
            $editsearchloc = ""
            If Not IsDeclared("editsearch") Then Local $editsearch
            $editsearch = InputBox("Edit Customer", "Enter the customers name which you would like to edit", "", " ", "-1", "-1", "-1", "-1")
            Select
                Case @error = 0;OK - The string returned is valid
                Case @error = 1;The Cancel button was pushed
                Case @error = 3;The InputBox failed to open
                    
            EndSelect
            
            $editsearchloc = _ArraySearch($customers, $editsearch, "", "", 0, 1)
            
            
            
            
;================================================================================================


=================================================================================
;;;;;;;;;;;;; ADD NEW CUSTOMER;;;;;;;;;;;;;;;;;;;;;;;;;;;; COMPLETE WORKING
        Case $msg = $Button3
            Local $newname
            Local $newcardnumber
            Local $newcardcount

            If Not IsDeclared("newname") Then Local $newname
            $newname = InputBox("New Customer", "Enter new customers full name", "", " ", "-1", "-1", "-1", "-1")
            Select
                Case @error = 0;OK - The string returned is valid
                Case @error = 1;The Cancel button was pushed
                Case @error = 3;The InputBox failed to open
            EndSelect
            
            If Not IsDeclared("newcardnumber") Then Local $newcardnumber
            $newcardnumber = InputBox("Amount of Stamps", "Enter the amount of stamps this customer has earned:", "", " ", "-1", "-1", "-1", "-1")
            Select
                Case @error = 0;OK - The string returned is valid
                Case @error = 1;The Cancel button was pushed
                Case @error = 3;The InputBox failed to open
            EndSelect

            If Not IsDeclared("newcardcount") Then Local $newcardcount
            $newcardcount = InputBox("Number of Cards", "Enter the number of completed cards this customer has earned", "", " ", "-1", "-1", "-1", "-1")
            Select
                Case @error = 0;OK - The string returned is valid
                Case @error = 1;The Cancel button was pushed
                Case @error = 3;The InputBox failed to open
            EndSelect

            $countlines = $customers[0] + 1

;; Blank name field solver;;
            If $newname = "" Then
                MsgBox(48, "MUST ENTER NAME", "You must enter a customer name to add.")

                If Not IsDeclared("newname") Then Local $newname
                $newname = InputBox("New Customer", "Enter new customers full name", "", " ", "-1", "-1", "-1", "-1")
                Select
                    Case @error = 0;OK - The string returned is valid

                    Case @error = 1;The Cancel button was pushed

                    Case @error = 3;The InputBox failed to open

                EndSelect

                _ArrayInsert($customers, $countlines, $newname)
                _FileWriteFromArray(@ScriptDir & "/customers.txt", $customers, 1)
                _ArrayInsert($cards, $countlines, $newcardnumber)
                _FileWriteFromArray(@ScriptDir & "/cards.txt", $cards, 1)
                _ArrayInsert($cardcount, $countlines, $newcardcount)
                _FileWriteFromArray(@ScriptDir & "/cardcount.txt", $newcardcount, 1)
            Else
                _ArrayInsert($customers, $countlines, $newname)
                _FileWriteFromArray(@ScriptDir & "/customers.txt", $customers, 1)
                _ArrayInsert($cards, $countlines, $newcardnumber)
                _FileWriteFromArray(@ScriptDir & "/cards.txt", $cards, 1)
                _ArrayInsert($cardcount, $countlines, $newcardcount)
                _FileWriteFromArray(@ScriptDir & "/cardcount.txt", $newcardcount, 1)
            EndIf
    EndSelect
    
    
    
WEnd

cardcount.txt

cards.txt

customers.txt

Edited by king9072

Share this post


Link to post
Share on other sites



Hi,

Just curious, how many stamps per card, or should I say how many stamps to get a free smoothie?

I've added the double click to the list, but if I knew the above then I could merge the 3 db text files into 1 file.

Let me know and I'll post your updated code if you like.

Cheers

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