Jump to content

$cmdline[0] - error (Working again :-) )


 Share

Recommended Posts

i've added an exe with this script to the context menu of all files through the registry. (see here)

#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 by mdiesel
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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 by Varian
Link to comment
Share on other sites

thanks for all the replies - that is now up and running under this code:

#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 by Mat
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Yer, i notice that now, thanks for all the help -

final script (hopefully)

#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

;------------------------------------------------------------------------------------------------------------------------------------------------------
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...