 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
vlcek
Joined: 19 Feb 2007 Posts: 321 Location: Czech Republic
|
Posted: Thu Mar 01, 2007 10:33 am Post subject: example from documentation for autohotkey |
|
|
Please help.
Good Afternoon. In this code is any error, because I Want save file to c:\docs\helo.txt, but my program save file to c:\docs\helo.
| Code: | ; Create the sub-menus for the menu bar:
Menu, FileMenu, Add, nový, FileNew
Menu, FileMenu, Add, &otevřít, FileOpen
Menu, FileMenu, Add, &uložit, FileSave
Menu, FileMenu, Add, uložit &jako, FileSaveAs
Menu, FileMenu, Add
; Separator line.
Menu, FileMenu, Add, k&onec, FileExit
Menu, HelpMenu, Add, &o programu, HelpAbout
; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, &Soubor, :FileMenu
Menu, MyMenuBar, Add, &nápověda, :HelpMenu
; Attach the menu bar to the window:
Gui, Menu, MyMenuBar
; Create the main Edit control and display the window:
Gui, +Resize
; Make the window resizable.
Gui, Add, Edit, vMainEdit WantTab W600 R20
Gui, Show,, Untitled
CurrentFileName =
; Indicate that there is no current file.
return
FileNew:
GuiControl,, MainEdit
; Clear the Edit control.
return
FileOpen:
Gui +OwnDialogs
; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, Open File, Text Documents (*.txt)
if SelectedFileName =
; No file selected.
return
Gosub FileRead
return
FileRead:
; Caller has set the variable SelectedFileName for us.
FileRead, MainEdit, %SelectedFileName%
; Read the file's contents into the variable.
if ErrorLevel
{
MsgBox Could not open "%SelectedFileName%".
return
}
GuiControl,, MainEdit, %MainEdit%
; Put the text into the control.
CurrentFileName = %SelectedFileName%
Gui, Show,, %CurrentFileName%
; Show file name in title bar.
return
FileSave:
if CurrentFileName =
; No filename selected yet, so do Save-As instead.
Goto FileSaveAs
Gosub SaveCurrentFile
return
FileSaveAs:
FileSelectFile, SelectedFileName, S16,, Save File, Text Documents (*.txt)
if SelectedFileName =
; No file selected.
return
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return
SaveCurrentFile:
; Caller has ensured that CurrentFileName is not blank.
IfExist %CurrentFileName%
{
FileDelete %CurrentFileName%
if ErrorLevel
{
MsgBox The attempt to overwrite "%CurrentFileName%" failed.
return
}
}
GuiControlGet, MainEdit
; Retrieve the contents of the Edit control.
FileAppend, %MainEdit%, %CurrentFileName%
; Save the contents to the file.
; Upon success, Show file name in title bar (in case we were called by FileSaveAs):
Gui, Show,, %CurrentFileName%
return
HelpAbout:
MsgBox 8256, O programu., Textový editor verze 1.
return
return
GuiDropFiles:
; Support drag & drop.
Loop, parse, A_GuiEvent, `n
{
SelectedFileName = %A_LoopField%
; Get the first file only (in case there's more than one).
break
}
Gosub FileRead
return
GuiSize:
if ErrorLevel = 1
; The window has been minimized. No action needed.
return
; Otherwise, the window has been resized or maximized.
;Resize the Edit control to match.;
NewWidth := A_GuiWidth - 20
NewHeight := A_GuiHeight - 20
GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
return
FileExit:
; User chose "Exit" from the File menu.
GuiClose:
; User closed the window.
ExitApp |
Please write good code.
Thank you.
soubor=file
nový=new
otevřít=open
uložit=save
uložit jako=save as
konec=exit
nápověda=help
O programu=About. |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Thu Mar 01, 2007 5:48 pm Post subject: |
|
|
when you open the dialogue box you need to type in "helo.txt" as the file name.
or you could simply use stringright to see if ".txt" is there already, and if it isn't, append it.
| Code: | ; NOT TESTED
FileSaveAs:
FileSelectFile, SelectedFileName, S16,, Save File, Text Documents (*.txt)
if SelectedFileName = ; No file selected.
return
StringRight,ext,4
if (ext <> ".txt")
CurrentFileName = %SelectedFileName%.txt
else
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return |
_________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 321 Location: Czech Republic
|
Posted: Fri Mar 02, 2007 7:09 am Post subject: |
|
|
| Veovis wrote: | when you open the dialogue box you need to type in "helo.txt" as the file name.
or you could simply use stringright to see if ".txt" is there already, and if it isn't, append it.
| Code: | ; NOT TESTED
FileSaveAs:
FileSelectFile, SelectedFileName, S16,, Save File, Text Documents (*.txt)
if SelectedFileName = ; No file selected.
return
StringRight,ext,4
if (ext <> ".txt")
CurrentFileName = %SelectedFileName%.txt
else
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return |
|
Helo. I write your code, but.
---------------------------
miniword.ahk
---------------------------
Error at line 99.
Line Text: StringRight,ext
Error: "StringRight" requires at least 3 parameters.
The program will exit.
---------------------------
OK
--------------------------- |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 358
|
Posted: Fri Mar 02, 2007 8:50 am Post subject: |
|
|
| StringRight, OutputVar, InputVar, Count |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Fri Mar 02, 2007 5:07 pm Post subject: |
|
|
heh, oops
| Veovis wrote: | | ; NOT TESTED |
i wrote that off the top of my head, and didn't realize i did that wrong _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|