Jump to content

Strange List Box malfunction...


LetsAuto
 Share

Recommended Posts

correct me if i am wrong, For loops are generally for numbers rather than searching for strings, right? or maybe im not understanding somethign fully... i have 2 cases... one for servers and one for desktops... what the program needs to do is

if line 1 says " # servers" then send string "xxxxx" to xx.txt OR if line 1 says "# desktops" then send string "yyyy" to yy.txt..

but i need it to evaluate both lines and right now what its doing is only evaluating the case until one option is true.. i think its because my stuff is set up in 2 separate Switches... so maybe when i do

"Case $finishButton

Switch $server

.

.

.

End switch

Switch $desktop

.

.

.

End switch

end switch

so maybe that is saying to only evaluate either of the cases for the first line of the list box until it finds a true statement....

WHAT IF..... i nest those two Switches inside of a for loop to do a line count? that should work right? evaluate it twice type of deal?

Link to comment
Share on other sites

LetsAuto,

_GUICtrlListBox_FindString returns an index into the LB, it looks like you are trying to do a string compare on that result.

What is all this for?

;;;;server variables
$sServer1 = "aaaaaaaaaaaaaaa"
$sServer2 = "bbbbbbbbbbbbbbbbbb"
$sServer3 = "ccccccccccccccc"
$sServer4 = "dddddddddddddddddddd"
$sServer = ""
;;;
$aServer1 = "eeeeeeeeeeeeeeeeeeeee"
$aServer2 = "fffffffffffffffffffffffffffff"
$aServer3 = "ggggggggggggggggggggg"
$aServer4 = "hhhhhhhhhhhhhhhhhhhhh"
$aServer = ""
;;;
$dServer1 = "iiiiiiiiiiiiiiiiii"
$dServer = ""
;;;
$iServer1 = "jjjjjjjjjjjjjjjjjjjjjjjjjj"
$iServer2 = "kkkkkkkkkkkkkkkkkkkkkkkkk"
$iServer = ""
;;;;;;;

;;;;;;;desktop variables
$sDesk1 = "lllllllllllllllllllllllll"
$sDesk2 = "mmmmmmmmmmmmmmmmmmmm"
$sDesk3 = "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"
$sDesk4 = "oooooooooooooooooooooooo"
$sDesk5 = "pppppppppppppppppppppp"
$sDesk6 = "qqqqqqqqqqqqqqqqqqqqqqq"
$sDesk = ""
;;;
$aDesk1 = "rrrrrrrrrrrrrrrrrrrrrrrrrrr"
$aDesk2 = "sssssssssssssssssssssss"
$aDesk = ""
;;;
$dDesk1 = "tttttttttttttttttttttttt"
$dDesk = ""
;;;
$iDesk1 = "uuuuuuuuuuuuuuuuuuuuuuuuuu"
$iDesk2 = "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
$iDeskTen = "wwwwwwwwwwwwwwwwwwwwww"
$iDesk = ""
;;;
$wDesk1 = "xxxxxxxxxxxxxxxxxxxxxxxx"
$wDesk = ""
;;;;;;;

As soon as I can understand what you are trying to do I will show you how to implement loops and functions to reduce the code significantly.

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

those are variables to be written to text documents depending on what strings appear when the server button or desktop button is pressed and the finishbutton is pressed.. because i want those variables to be saved, but people wont understand those variables so i sort of cover the variables with strings and save the variables according to the selected strings

Link to comment
Share on other sites

LetsAuto,

You missed (skipped) the part where I said to use an array for the values to check then loop through the array. What about some of the other questions that I've asked?

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

Once again, I have to ask, have you tried the script I posted, because you never answered that either? My script creates a listbox, then allows you to read the contents line by line until it hits the end of the list.

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

LetsAuto,

You seem reluctant to answer questions directly. This makes it difficult to discern the problem. The following code shows how to use a loop/array to replace the if...else...endif constructs. None of it is tested as you have not given enough info. The construct should work, however.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

#region ### START Koda GUI section ### Form=f:autoit3testingsautowizardform1.kxf
$Form1_1 = GUICreate("CALs", 752, 447, 425, 188)
$serverButton = GUICtrlCreateButton("Server", 240, 56, 105, 41)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$deskButton = GUICtrlCreateButton("Desktop", 400, 56, 105, 41)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$addedListBox = GUICtrlCreateList("", 432, 112, 260, 206)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$finishButton = GUICtrlCreateButton("Finish", 320, 336, 124, 49)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$addButton = GUICtrlCreateButton("--->", 336, 184, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$deleteButton = GUICtrlCreateButton("<---", 336, 240, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;; in log, updates list box ITEM 1 ONLY, ignores update for ITEM 3 ;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $serverButton
            $sValue = 0  ; simulate ini file read value
            ;$sValue = IniRead("C:IanLogTestradioButton.ini", "Brand", "Radio Checked", "Error!")
            Switch $sValue ;;;;;;;;;;;;;;;;;;;;;;;;;populates for servers
                Case "0" ;;;syam
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "1 sServer1")
                    _GUICtrlListBox_InsertString($calListBox, "5 sServer2")
                    _GUICtrlListBox_InsertString($calListBox, "10 sServer3")
                    _GUICtrlListBox_InsertString($calListBox, "20 sServer4")
                Case "1" ;;;acer
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "1 aServer1")
                    _GUICtrlListBox_InsertString($calListBox, "1 aServer2")
                    _GUICtrlListBox_InsertString($calListBox, "1 aServer3")
                    _GUICtrlListBox_InsertString($calListBox, "1 aServer4")
                Case "2" ;;;depo
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "5 dServer1")
                Case "3" ;;;itautec
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "1 iServer1")
                    _GUICtrlListBox_InsertString($calListBox, "5 iServer2")
                Case Else ;;disable server button for wipro
                    GUICtrlSetState($serverButton, $GUI_DISABLE)
            EndSwitch
        Case $deskButton
            $sValue = IniRead("C:IanLogTestradioButton.ini", "Brand", "Radio Checked", "Error!")
            Switch $sValue ;;;;;;;;;;;;;;;;;;;;;;;; populates for desktops
                Case "0" ;;;syam
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "1 sDesk1")
                    _GUICtrlListBox_InsertString($calListBox, "5 sDesk2")
                    _GUICtrlListBox_InsertString($calListBox, "10 sDesk2")
                    _GUICtrlListBox_InsertString($calListBox, "20 sDesk4")
                    _GUICtrlListBox_InsertString($calListBox, "50 sDesk5")
                    _GUICtrlListBox_InsertString($calListBox, "100 sDesk6")
                Case "1" ;;;acer
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "5 aDesk1")
                    _GUICtrlListBox_InsertString($calListBox, "5 aDesk2")
                Case "2" ;;;depo
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "5 dDesk1")
                Case "3" ;;;itautec
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "1 iDesk1")
                    _GUICtrlListBox_InsertString($calListBox, "5 iDesk2")
                Case "5" ;;;wipro
                    GUICtrlDelete($calListBox)
                    $calListBox = GUICtrlCreateList("", 56, 112, 260, 206)
                    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                    _GUICtrlListBox_InsertString($calListBox, "1 wDesk")
            EndSwitch
        Case $addButton
            _LeftToRight($calListBox, $addedListBox)
        Case $deleteButton
            delete($addedListBox, $calListBox)
        Case $finishButton
            Run("C:Program FilesAutoIt3AutoIt3.exe F:AutoIt3testingsautoWizardstep4.au3")
            $handle = WinGetHandle("Untitled - AutoIt", "")
            WinClose($handle)
            Run("C:Program FilesAutoIt3AutoIt3.exe F:AutoIt3testingsautoWizardstep4.au3")
            $handle = WinGetHandle("Untitled - AutoIt", "")
            WinClose($handle)

            ; loop to search for various things.  you will need to add whatever else you are searching for

            local $search_terms[4] = ['1 sServer1','5 sServer2','10 Sserver3','20 sServer4'], $ix
            for $1 = 0 to ubound($search_terms) - 1
                $ix = _GUICtrlListBox_FindString($addedListBox, $search_terms[$1],true)
                ConsoleWrite($ix & @LF)
                if $ix <> -1  Then lf(_GUICtrlListBox_GetText($addedListBox,$ix))   ; see function lf() below
            Next

    EndSwitch
WEnd


func lf($str)

    local $hfl = fileopen(@scriptdir & 'helpdesk.txt',1)   ; append
    filewrite($hfl,$str & @lf)
    fileclose($hfl)
    $hfl = 0

endfunc

;;;;;;;;;;;;;functions and button operations;;;;;;;;;;;;
Func _LeftToRight(Const $list, Const $addlist)
    Local $sRead
    $sRead = GUICtrlRead($list)
    ConsoleWrite($sRead & @CR)
    If $sRead = "" Then
        MsgBox(16 + 262144, @ScriptName, "No value selected!")
    Else
        ConsoleWrite(_GUICtrlListBox_DeleteString($list, _GUICtrlListBox_FindString($list, $sRead, True)) & @CR)
        ConsoleWrite(_GUICtrlListBox_AddString($addlist, $sRead) & @CR)
    EndIf
EndFunc   ;==>_LeftToRight

Func delete(Const $list, Const $rmvlist)
    Local $sRead
    $sRead = GUICtrlRead($list)
    ConsoleWrite($sRead & @CR)
    If $sRead = "" Then
        MsgBox(16 + 262144, @ScriptName, "No value selected!")
    Else
        ConsoleWrite(_GUICtrlListBox_DeleteString($list, _GUICtrlListBox_FindString($list, $sRead, True)) & @CR)
        ConsoleWrite(_GUICtrlListBox_AddString($rmvlist, $sRead) & @CR)
    EndIf
EndFunc   ;==>delete

This is as far as I am willing to go until I have enough answers to understand what you are doing!

kylomas

edit: corrected code

edit2: modified code to test. This runs and does what I am GUESSING that you want.

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

I got it to work, my supervisor said he was not really that picky and sort of just wanted it done, so i just broke it into two separate scripts, its the easy way out and i didnt learn how to fix this issue unfortunately, but where ive rebuilt the script 8 times now, i wanted it done.. thank you SO much for all of the help, im sorry i was hard to work with on this one

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