Jump to content
Sign in to follow this  
pbecks1963

Making an automated inquiry

Recommended Posts

pbecks1963

Hello Y'all,

I am playing around with autoit and decided to make an automated Inquiry ("enquette" in Dutch or Questionaire?)

See script below:

***************************************************

; filename to write

$file_to_write = @ScriptDir & "\InquiryAnswers.txt"

; open file to read and store the handle

$handle_write = FileOpen($file_to_write, 2); erase mode

$x = 1

$count = 0

Do

$file_to_read = @ScriptDir & "\InquiryQuestions.txt"

; open file to read and store the handle

$handle_read = FileOpen($file_to_read, 0)

; check the handle is valid

; loop through each line of the file

While 1

; read each line from a file

$line_read = FileReadLine($handle_read)

; exit the loop if end of file

$answer = InputBox("blabla", $line_read , "", " M", _

-1, -1, 0, 0)

If $count < 4 Then $count = $count + 1

if $count = 1 Then $answer1 = $answer

if $count = 2 Then $answer2 = $answer

if $count = 3 Then $answer3 = $answer

if $count = 4 Then

$answer4 = $answer

ExitLoop

Endif

WEnd

FileWriteLine($handle_write, $answer1 & "," & $answer2 & "," & $answer3 & "," & $answer4)

$count = 0

Until $x = 0

; close the file handle for read

FileClose($handle_read)

; close the file handle for write

FileClose($handle_write)

*******************************************************************

This results in a file which can easily imported into excel as a csv-file (comma seperated file).

Trouble is: it is clumpsy (i am still quit new "at autoit"). If there are more then 4 more questions i will need to rewrite a part of the script. And then there is the problem with terminating the Inquiry in a clean way... And (not to forget!) How do i enlarge, pimp the inputbox?

Do you have a suggestion?

Edited by pbecks1963

Share this post


Link to post
Share on other sites
Melba23

pbecks1963,

Here ia another way to do what you want. Note the differences from your script:

1. Use of @error to escape from the loop - FileReadLine sets the @error whan it gets to the end of a file, so you need not worry about how long it is.

2. Use of an array to hold the answers - you can increase the array size as you go so again no worries about size.

3. Use of a loop to get the answers from the array into a single string to write.

; Set filenames
$file_to_write = @ScriptDir & "\InquiryAnswers.txt"
$file_to_read = @ScriptDir & "\InquiryQuestions.txt"

; open file to read and store the handle
$handle_read = FileOpen($file_to_read, 0)
; open file to Write and store the handle
$handle_write = FileOpen($file_to_write, 2); erase mode

Global $aAnswers[1] = [0]

; loop through each line of the file
While 1

    ; read each line from a file
    $line_read = FileReadLine($handle_read)
    ; exit the loop if end of file
    If @error = -1 Then ExitLoop

    ; get answer to question
    $answer = InputBox("blabla", $line_read, "", " M")

    ; Increase count
    $aAnswers[0] += 1
    ; Increase array size
    ReDim $aAnswers[$aAnswers[0] + 1]
    ; Save answer
    $aAnswers[$aAnswers[0]] = $answer

WEnd

; Collect answers
$sAllAnswers = ""
For $i = 1 To $aAnswers[0] - 1
    $sAllAnswers &= $aAnswers[$i] & ","
Next
$sAllAnswers &= $aAnswers[$i]

; Write file
FileWriteLine($handle_write, $sAllAnswers)

; close the file handle for read
FileClose($handle_read)
; close the file handle for write
FileClose($handle_write)

I hope it is all clear - please ask if not. :mellow:

To "pimp" your InputBox, you will neeed to write your own GUI - here is an example (although it looks very much like an InputBox at the moment :( !):

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

; Set filenames
$file_to_write = @ScriptDir & "\InquiryAnswers.txt"
$file_to_read = @ScriptDir & "\InquiryQuestions.txt"

; open file to read and store the handle
$handle_read = FileOpen($file_to_read, 0)
; open file to Write and store the handle
$handle_write = FileOpen($file_to_write, 2); erase mode

Global $aAnswers[1] = [0]

; loop through each line of the file
While 1

    ; read each line from a file
    $line_read = FileReadLine($handle_read)
    ; exit the loop if end of file
    If @error = -1 Then ExitLoop

    ; get answer to question
    $answer = _Get_Answer()

    ; Increase count
    $aAnswers[0] += 1
    ; Increase array size
    ReDim $aAnswers[$aAnswers[0] + 1]
    ; Save answer
    $aAnswers[$aAnswers[0]] = $answer

WEnd

; Collect answers
$sAllAnswers = ""
For $i = 1 To $aAnswers[0] - 1
    $sAllAnswers &= $aAnswers[$i] & ","
Next
$sAllAnswers &= $aAnswers[$i]

; Write file
FileWriteLine($handle_write, $sAllAnswers)

; close the file handle for read
FileClose($handle_read)
; close the file handle for write
FileClose($handle_write)

Exit

Func _Get_Answer()

    $hGUI = GUICreate("BlaBlaBla", 180, 100, Default, Default, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)

    GUICtrlCreateLabel($line_read, 10, 10, 160, 20)

    $hInput = GUICtrlCreateInput("", 10, 40, 160, 20)

    $hOK_Button = GUICtrlCreateButton("OK", 10, 70, 75, 20)
    $hCan_Button = GUICtrlCreateButton("Cancel", 95, 70, 75, 20)

    GUISetState()

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hCan_Button
                Exit
            Case $hOK_Button
                $sAnswer = GUICtrlRead($hInput)
                GUIDelete($hGUI)
                Return $sAnswer
        EndSwitch

    WEnd

EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
pbecks1963

Hello M23,

This is my script so far (works, although i am not sure if i coded the loop properly). I am unsure where to begin tweaking the GUI. Where should i start? What i want is a big fat messagebox, big font, so i am looking for a way to do that. And then there is the problem of closing the script once the last Inquiry has been made (right now i have to manualy close the script AND i have to click "cancel".

Can you give me some more pointers...?

*********************************

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

; Set filenames

$file_to_write = @ScriptDir & "\InquiryAnswers.txt"

$file_to_read = @ScriptDir & "\InquiryQuestions.txt"

; open file to read and store the handle

$handle_read = FileOpen($file_to_read, 0)

; open file to Write and store the handle

$handle_write = FileOpen($file_to_write, 2); erase mode

$x = 0

Global $aAnswers[1] = [0]

Do

; loop through each line of the file

While 1

; read each line from a file

$line_read = FileReadLine($handle_read)

; exit the loop if end of file

If @error = -1 Then ExitLoop

; get answer to question

$answer = InputBox("blabla", $line_read, "", " M", -1, -1, 0, 0)

; Increase count

$aAnswers[0] += 1

; Increase array size

ReDim $aAnswers[$aAnswers[0] + 1]

; Save answer

$aAnswers[$aAnswers[0]] = $answer

WEnd

; Collect answers

$sAllAnswers = ""

For $i = 1 To $aAnswers[0] - 1

$sAllAnswers &= $aAnswers[$i] & ","

Next

$sAllAnswers &= $aAnswers[$i]

; Write file

FileWriteLine($handle_write, $sAllAnswers)

$handle_read = FileOpen($file_to_read, 0)

Global $aAnswers[1] = [0]

Until $x = 1

; close the file handle for read

FileClose($handle_read)

; close the file handle for write

FileClose($handle_write)

Func _Get_Answer()

$hGUI = GUICreate("Vraag!", 2000, 2000, Default, Default, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)

GUICtrlCreateLabel($line_read, 10, 10, 160, 200)

$hInput = GUICtrlCreateInput("", 10, 40, 160, 20)

$hOK_Button = GUICtrlCreateButton("OK", 10, 70, 75, 20)

$hCan_Button = GUICtrlCreateButton("Cancel", 95, 70, 75, 20)

GUISetState()

While 1

Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE, $hCan_Button

Exit

Case $hOK_Button

$sAnswer = GUICtrlRead($hInput)

GUIDelete($hGUI)

Return $sAnswer

EndSwitch

WEnd

EndFunc

*************

Share this post


Link to post
Share on other sites
Melba23

pbecks1963,

First pointer: when you post code please use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). Or press the blue button just under the BOLD toolbar button.

But my better half has just called me to the table. Please be patient and I will return after I have eaten! :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
pbecks1963

Ok, got it.

code here

:mellow:

Share this post


Link to post
Share on other sites
pbecks1963

Little change in the code..

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

; Set filenames
$file_to_write = @ScriptDir & "\InquiryAnswers.txt"
$file_to_read = @ScriptDir & "\InquiryQuestions.txt"

; open file to read and store the handle
$handle_read = FileOpen($file_to_read, 0)
; open file to Write and store the handle
$handle_write = FileOpen($file_to_write, 2); erase mode
$x = 0
Global $aAnswers[1] = [0]
Do


; loop through each line of the file
While 1

    ; read each line from a file
    $line_read = FileReadLine($handle_read)
    ; exit the loop if end of file
    If @error = -1 Then ExitLoop

    ; get answer to question
    $answer = InputBox("blabla", $line_read, "", "", -1, -1, 0, 0)

    ; Increase count
    $aAnswers[0] += 1
    ; Increase array size
    ReDim $aAnswers[$aAnswers[0] + 1]
    ; Save answer
    $aAnswers[$aAnswers[0]] = $answer

WEnd

; Collect answers
$sAllAnswers = ""
For $i = 1 To $aAnswers[0] - 1
    $sAllAnswers &= $aAnswers[$i] & ","
Next
$sAllAnswers &= $aAnswers[$i]

; Write file
MsgBox(0,"","Thank you for participating!", 5)
FileWriteLine($handle_write, $sAllAnswers)

$handle_read = FileOpen($file_to_read, 0)
Global $aAnswers[1] = [0]
Until $x = 1
; close the file handle for read
FileClose($handle_read)
; close the file handle for write
FileClose($handle_write)

Func _Get_Answer()

    $hGUI = GUICreate("Vraag!", 2000, 2000, Default, Default, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)

    GUICtrlCreateLabel($line_read, 10, 10, 160, 200)

    $hInput = GUICtrlCreateInput("", 10, 40, 160, 20)

    $hOK_Button = GUICtrlCreateButton("OK", 10, 70, 75, 20)
    $hCan_Button = GUICtrlCreateButton("Cancel", 95, 70, 75, 20)

    GUISetState()

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hCan_Button
                Exit
            Case $hOK_Button
                $sAnswer = GUICtrlRead($hInput)
                GUIDelete($hGUI)
                Return $sAnswer
        EndSwitch

    WEnd

EndFunc

Share this post


Link to post
Share on other sites
Melba23

pbecks1963,

What i want is a big fat messagebox, big font

You change the font by using GUISetFont or GUICtrlSetFont - in particular the size parameter. But then you need to make sure the GUI and the input can take that size font. Up to you to experiment! :mellow: Once you have chosen a font and size, you need to resize the Input and Label controls so that they can match. Then you need to adjust the GUI to allow the size of control you need. I cannot help too much here as all depends on the font you choose - but here is an example:

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

$hGUI = GUICreate("Test BIG Font", 320, 180, Default, Default, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)

GUISetFont(24, Default, Default, "MS Comic Sans") ; Set the font for ALL controls in the GUI

GUICtrlCreateLabel("Question", 10, 10, 300, 40)
$hInput = GUICtrlCreateInput("", 10, 60, 300, 40)
$hOK_Button = GUICtrlCreateButton("OK", 10, 120, 120, 50)
$hCan_Button = GUICtrlCreateButton("Cancel", 190, 120, 120, 50)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hCan_Button
            Exit
        Case $hOK_Button
            $sAnswer = GUICtrlRead($hInput)
            GUIDelete($hGUI)
            Exit
    EndSwitch
WEnd

Your new code was a bit TOO big, in my opinion! :lol:

the problem of closing the script once the last Inquiry has been made

Just ask if you want to exit or carry on using a "Yes/No" MsgBox. Here is an example combining the BIG text questions and the "Do you want to Exit" MsgBox:

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

; Set filenames
$file_to_write = @ScriptDir & "\InquiryAnswers.txt"
$file_to_read = @ScriptDir & "\InquiryQuestions.txt"

; open file to read and store the handle
$handle_read = FileOpen($file_to_read, 0)
; open file to Write and store the handle
$handle_write = FileOpen($file_to_write, 1); append mode ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1

    ; Set or Reset array for this set of answers
    Local $aAnswers[1] = [0]

    ; Loop through each line of the file to get the questions
    While 1

        ; read each line from a file - starting at 1 for each pass
        If $aAnswers[0] = 0 Then
            $line_read = FileReadLine($handle_read, 1)
        Else
            $line_read = FileReadLine($handle_read)
        EndIf
        ; exit the loop if end of file
        If @error = -1 Then ExitLoop

        ; get answer to question
        $answer = _Get_Answer($line_read)

        ; Increase count
        $aAnswers[0] += 1
        ; Increase array size
        ReDim $aAnswers[$aAnswers[0] + 1]
        ; Save answer
        $aAnswers[$aAnswers[0]] = $answer

    WEnd

    ; Collect answers
    $sAllAnswers = ""
    For $i = 1 To $aAnswers[0] - 1
        $sAllAnswers &= $aAnswers[$i] & ","
    Next
    $sAllAnswers &= $aAnswers[$i]

    FileWriteLine($handle_write, $sAllAnswers)

    ; Write file
    $iResponse = MsgBox(4, "", "Thank you for participating!" & @CRLF & @CRLF & "Do you want to exit now?")

    If $iResponse = 6 Then ExitLoop

WEnd

; close the file handle for read
FileClose($handle_read)
; close the file handle for write
FileClose($handle_write)


Exit

Func _Get_Answer($sQuestion)

    $hGUI = GUICreate("Test BIG Font", 320, 180, Default, Default, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)
    GUISetFont(24, Default, Default, "MS Comic Sans")

    GUICtrlCreateLabel($sQuestion, 10, 10, 300, 40)

    $hInput = GUICtrlCreateInput("", 10, 60, 300, 40)

    $hOK_Button = GUICtrlCreateButton("OK", 10, 120, 120, 50)
    $hCan_Button = GUICtrlCreateButton("Cancel", 190, 120, 120, 50)

    GUISetState()

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hCan_Button
                Exit
            Case $hOK_Button
                $sAnswer = GUICtrlRead($hInput)
                GUIDelete($hGUI)
                Return $sAnswer
        EndSwitch

    WEnd

EndFunc   ;==>_Get_Answer

I hope that explains enough for you - if not ask again! :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×