greenmachine Posted December 4, 2005 Share Posted December 4, 2005 I'm making a script that does about a million things, and a few of them deal with loading files. For some reason, calling the load function doesn't work right. Here's a super shortened script that shows what I mean. Global $fileloaded HotKeySet ("1", "LoadAFile") HotKeySet ("2", "ReloadTheFile") HotKeySet ("3", "UseBlankFile") HotKeySet ("9", "GODIE") Func UseBlankFile() LoadAFile("BlankFile.txt") EndFunc Func ReloadTheFile() If $fileloaded <> "" Then LoadAFile($fileloaded) EndIf EndFunc Func LoadAFile($load = "") If $load = "" Then MsgBox (0, "load", "load is empty string") $load = InputBox ("loadfile", "type in a file name") EndIf If $load = "BlankFile.txt" Then MsgBox (0, "loadedblank", "blankfile.txt was loaded") EndIf $fileloaded = $load EndFunc Func GODIE() Exit EndFunc While 1 Sleep (100) WEnd When I run this script, pressing 1 should let you input a file through the input box (because the $load is optional in the function and set to "" if nothing is called, right?). But... it doesn't. It gives me an error saying $load isn't declared. It might be that I don't understand these optional parameters, but I thought I was doing it right. Any help would be appreciated. Yes, my exit function is called GODIE - I'm a little frustrated by my script not working.... Link to comment Share on other sites More sharing options...
gamerman2360 Posted December 4, 2005 Share Posted December 4, 2005 Mabey:Global $fileloaded HotKeySet ("1", "LoadAFile") HotKeySet ("2", "ReloadTheFile") HotKeySet ("3", "UseBlankFile") HotKeySet ("9", "GODIE") Func UseBlankFile() LoadAFile("BlankFile.txt") EndFunc Func ReloadTheFile() If $fileloaded <> "" Then LoadAFile($fileloaded) EndIf EndFunc Func LoadAFile($load = "") If Not IsDeclared("load") Then MsgBox (0, "load", "load is empty string") $load = InputBox ("loadfile", "type in a file name") ElseIf $load = "BlankFile.txt" Then MsgBox (0, "loadedblank", "blankfile.txt was loaded") EndIf $fileloaded = $load EndFunc Func GODIE() Exit EndFunc While 1 Sleep (100) WEndI would recommend using FileOpenDialog(). Link to comment Share on other sites More sharing options...
greenmachine Posted December 4, 2005 Author Share Posted December 4, 2005 (edited) I see that you used: If Not IsDeclared("load"). While that should work, why does it have to be that way? In all sorts of other functions, there are optional strings that don't have to use that statement. It seems like my way should work... And I am using FileOpenDialog. This was just an example to show my problem. It's not supposed to do anything. The real script does all the real stuff. Example.. _TempFile does not need any parameters to work, and the first thing it does is use one of the optional parameters. I thought mine would do that too. Func _TempFile($s_DirectoryName = @TempDir, $s_FilePrefix = "~", $s_FileExtension = ".tmp", $i_RandomLength = 7) Local $s_TempName ; Check parameters If Not FileExists($s_DirectoryName) Then $s_DirectoryName = @TempDir ; First reset to default temp dir If Not FileExists($s_DirectoryName) Then $s_DirectoryName = @ScriptDir; Still wrong then set to Scriptdir ; add trailing \ for directory name If StringRight($s_DirectoryName, 1) <> "\" Then $s_DirectoryName = $s_DirectoryName & "\" ; Do $s_TempName = "" While StringLen($s_TempName) < $i_RandomLength $s_TempName = $s_TempName & Chr(Random(97, 122, 1)) WEnd $s_TempName = $s_DirectoryName & $s_FilePrefix & $s_TempName & $s_FileExtension Until Not FileExists($s_TempName) Return ($s_TempName) EndFunc ;==>_TempFile Edited December 4, 2005 by greenmachine Link to comment Share on other sites More sharing options...
w0uter Posted December 4, 2005 Share Posted December 4, 2005 use like HotKeySet ("1", "LoadAFileDummy") Func LoadAFileDummy() LoadAFile() EndFunc My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
gamerman2360 Posted December 4, 2005 Share Posted December 4, 2005 (edited) I guess hotkeys don't use any prams whatsoever... [edit] If 'If Not IsDeclared("load")' is bad you could check if it was started by a hotkey by using something like "@HotKeyPressed". Edited December 4, 2005 by gamerman2360 Link to comment Share on other sites More sharing options...
greenmachine Posted December 4, 2005 Author Share Posted December 4, 2005 Update: w0uter, your idea worked. Thanks. gamerman2360: the thing is, I was only using hotkeys for the example. In my regular script, I'm using GUI Onevent functions to call... and I guess they do the same thing as hotkeys. OK I figured it out. Watch this: Add HotKeySet ("4", "Calltest") to the top, and add this function anywhere... Func Calltest() Call ("LoadAFile") EndFunc That gives the same error, which means I know what's going on. Hotkeys and GUIOnEvent functions use Call( "function" ) instead of just Function(). That makes a big difference. Link to comment Share on other sites More sharing options...
gamerman2360 Posted December 4, 2005 Share Posted December 4, 2005 :\, why doesn't Call() use any of the variables? Not even the default ones? Link to comment Share on other sites More sharing options...
Bert Posted December 4, 2005 Share Posted December 4, 2005 Are you planning to have the hotkeysets to be on all the time? If so, you may run into problems with other applications that use the same keys. You may wish to do a winactive to have the hotkeyset work only while the window you wish to use is active. (Hope I'm explaining that right) The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
greenmachine Posted December 4, 2005 Author Share Posted December 4, 2005 Are you planning to have the hotkeysets to be on all the time? If so, you may run into problems with other applications that use the same keys. You may wish to do a winactive to have the hotkeyset work only while the window you wish to use is active.(Hope I'm explaining that right)You are definitely explaining it correctly, but like I said above, I'm not actually using HotKeys in my real script. That was just examples. In my real script, I use buttons and menuitems. But hotkeys were just simplifying things for the example. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now