Sign in to follow this  
Followers 0
the7thcolumn

AutoIt rules. But I need a hand.

10 posts in this topic

Morning, I have just started out using AutoIt and I like it! It is going to make automation very easy. Im not new to programming but I suck at it. I have taken (in order of complexity) Turing, HTML, Powershell, Perl; classes before so I understand how programming is supposed to work. I just need a hand actually getting there. I understand the theroy and the goal its just the process. Im a hardware guy in need of a software goal.

Here is my goal:

To automate a script that checks my (correctally formatted csv) file for a users extension and then displays their hostname and username based of extension. I have all that working but I seem to have broken it when adding a exit command.

The script loops on perpous so that I don't have to open it every 3 seconds.

Im trying to add a exit command.

I need to remove the output commands I tried to nuke the $output var but I ended up breaking it.

While True
    $input = FileOpen("Source.csv",0)
    $output = FileOpen("results.csv",2)
    $FINDME = InputBox("Finder 0.1","What extension or name are you looking for?")

    While True
        

        
        $line = FileReadLine($input)

        if @error = -1 then ExitLoop 
    if FileExists ("source.csv") Then ;Checking to see if the file exists if not prompt the user
        
        if StringInStr($line,$FINDME) Then
            MsgBox(0,"Finder 0.1 - Results","x" &$FINDME & " found:" & @crlf & " " & $line & @CRLF & " ")
        ElseIf $line="0,0,0,0" Then
            MsgBox(0,"Did Not Find",$FINDME & " Not Found")
            
        else MsgBox (4096, "Missing extension list SOURCE.CSV") ;This is the prompt
    EndIf   
            
            
        EndIf

    WEnd

    
WEnd

Can someone help me clean this up a bit?

Also I would eventually like to add a but of a GUI (noting complicated) but I want the hostname to be copied into the clipboard. Can someone direct me in the way of a good tutorial to get that done?

Thanks

Share this post


Link to post
Share on other sites



How often do you want it to check the csv file? Could you post an example of the csv file?

And the function to copy data to the clipboard is ClipPut.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Here's something to consider:

#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>

$fileName = "Source.csv"

If NOT FileExists($fileName) Then
    MsgBox(0, "", "Source file is missing.")
    Exit
EndIf

Global $line = ""

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 297, 155, -1, -1)
$Input = GUICtrlCreateInput("", 16, 34, 151, 21)
$Label1 = GUICtrlCreateLabel("Name to search for:", 16, 8, 113, 17)
$Button1 = GUICtrlCreateButton("Search", 192, 32, 75, 25, 0)
$Output = GUICtrlCreateInput("", 16, 100, 151, 21)
$Button2 = GUICtrlCreateButton("Clipboard", 192, 96, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ReadCSVFile()
        Case $Button2
            ClipPut($line)
    EndSwitch
WEnd


Func ReadCSVFile()
    
    $FINDME = GUICtrlRead($Input)
    
    $loopCount = _FileCountLines($fileName)
    
    For $i = 1 to $loopCount
        $line = FileReadLine($fileName, $i)
        If StringInStr($line, $FINDME) Then
            GUICtrlSetData($Output, $line)
            ExitLoop
        EndIf
    Next
EndFunc

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

How often do you want it to check the csv file? Could you post an example of the csv file?

And the function to copy data to the clipboard is ClipPut.

Ok cool Ill look into ClipPut

This is the csv, how often it checks is not important I don't care if it checks it every time since there are less then 300 entries, it can check every time for all I care.

323 NAME HOSTNAME

324 NAME HOSTNAME

334 NAME HOSTNAME

357 NAME HOSTNAME

300 NAME HOSTNAME

At the end of the hostname I have 0, 0, 0, 0 as a EOF for the program

Edited by the7thcolumn

Share this post


Link to post
Share on other sites

Here's something to consider:

#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>

$fileName = "Source.csv"

If NOT FileExists($fileName) Then
    MsgBox(0, "", "Source file is missing.")
    Exit
EndIf

Global $line = ""

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 297, 155, -1, -1)
$Input = GUICtrlCreateInput("", 16, 34, 151, 21)
$Label1 = GUICtrlCreateLabel("Name to search for:", 16, 8, 113, 17)
$Button1 = GUICtrlCreateButton("Search", 192, 32, 75, 25, 0)
$Output = GUICtrlCreateInput("", 16, 100, 151, 21)
$Button2 = GUICtrlCreateButton("Clipboard", 192, 96, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ReadCSVFile()
        Case $Button2
            ClipPut($line)
    EndSwitch
WEnd


Func ReadCSVFile()
    
    $FINDME = GUICtrlRead($Input)
    
    $loopCount = _FileCountLines($fileName)
    
    For $i = 1 to $loopCount
        $line = FileReadLine($fileName, $i)
        If StringInStr($line, $FINDME) Then
            GUICtrlSetData($Output, $line)
            ExitLoop
        EndIf
    Next
EndFunc

Man this is really good! How would I be able to tell it to copy just Field 3 for example in the .CSV

323 NAME HOSTNAME

324 NAME HOSTNAME

334 NAME HOSTNAME

Also this only searches and displays the first entry the nice thing about it looping before was if there were two MIKE's then it would output like the following

Search: Mike

Mike, IT, localhost

Mike C, mcans, mcans01

Share this post


Link to post
Share on other sites

I would have to imput that line into a hash no?

Share this post


Link to post
Share on other sites

I would have to imput that line into a hash no?

You put the split the string by delimiting with the commas. The results are put into an array.

$array = StringSplit($line, ",")

Then you reference the array position with $array[0], $array[1] or $array[2].


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Morning, I have just started out using AutoIt and I like it! It is going to make automation very easy. Im not new to programming but I suck at it. I have taken (in order of complexity) Turing, HTML, Powershell, Perl; classes before so I understand how programming is supposed to work. I just need a hand actually getting there. I understand the theroy and the goal its just the process. Im a hardware guy in need of a software goal.

Here is my goal:

Guru in (something) here.

Suggest some new goals. Better spelling and less :).

Turing. Mmm might that be the "Alan Turing" language.


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

You put the split the string by delimiting with the commas. The results are put into an array.

$array = StringSplit($line, ",")

Then you reference the array position with $array[0], $array[1] or $array[2].

This worked GREAT! Thanks for the help now its time to tweak it abit! The code you gave me was great thanks.

You guys truly are a asset to computer people!

Share this post


Link to post
Share on other sites

Guru in (something) here.

Suggest some new goals. Better spelling and less :).

Turing. Mmm might that be the "Alan Turing" language.

Sorry I was trying to type that on my cell. Excuse my inability to spell with large hands and a small keypad.

Yes Alan Turing hes the man!

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