Mat Posted March 5, 2009 Posted March 5, 2009 (edited) i've added an exe with this script to the context menu of all files through the registry. (see here) expandcollapse popup#include <GUIConstantsEx.au3> #Include <Clipboard.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Opt("TrayIconHide", 1) Opt("GUICloseOnESC", 0) _main () Restart () func _Main () local $msg, $long, $short, $copy, $close, $retry, $GUI, $error, $CmdLine If $CmdLine[0] = 0 Then Exit Endif $long = Inputbox ("long File name", "Please give the long file name to convert.", "" & $CmdLine[1] & "") if @error = 1 then exit endif $short = FileGetShortName ($long) $GUI = GuiCreate("M@'s Short File Name Generator", 392, 168, -1, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX) GuiCtrlCreateLabel("The short file name is: " & @CRLF & "" & $short & ".", 10, 10, 370, 100) $Copy = GuiCtrlCreateButton("Copy", 10, 120, 110, 30) $Retry = GuiCtrlCreateButton("Try again", 130, 120, 110, 30) $close = GuiCtrlCreateButton("Close", 250, 120, 110, 30) GUISetState () do $msg = GUIGetmsg() select case $msg = $retry Restart () case $msg = $copy ClipPut ($short) case $msg = $close or $msg = $GUI_Event_Close or $msg = $retry Exit Endselect until $msg = $GUI_Event_Close endfunc ;------------------------------------------------------------------------------------------------------------------------------------------------------ Func Restart() If Not @Compiled Then Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath)) ElseIf @Compiled Then Run(@ScriptFullPath) EndIf Exit EndFunc i get an error when running the script though error: Subscript used with non-Array variable it doesn't seem to like my $cmdline[] any ideas?? the script worked fine until i added the cmdline parts Mdiesel Edited March 5, 2009 by mdiesel AutoIt Project Listing
water Posted March 5, 2009 Posted March 5, 2009 You defined $cmdline as a local variable. I think you don' t have to define it. Just drop the $cmdline definition and see if it works. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Mat Posted March 5, 2009 Author Posted March 5, 2009 done...and it works BUT part 2 error: array variable has incorrect number of subscripts or subscript dimension range exceeded. ?????? AutoIt Project Listing
James Posted March 5, 2009 Posted March 5, 2009 Works for me. Are you trying to do more than one file at a time? Also, why the hell do you have a "Try Again" button? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Varian Posted March 5, 2009 Posted March 5, 2009 (edited) Why not make the following changes to so your Try Again button functions as you want it and you can run it without compiling it If $CmdLine[0] = 0 Then Local $File = FileOpenDialog("Please select the file to convert", "", "All Files (*.*)", 1 + 2) If @error Then Exit Else Local $File = $CmdLine[1] EndIf $Long = InputBox("long File name", "Please give the long file name to convert.", "" & $File & "") Edited March 5, 2009 by Varian
Mat Posted March 5, 2009 Author Posted March 5, 2009 (edited) thanks for all the replies - that is now up and running under this code: expandcollapse popup#include <GUIConstantsEx.au3> #Include <Clipboard.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Opt("TrayIconHide", 1) Opt("GUICloseOnESC", 0) _main () Restart () func _Main () local $msg, $long, $short, $copy, $close, $retry, $GUI, $error, $file If $CmdLine[0] = 0 Then Local $File = FileOpenDialog("Please select the file to convert", "", "All Files (*.*)", 1 + 2) If @error Then Exit Else Local $File = $CmdLine[1] EndIf $long = Inputbox ("long File name", "Please give the long file name to convert.", "" & $file & "") if @error = 1 then exit endif $short = FileGetShortName ($long) $GUI = GuiCreate("M@'s Short File Name Generator", 392, 168, -1, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX) GuiCtrlCreateLabel("The short file name is: " & @CRLF & "" & $short & ".", 10, 10, 370, 100) $Copy = GuiCtrlCreateButton("Copy", 10, 120, 110, 30) $Retry = GuiCtrlCreateButton("Try again", 130, 120, 110, 30) $close = GuiCtrlCreateButton("Close", 250, 120, 110, 30) GUISetState () do $msg = GUIGetmsg() select case $msg = $retry Restart () case $msg = $copy ClipPut ($short) case $msg = $close or $msg = $GUI_Event_Close or $msg = $retry Exit Endselect until $msg = $GUI_Event_Close endfunc ;------------------------------------------------------------------------------------------------------------------------------------------------------ Func Restart() If Not @Compiled Then Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath)) ElseIf @Compiled Then Run(@ScriptFullPath) EndIf Exit EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------------------ try again - restart same thing... anyway thanks Mdiesel Edited June 21, 2010 by Mat AutoIt Project Listing
Varian Posted March 5, 2009 Posted March 5, 2009 I suggested the changes because with your original script, if you pressed Try Again the Restart() function ran the script with no parameters and would close because $Cmdline[0] = 0..there was no point to restarting it before
Mat Posted March 5, 2009 Author Posted March 5, 2009 Yer, i notice that now, thanks for all the help - final script (hopefully) expandcollapse popup#include <GUIConstantsEx.au3> #Include <Clipboard.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Opt("TrayIconHide", 1) Opt("GUICloseOnESC", 0) _main () Restart () func _Main () local $msg, $long, $short, $copy, $close, $retry, $GUI, $error, $file If $CmdLine[0] = 0 Then $msgbox1 = msgbox (1, "No file or folder selected", "This program was not accessed throught the system context menu" & @CRLF & "Do you wish to select a file?") select case $msgbox1 = 1 $File = FileOpenDialog("Please select the file to convert", "", "All Files (*.*)", 1 + 2) If @error Then Exit case $msgbox1 = 2 exit endselect Else Local $File = $CmdLine[1] EndIf $long = Inputbox ("long File name", "Please give the long file name to convert.", "" & $file & "") if @error = 1 then exit endif $short = FileGetShortName ($long) $GUI = GuiCreate("M@'s Short File Name Generator", 392, 168, -1, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX) GuiCtrlCreateLabel("The short file name is: " & @CRLF & "" & $short & ".", 10, 10, 370, 100) $Copy = GuiCtrlCreateButton("Copy", 10, 120, 110, 30) $Retry = GuiCtrlCreateButton("Try again", 130, 120, 110, 30) $close = GuiCtrlCreateButton("Close", 250, 120, 110, 30) GUISetState () do $msg = GUIGetmsg() select case $msg = $retry Restart () case $msg = $copy ClipPut ($short) case $msg = $close or $msg = $GUI_Event_Close or $msg = $retry Exit Endselect until $msg = $GUI_Event_Close endfunc ;------------------------------------------------------------------------------------------------------------------------------------------------------ Func Restart() If Not @Compiled Then Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath)) ElseIf @Compiled Then Run(@ScriptFullPath) EndIf Exit EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------------------ AutoIt Project Listing
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