Sign in to follow this  
Followers 0
Skorpius666

GUI Comp. File search Help!

15 posts in this topic

Hello everyone,

I am completely new to AutoIT. I have been tampering with Xcode though. not much.

now we got that out of the way.

I have a question and was hoping someone here could answer this or point me in the right direction.

I am trying to make a program that will basically.

1: 1 input box to enter a spec# in and have it show that number and a few details such as a company name in a msg box with 2 buttons, an ok, and cancel button (for verification)

2: upon hitting the ok button it will open another window that shows the spec document in full.

3: in new window, it has another input box (such as a keyword finder) so I can find the specific info I am searching for.

--I am also wondering if autoIT can enter data into another program such as a third party software from an input box in the GUI.

I don't expect anyone to write this type of program for me, I am just asking to be pointed in the right direction. I know this is the GUI Help but my question goes with both and I don't want to double post.

I have looked all over the help files and online, but can't seem to find the right answers to my questions.

Thank you in advance for any help and advice I am given.

Share this post


Link to post
Share on other sites



Hi, Skorpius666, welcome to the forum. The short answer to your question is yes, this can be accomplished with AutoIt (rarely do I see anyone saying they can't accomplish something in AutoIt). For more specific direction:

1: 1 input box to enter a spec# in and have it show that number and a few details such as a company name in a msg box with 2 buttons, an ok, and cancel button (for verification)

With the InputBox function, you can have a user enter in data such as your spec#. You can then use that information to produce your Msgbox. Something like this is a simple example:

$input = InputBox("My Word Library", "Please enter the article number")

If $input = "10236" Then
MsgBox(1, "Article 10236", "Is this the article you would like to open?")
EndIf

2: upon hitting the ok button it will open another window that shows the spec document in full.

There are many ways you can go about this, depending on what the document is. You could just call the document, like so:

$input = InputBox("My Word Library", "Please enter the article number")

If $input = "10236" Then
$doublecheck = MsgBox(1, "Article 10236", "Is this the article you would like to open?")
EndIf

If $doublecheck = 1 Then
ShellExecute(@ScriptDir & "\10236.docx")
EndIf

3: in new window, it has another input box (such as a keyword finder) so I can find the specific info I am searching for.

--I am also wondering if autoIT can enter data into another program such as a third party software from an input box in the GUI.

For #3, I would suggest using the program's built-in search function (be it Word, or your PDF reader). This is typically going to be faster than you parsing the document looking for a keyword. But if your requirement is solid, you can likewise use an InputBox for this.

The answer to your last question is yes, AutoIt can take data you give it and input that into a third party app. How you go about that depends on the app (web, java, etc.)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Thank you very much JLogan3o13. That helped a lot. I was also curious. Is there a way to search a directory for the file or would I have to enter every file name into the code? Again. Thank you very much

Share this post


Link to post
Share on other sites

You should have a look at the AutoIt help file it outlines a bunch of native AutoIt functions and also UDF functions for use in directory/file management. As JLogan said (i am only learning AutoIt still myself) i also find very few things that this language CANT do, and thats without the help of the knowledgable people on the forum.

To point you in the right direction i think you're looking for something like the FindFileFirst and FindFileNext functions.

Share this post


Link to post
Share on other sites

Wayfarer,

Thanks for you help.

The only time I can really mess with AutoIT is when I'm at work and I stay pretty busy. I am usually running through the help file but to me, they don't explain it very well.

I've been trying this project of mine for a little over a week now and it's just been driving me insane. Thats why I came here.

Thanks again, to the both of you.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I would do something like this, so you just have to define the directory where the documents are:

$dir = @DesktopDir & "Test" ;<===Where our files are stored, 100 PDFs, numbered 1 to 100.
$input = InputBox("My PDF Library", "Please enter the article number")

   If FileExists($dir & $input & ".pdf") Then ;<==Check for the existence of the file first
      $doublecheck = MsgBox(1, "Article " & $input, "Is this the article you would like to open?")
   Else
      MsgBox(0, "Error", "Article " & $input & " does not exist. Please check your article number and try again.");<===If the file doesn't exist, throw an error.
   EndIf

   If $doublecheck = 1 Then
      ShellExecute($dir & $input & ".pdf")
   EndIf
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

OK this is starting to make a little more sense. I have been tempting this for a while now. I am trying to male this more complicated than it is. When I write it like JLogan with my own for it doesn't seem to work. I am trying to make it a little bit more in depth. I'll probably set my old xp desktop up at home and try it more there. Thanks again guys.

Share this post


Link to post
Share on other sites

Go ahead and post what you have when you get a chance, we can then take a look and tweak your code where needed.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

ok, I appreciate it... I'll get the au3 when I go back to work... I am adding a password to the script... I got that part... When I get home tonight I'll post what I have (which is really nothing since I have been swamped..) but I found the autoit 1.2.3 thing and am going to look it over and see if there is anything in there that can help me... I most likely won't post it today due to lack of code in the script. But will post by tuesday.

I was also wondering. Since this is complicating to me without seeing something similar to what I am trying to do (which I haven't really explained much, which I will explain further when I post the script) I was wondering if anyone knew of any good tutorials based on GUI's and file searching. I usually search using my phone at work since my computer isn't connected to the internet. So PDF and document based tutorials would be best.

The reason the help file doesn't really help me much is because it's so spread out between things and it is going to take me forever to get my windows based desktop at home running again. Anyways, I'll post what I have by Tuesday or Wednesday.

Thanks again, you have been a great help...

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

JLogan, Here is the code that I was writing for that GUI.

$Password = "secret"

$retryCount = 0

While 1

If $retryCount > 2 Then Exit

$input = InputBox("Password dialog", "Enter the password to continue", "", "*")

If @error Or $input <> $Password Then

MsgBox(4096, "Article", "Error", "Incorrect password")

Else

MsgBox(4096, "Article", "Press Ok to continue")

ExitLoop

EndIf

WEnd

$Password = "secret"

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=c:documents and settingsadministratordesktopnew folder (2)specsearch.kxf

$specSearch = GUICreate("Specification Search", 307, 225, 192, 124)

$file1 = GUICtrlCreateMenu("File")

$exit1 = GUICtrlCreateMenuItem("Exit", $file1)

$help1 = GUICtrlCreateMenu("Help")

$help2 = GUICtrlCreateMenuItem("Help", $help1)

$about1 = GUICtrlCreateMenuItem("About", $help1)

$inputBox = GUICtrlCreateInput("Spec# Here", 32, 48, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))

$search = GUICtrlCreateButton("Search", 40, 104, 75, 25)

$cancel = GUICtrlCreateButton("Cancel", 176, 104, 75, 25)

$Spec = @DesktopDir & "Spec"

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Or $msg = $cancel Or $msg = $exit1 Then

Exit

EndIf

If $msg = $search Then

GUICtrlRead($inputBox)

EndIf

If FileExists($Spec & $inputBox & ".txt") Then

$doublecheck = MsgBox(1, "Article" & $inputBox, "Verify Article")

Else

MsgBox(0, "Error", "Article" & $inputBox, " does not exist, Please check your Spec# and try again.")

EndIf

If $doublecheck = (1) Then

ShellExecute($Spec & $inputBox & ".txt")

EndIf

WEnd

Exit

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

I'm not sure what I am doing wrong here, it comes up with an "article 8 error" The password part works fine. I enter the password (secret) and then it says I entered it correct... but it won't open the GUI I made with Koda...

I really do appreciate your help.

Edited by Skorpius666

Share this post


Link to post
Share on other sites

Your GUISetState is in the wrong place, it needs to be before the While loop. Also, you should probably move the first part of your code below the #include lines, just better coding practice that way.


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

Share this post


Link to post
Share on other sites

Your GUISetState is in the wrong place, it needs to be before the While loop. Also, you should probably move the first part of your code below the #include lines, just better coding practice that way.

Ok, so basically it would look something like this?

I won't be able to try it until later on, but I will see if I get the same error...

I was reading, and I'm not sure where I read it, but I think I read that XP, Vista, and Windows 7 are all written different. I was wondering if that is true?

Also, thank you for your insight.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Password = "secret"
$retryCount = 0
While 1
    If $retryCount > 2 Then Exit
    $input = InputBox("Password dialog", "Enter the password to continue", "", "*")
    If @error Or $input <> $Password Then
        MsgBox(4096, "Article", "Error", "Incorrect password")
    Else
        MsgBox(4096, "Article", "Press Ok to continue")
        ExitLoop
    EndIf
WEnd

$Password = "secret"


#Region ### START Koda GUI section ### Form=c:documents and settingsadministratordesktopnew folder (2)specsearch.kxf
$specSearch = GUICreate("Specification Search", 307, 225, 192, 124)
$file1 = GUICtrlCreateMenu("File")
$exit1 = GUICtrlCreateMenuItem("Exit", $file1)
$help1 = GUICtrlCreateMenu("Help")
$help2 = GUICtrlCreateMenuItem("Help", $help1)
$about1 = GUICtrlCreateMenuItem("About", $help1)
$inputBox = GUICtrlCreateInput("Spec# Here", 32, 48, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$search = GUICtrlCreateButton("Search", 40, 104, 75, 25)
$cancel = GUICtrlCreateButton("Cancel", 176, 104, 75, 25)
$Spec = @DesktopDir & "Spec"
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancel Or $msg = $exit1 Then
        Exit
    EndIf

    If $msg = $search Then
        GUICtrlRead($inputBox)
    EndIf

    If FileExists($Spec & $inputBox & ".txt") Then
        $doublecheck = MsgBox(1, "Article" & $inputBox, "Verify Article")
    Else
        MsgBox(0, "Error", "Article" & $inputBox, " does not exist, Please check your Spec# and try again.")
    EndIf

    If $doublecheck = (1) Then
        ShellExecute($Spec & $inputBox & ".txt")
EndIf
WEnd
Exit


#EndRegion ### END Koda GUI section ###

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I noticed a couple of points that may give you issues. In your password portion, you define $retryCount, but you never increment it. So if I put in the wrong password, or click cancel, I get stuck in an infinite loop. I would suggest something like this:

$Password = "secret"
$retryCount = 1

While 1
If $retryCount > 2 Then Exit
$input = InputBox("Password dialog", "Enter the password to continue", "", "*")

If @error = 1 Or $input <> $Password Then <---@error 1 on an InputBox is the Cancel button
     MsgBox(4096, "Article", "Error", "Incorrect password")
     $retryCount += 1 <---Be sure to increment the retry value on failures.
Else
     MsgBox(4096, "Article", "Press Ok to continue")
     ExitLoop
EndIf

WEnd

I also noticed, due to the way you had your If statements positioned, you would receive an error as soon as the GUI opens. For cleaner reading, I would suggest a Select statement to loop through your possible actions. Something like this:

$specSearch = GUICreate("Specification Search", 307, 225, 192, 124)
$file1 = GUICtrlCreateMenu("File")
$exit1 = GUICtrlCreateMenuItem("Exit", $file1)
$help1 = GUICtrlCreateMenu("Help")
$help2 = GUICtrlCreateMenuItem("Help", $help1)
$about1 = GUICtrlCreateMenuItem("About", $help1)
$inputBox = GUICtrlCreateInput("Spec# Here", 32, 48, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$search = GUICtrlCreateButton("Search", 40, 104, 75, 25)
$cancel = GUICtrlCreateButton("Cancel", 176, 104, 75, 25)
$Spec = @DesktopDir & "Spec"

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()
     Select
         Case $msg = $GUI_EVENT_CLOSE
         Exit
         Case $msg = $cancel
         Exit
         Case $msg = $exit1
         Exit
         Case $msg = $search
         GUICtrlRead($inputBox)
             If FileExists($Spec & GUICtrlRead($inputBox) & ".txt") Then
                 $doublecheck = MsgBox(1, "Article" & GUICtrlRead($inputBox), "Verify Article (" & GUICtrlRead($inputBox) & ")")
                     If $doublecheck = 1 Then ShellExecute($Spec & GUICtrlRead($inputBox) & ".txt")
             Else
             MsgBox(0, "Error", "Article" & $inputBox, " does not exist, Please check your Spec# and try again.")
             EndIf
     EndSelect

WEnd

Edited for my stunningly poor grammar.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I do have a quick question. How do I upload a .au3 file to my attachments so I can place it on here so you can see my progress on this topic? I can't open it on my computer at home and insert the code because I am on a Mac, unless I am missing a way to open it on my Mac.

Share this post


Link to post
Share on other sites

And so, basically I patted myself on the back because I figured out that you can open .au3 on a Mac with Xcode :dance: . I basically took one of the first posts on here, added a username password section, but. I can't figure out 2 things, and all of the other snippets doesn't quite explain how to make the username password save per user. I am also having trouble writing it so that when the password is written, it calls up the 2nd GUI, without using the #include. I am basically trying to write it so that it will all save under one .exe.

For some reason or another( I am also writing another script that I will be able to complete after this is solved ) When I click on the cancel button, it still asks if it is the right document. again I've tried several things which, well, doesn't do what I need it to do.

Anyways, here is my code for the Username and Password. I haven't encrypted it yet because I just want it to work first, I can do the encryption part with one of the tools, or at least I think I can. :blink:

Here is the username, password script.

#NoTrayIcon
#include 
#include 
$Form0 = GUICreate("User | Password", 220, 100, -1, -1)
$userr = GUICtrlCreateInput ("UserName", 2, 2, 100, 22)
$passs = GUICtrlCreateInput ("Password", 2, 32, 100, 22)
$go = GUICtrlCreateButton ("OK", 2, 62)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop

case $msg = $go
if GUICtrlRead ($userr) <> "UserName" or GUICtrlRead ($passs) <> "Password" Then
MsgBox (4096, "Warning", "Password was entered incorrectly")
Exit
ElseIf GUICtrlRead ($userr) = "UserName" or GUICtrlRead ($passs) = "Password" Then
#include 
Sleep(1000)
Send ("{ESC}")
EndIf

EndSelect
WEnd

Next is the code to search for the file and open it.

$dir = @DesktopDir & "Spec"
$input = InputBox("Spec Library", "Please enter Article Number")

If FileExists($dir & $input & ".txt") Then
    $doublecheck = msgbox(1, "Article " & $input, "Is this the correct Article")
Else
    MsgBox(0, "Error", "Article " & $input & " does not exist, Please check your article number and try again.")
EndIf

If $doublecheck = 1 Then
    ShellExecute($dir & $input & ".txt")
    Exit
    EndIf

I really wanted this to be a little bit more complicated, such as me creating the GUI, but this is sufficient enough. It gets the job done.

And just so everyone knows, I have searched the help file, countless times. I've searched these forums and other forums and have turned up nothing for an answer. :mad2:

Thanks in advance.

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