Jump to content
Sign in to follow this  
Ferman

Func not working and I can't figure out why.

Recommended Posts

Ferman

Alright,

So I am trying to make an autoit script to create a file and I just looked at the example on the function page for FileWriteLine everything seemed to make since so I added a GUISetOnEvent so that when the "done" button is pressed it will create a file with text in it and it will continue to write the text in it over and over again... I am just trying to get this to work before I do any other stuff.

So I used Koda to make the gui real fast (that was the easy part) and I exported it etc and I added the GUISetOnEvent and the function from the FileWriteLine example and it doesn't work.

I did get it to work once though but I had to generate the code from Koda with events on everybutton which then left minimize and close useless, so creating a file with text in it worked but closing the application itself didn't which was pretty useless.

My question is "How do I make the FileWriteLine actually work?". With this code right now it will not create test.txt with "Line1 Line2 Line3" written in it.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:UsersjustinDesktopcreat-vhostvhost-gui.kxf
$Form1 = GUICreate("Create a new vHost for localdev", 401, 201, 325, 193)
GUISetBkColor(0xFFFFFF)
$website = GUICtrlCreateInput("", 16, 40, 361, 21)
GUICtrlSetCursor (-1, 2)
$website_label = GUICtrlCreateLabel("Website Name ( Do not provide the extension ex. graphtek.com = graphtek )", 16, 16, 364, 17)
$done = GUICtrlCreateButton("Done", 304, 160, 73, 33)
GUICtrlSetOnEvent($done, "doneClick")
$coldfusion = GUICtrlCreateCheckbox("Is this a coldfusion site?", 16, 72, 281, 20)
$directory_edit = GUICtrlCreateButton("Edit Directories", 16, 160, 105, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

Func doneClick()
Local $file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

FileWriteLine($file, "Line1")
FileWriteLine($file, "Line2" & @CRLF)
FileWriteLine($file, "Line3")

FileClose($file)
EndFunc
Edited by Ferman

Share this post


Link to post
Share on other sites
water

And the question is?

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ferman

And the question is?

My question is "How do I make the FileWriteLine actually work?". With this code right now it will not create test.txt with "Line1 Line2 Line3" written in it......

Sorry I was a little flustered when I was writing this post which means I am not very coherent in my typing haha.. Its making me mad. I haven't used autoit in like 2-3 years which means I forgot a lot and I mean I didn't really know much when I used it last.

Share this post


Link to post
Share on other sites
Danyfirex

Use case $done

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>#Region ### START Koda GUI section ### Form=C:UsersjustinDesktopcreat-vhostvhost-gui.kxf
$Form1 = GUICreate("Create a new vHost for localdev", 401, 201, 325, 193)
GUISetBkColor(0xFFFFFF)
$website = GUICtrlCreateInput("", 16, 40, 361, 21)
GUICtrlSetCursor (-1, 2)
$website_label = GUICtrlCreateLabel("Website Name ( Do not provide the extension ex. graphtek.com = graphtek )", 16, 16, 364, 17)
$done = GUICtrlCreateButton("Done", 304, 160, 73, 33)
GUICtrlSetOnEvent($done, "doneClick")
$coldfusion = GUICtrlCreateCheckbox("Is this a coldfusion site?", 16, 72, 281, 20)
$directory_edit = GUICtrlCreateButton("Edit Directories", 16, 160, 105, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $done ;the case when you click on botton
doneClick()
EndSwitch
WEnd

Func doneClick()
Local $file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

FileWriteLine($file, "Line1")
FileWriteLine($file, "Line2" & @CRLF)
FileWriteLine($file, "Line3")

FileClose($file)
EndFunc

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites
Ferman

Use case $done

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>#Region ### START Koda GUI section ### Form=C:UsersjustinDesktopcreat-vhostvhost-gui.kxf
$Form1 = GUICreate("Create a new vHost for localdev", 401, 201, 325, 193)
GUISetBkColor(0xFFFFFF)
$website = GUICtrlCreateInput("", 16, 40, 361, 21)
GUICtrlSetCursor (-1, 2)
$website_label = GUICtrlCreateLabel("Website Name ( Do not provide the extension ex. graphtek.com = graphtek )", 16, 16, 364, 17)
$done = GUICtrlCreateButton("Done", 304, 160, 73, 33)
GUICtrlSetOnEvent($done, "doneClick")
$coldfusion = GUICtrlCreateCheckbox("Is this a coldfusion site?", 16, 72, 281, 20)
$directory_edit = GUICtrlCreateButton("Edit Directories", 16, 160, 105, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $done ;the case when you click on botton
doneClick()
EndSwitch
WEnd

Func doneClick()
Local $file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

FileWriteLine($file, "Line1")
FileWriteLine($file, "Line2" & @CRLF)
FileWriteLine($file, "Line3")

FileClose($file)
EndFunc

Saludos

IT WORKS!!! Thank you very much!

I guess I have some more reading to do. Apparently I didn't think of making a case for $done.

Share this post


Link to post
Share on other sites
FireFox

@Ferman

Then remove this :

GUICtrlSetOnEvent($done, "doneClick")

Or add this after includes :

Opt("GUIOnEventMode", 1)

Br, Firefox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

  • Similar Content

    • nooneclose
      By nooneclose
      Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.
      HTML Code: 
      <img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false"> Here is the code that I have so far:
      ;******************************************************************************* ; Opens IE and fill out a New Workorder ;******************************************************************************* ; Start IE at the ** Tracking Application in ****** $oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage") ; Wait for a browser page load to complete _IELoadWait($oIE) Sleep(6000) ; Store the field names where the important data will be sent Local $nWorkOrderB = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image") _IEAction($nWorkOrderB, "click")  I want my program to click on the button that looks like a piece of paper with a blue # 
      (For those wondering, I am allowed to send images just not the URL.) 
      As always any help would be appreciated. 

    • Pike
      By Pike
      Hello Everyone,
      New Guy here. This is a two-part question, hopefully easy enough though. I know it's ugly coding, this is because I have only a couple hours worth of coding experience and could really use some help.
      1) When I single click the button I want one action (like playing a sound clip) and when I double click the button I want a different action (such as opening dialogue box to ask for soundclip directory address). At the bottom of the script I made a comment which one I would like single click versus double click.
      2) I can not get the FileOpenDialogue to save the file address to the config.ini file at the 'One' position on the .ini.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Sound.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $OneID _Main() Func _Main() GUICreate("Form1", 156, 86, 281, 276) $OneID = GUICtrlCreateButton("Button", 15, 17, 122, 37) GUICtrlSetOnEvent($OneID, "OnOne") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 While 1 Sleep(1000) WEnd WEnd EndFunc ;---------------Functions------------- While 1 Sleep(100) WEnd Func OnOne() ; ******************Single Click for this action**************** $OneID = IniRead("config.ini", "Config", "One", $OneID) If $OneID = True Then SoundPlay($OneID, @HotKeyPressed) Else ; *******Double Click for this action*****And Help Saving File Address to config.ini 'One'*********** $OneID = FileOpenDialog("Select file", @WorkingDir, "All (*.*)") IniWrite("config.ini", "Config", "One", $OneID) $OneID = InputBox("Enter Information", "Short Name for File?", "") IniWrite("config.ini", "Config", "NameOne", $OneID) EndIf EndFunc Any help would be greatly appreciated, and if you need anymore clarity as to what exactly I'm trying to do, please do not hesitate to ask. Thanks so much!
      Pike
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have a query please
      It is about windows file explorer
      If i design a tool in autoit language to delete files for example
      and i  added it in the context menu in File Explorer
      If i right-click on any file And you choose the tool, it will be get the path of the selected file or folder
      The problem here is
      If i select a set of files or folders
      it only detect the first one
      The code that i  used is
      if $CMDLine[0] = 0 then
      msgBox(16, "error", "you don't selecte any files")
      exit
      else
      for $i = 1 to $CMDLine[0]
      msgBox(0, "files", $CMDLine[$i]
      next
      endIf
      exit
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • TheSaint
      By TheSaint
      Files Checklist
      Just a simple little (complex enough) program I whipped up, for a purpose ... but only too happy to share.
      It can of course be modified to do more, but at the moment just compares file names with or without path ... Location versus Checklist.
      There are of course other compare programs out there, most doing a lot more than mine (i.e. WinMerge or FileComparer). But I wanted something quick and simple with drag & drop, that uses up a smallish amount of screen real estate.
      NOTE - The SAVE button is also a LOAD one, and displays 'Load' when the list is empty. So you can save and load specific lists. While in SAVE mode, the button can also be used with CTRL held down, to ADD another list to existing (displayed one) ... combining as they say ... though not saved until you SAVE. CLEAR button removes a selected entry, or if used with CTRL held down, queries about removing all listed entries.
              
      Files Checklist v1.2.zip
      Files Checklist v1.3.zip
      Files Checklist v1.4.zip  (Includes a BUGFIX.)
        (source included)
      WARNING - While this program does not act on files or folders ADDED or CHECKED, you might act on the results, so I advise caution, and I also recommend using the new 'Relative' option in v1.3 or newer ... but you still need to understand what you are doing and what the results actually mean. Some basic examples in the next post.
      Enjoy!
      RELATED
      Users might also be interested in another somewhat related program of mine.
      DeleteIf Same
      Cheers!
×