Jump to content

Displaying all rows from a text file in an Edit Control


Simmy
 Share

Recommended Posts

Hi Everyone,

Thanks so much for the opportunity to post. This is my first one.

Guys, Im a newbie to autoit, and trying to work out what is wrong with the code im working on.

Basically, here is what im trying to do is to use dsquery computer -name <computername> * to return all computers from Active Directory.

The problem is that even though I get multiple records returned in the outputted text file, only one line is being displayed in my Edit Control, and that line is the very last line from that text file.

Any help would be greatly appreciated.

#include <Constants.au3>
#include <GUIConstants.au3>
#include <ListboxConstants.au3>
#include <EditConstants.au3>
#include <ListviewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



$pcname = InputBox("PC Name","Please input a Computer Name:")
RunWait(@ComSpec & ' /c dsquery.exe computer -name ' & $pcname & '* > c:\pcname.txt','',@SW_HIDE)
GUICreate("PC Name", 700,300)
GUICtrlCreateLabel ($pcname,  10, 10)
$mylist=GUICtrlCreateEdit("", 10,30,500,200, $WS_VSCROLL)


$close=GUICtrlCreateButton ("Close", 75,370,55,25)
$FileOpen = FileOpen('c:\pcname.txt', 0)
If $FileOpen = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($FileOpen)
    If $line = "" Then ExitLoop
    GUICtrlSetData($mylist,$line)

Wend

FileClose($FileOpen)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()

    Select
         Case $msg = $close
            FileDelete('c:\pcname.txt')
            Exit
    EndSelect
Wend

post-65297-0-01714500-1307452448_thumb.j

Link to comment
Share on other sites

Try _GUICtrlEdit_AppendText($mylist, $line & @CRLF) instead of GUICtrlSetData($mylist,$line).

You have to include GuiEdit.au3.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi UEZ and ahmet.

Guys thanks so much for this I really appreciate it.

Can I please just ask 2 more things about this code?

What you guys have given to me works, so I really thank you for that.

Issue 1:

Currently, if I enter nothing, and click on either cancel or ok button, I still get results back.

What I would like is:

If the Cancel button is selected, then the script exits.

If nothing is put into the input box, and the ok button is clicked, then a msgbox would come up prompting you to "You must first enter a computer".

Issue 2:

When the results are returned, its as if the original controls have vanished.

That is, I cannot see the label control for: GUICtrlCreateLabel etc.

Is there a way to have the input box visible all the time along with the label, so that when the results are returned in the edit control, I can see the label, input box, and edit control?

I so much appreciate your kind help.

Link to comment
Share on other sites

1)

Try this:

#include <Constants.au3>
#include <GUIConstants.au3>
#include <ListboxConstants.au3>
#include <EditConstants.au3>
#include <ListviewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


Do
    $pcname = InputBox("PC Name","Please input a Computer Name:")
    If @error = 1 Then Exit MsgBox(0, "Information", "Closing script")
    If $pcname = "" Then MsgBox(0, "Information", "You must enter a computer name")
Until $pcname <> ""
RunWait(@ComSpec & ' /c dsquery.exe computer -name ' & $pcname & '* > c:\pcname.txt','',@SW_HIDE)
GUICreate("PC Name", 700,300)
GUICtrlCreateLabel ($pcname,  10, 10)
$mylist=GUICtrlCreateEdit("", 10,30,500,200, $WS_VSCROLL)


$close=GUICtrlCreateButton ("Close", 600,70,55,25)
$read=FileRead("c:\pcname.txt")
GUICtrlSetData($mylist,$read)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()

    Select
         Case $msg = $close
            FileDelete('c:\pcname.txt')
            Exit
    EndSelect
Wend

2) I can see the label with the name you entered in the input box. The close button is behind the edit control. The input box cannot be visible with the main gui because input box will stop the script until you entered something.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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