Sign in to follow this  
Followers 0
Mat

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

9 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



remove declaration of $CmdLine


♡♡♡

.

eMyvnE

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

done...and it works BUT

part 2

error: array variable has incorrect number of subscripts or subscript dimension range exceeded.

??????

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Varian

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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

;------------------------------------------------------------------------------------------------------------------------------------------------------

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