Sign in to follow this  
Followers 0
Romm

Func and FileWrite

5 posts in this topic




Func OKButton()
$file = FileOpen("ID.txt", 1) 
FileWrite($file, "eewre") 
FileWrite($file, @CRLF) 
EndFunc

And nothing...

Without Func all works fine.

WTF?

I have no doubt you have a problem but without more explanation than you have given I have no idea what it is, apart from the fact that you have no error checking in the code you've shown.

A sample script which we can run which shows the problem is worth doing for 2 reasons; you will get more help and by making the sample you might well see your own solution.

Have you even tried adding a consolewrite line at the start of the function to check that the function is actually getting called?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I edited script.

#include <GUIConstantsEx.au3>  
#include <WindowsConstants.au3>  
#include <IE.au3>  
#Include <string.au3>  
#include <array.au3>          

$mainwindow = GUICreate("Test", 850, 580, 1, 1, _       
$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)      
GUICtrlSetImage(-1, "shell32.dll", 38)  GUISetState()  Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode     
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")  
$okbutton = GUICtrlCreateButton("Push to write into file", 130, 450, 180)  GUICtrlSetOnEvent($okbutton, "OKButton")      
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")      

GUISwitch($mainwindow)  
GUISetState(@SW_SHOW)    

While 1    
Sleep(1000)  ; Idle around  WEnd    

Func OKButton()     
MsgBox(1, "", "Trying to write into file")  
$file = FileOpen("ID.txt", 1)   
FileWrite($file, "Test")   
EndFunc    

Func CLOSEClicked()    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,    
;@GUI_WINHANDLE will be either $mainwindow or $dummywindow    
If @GUI_WINHANDLE = $mainwindow Then       
MsgBox(0, "GUI Event", "You clicked CLOSE in the main window! Exiting...")      
Exit    
EndIf   
EndFunc

Share this post


Link to post
Share on other sites

While 1

Sleep(1000) ; Idle around WEnd

First of all, that Wend is in the wrong place :D

Share this post


Link to post
Share on other sites

I edited script.

#include <GUIConstantsEx.au3>  
#include <WindowsConstants.au3>  
#include <IE.au3>  
#Include <string.au3>  
#include <array.au3>          

$mainwindow = GUICreate("Test", 850, 580, 1, 1, _       
$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)      
GUICtrlSetImage(-1, "shell32.dll", 38)  GUISetState()  Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode     
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")  
$okbutton = GUICtrlCreateButton("Push to write into file", 130, 450, 180)  GUICtrlSetOnEvent($okbutton, "OKButton")      
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")      

GUISwitch($mainwindow)  
GUISetState(@SW_SHOW)    

While 1    
Sleep(1000)  ; Idle around  WEnd    

Func OKButton()     
MsgBox(1, "", "Trying to write into file")  
$file = FileOpen("ID.txt", 1)   
FileWrite($file, "Test")   
EndFunc    

Func CLOSEClicked()    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,    
;@GUI_WINHANDLE will be either $mainwindow or $dummywindow    
If @GUI_WINHANDLE = $mainwindow Then       
MsgBox(0, "GUI Event", "You clicked CLOSE in the main window! Exiting...")      
Exit    
EndIf   
EndFunc

GUICtrlSetImage(-1, "shell32.dll", 38)  GUISetState()  Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

Im getting confused the way you 'edit' the script, multiple stuff on the same line doesnt work well for me when i try your code.

$mainwindow = GUICreate("Test", 850, 580, 1, 1, _       
$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)

This needs some work i belive.

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")  
$okbutton = GUICtrlCreateButton("Push to write into file", 130, 450, 180)  GUICtrlSetOnEvent($okbutton, "OKButton")      
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

Im no expert, but is GUISetOnEvent() needed on 2 places ?

and theres the multiline-thingy again.

While 1    
Sleep(1000)  ; Idle around  WEnd

Do we need to explain this ?

What are you trying to accomplish with the script ?

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