Jump to content

Need Help On Script


Recommended Posts

Myself and a ex employee wrote this script about 2 years ago as an easy photo import program for our shop employee's. We made a system wide change yesterday concerning our folder structure and I needed to update it in the script. It has been two years since I worked with AutoIt and now I can't compile the script. I keep getting a unknown function error. Can someone please help me because I really need to get this back into the shop working. I will be in someone's debt if they can help.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>


#region "Variable Declaration"
$name = @UserName
$file2 = "Photos"
$file = " "
$pic = " "
$fold = " "
$choose_pic_name = " "
$search = " "
$progress_bar = " "
$percentage_completed = " "
$btn_format_card = " "

$lbl_percentage = ""
Global $btn_yes = 3, $btn_no = 3,  $btn_yes_to_all = 3
$importer_name = ""
$importer_name_label = ""
$importer_date_label = ""
$importer_date = ""
$importer_time_label = ""
$importer_time = ""
$importer_comp_label = ""
$importer_comp = ""
$pic = ""
$picture = ""
$choose_loc_label = ""
$choose_loc = "photos"
$choose_pic_name_label = ""
$choose_pic_name = "test"
$choose_pic_import_label = ""

$val = ""                                               ; Variable passed to IfExist Function
$txt_folder_to_import = " "                     ;Folder To Import
$txt_job_number = " "                           ;Job Number
$lbl_folder = ""
$lbl_job = ""
$btn_folder_browse = " "
$btn_job_browse = " "
$btn_import = " "
$btn_cancel = " "
$mnu_import = " "
$mnu_import_new = " "
$mnu_import_view_imported = " "
$mnu_import_exit = " "
$mnu_administration = " "
$mnu_administration_format_card = " "
$mnu_administration_import_log = " "
$mnu_administration_preferences  = " "
$mnu_administration_change_runas = " "
$mnu_about = " "
$mnu_about_about_photo_import = " "
$folder_name = "Click Browse and select folder to import"   ; Variable for Initial folder location
                #comments-start
                    code inserted by Abhay
                #comments-end
                    $var = DriveGetDrive("all")

                    $myflag = False
                    If Not @error Then
                        For $i=1 To $var[0]
                            If FileExists($var[$i] & "\DCIM\100OLYMP\") Then
                                ;MsgBox(4096,"Folder Found",$var[$i] & "\DCIM\100OLYMP\")
                                $folder_name = $var[$i] & "\DCIM\100OLYMP\"
                                $myflag = True
                            EndIf
                        Next
                        If $myflag=False Then
                            MsgBox(4096,"Error", "Pleast check the Card!")
                        EndIf
                    EndIf

                #cs
                    code inserted by Abhay End
                #ce
$job_name = "Click Browse and select job"                           ;Job Number
$photo = " "                                ;Full path of the photo which is to be uploaded
$i = 0                                      ;Variable for loops
$j = 0                                      ;Variable for loops
$flg = False                                ;Variable for flag
$si_logo = ""                               ;Shermco logo picture
$si_label = ""                              ;Shermco label text
#endregion

#region "OnAutoItStart Function"
Func OnAutoItStart()
    ; Add User name
    $user = "ASDcamera"
    ; Add Domain name
    $domain = "shermco.ind"
    ; Add Password
    $password = "@SDcam3ra$"
    ;
    ; Check incomong parameters
    If Not $CMDLINE[0] Then
        ; No parameters then restart as admin
        RunAsSet($user, $domain, $password)
        Run('"' & @ScriptFullPath & '" /admin')
        RunAsSet()
        Exit
    ElseIf $CMDLINE[1] <> '/admin' Then
        ; Exit script with error code 1
        Exit 1
    EndIf
EndFunc

#endregion

#region "GUI Func"


Func CreateGUI()
    GUICreate("Photo Import - Shermco Ind",800,600,115,50)
    GUISetBkColor(0xFFFFFF)
    CreateMenu()
    $si_logo = GUICtrlCreatePic("\\shermco\dfs\public\Graphics\SiLogo-blue.gif",10,10,150,100,BitOR($SS_NOTIFY,$WS_GROUP))
    $folder_label = GUICtrlCreateLabel("Select folder to import : ",200,27,150,18)
    $folder_name = StringUpper($folder_name)
    $txt_folder_to_import = GUICtrlCreateInput( $folder_name ,320,25,275,18,$ES_READONLY)
    $btn_folder_browse = GUICtrlCreateButton("Browse",600,23,60,22)
    $lbl_job = GUICtrlCreateLabel("Job Number : ",245,60,150,18)
    $txt_job_number = GUICtrlCreateInput( $job_name ,320,60,275,18,$ES_READONLY)
    $btn_job_browse = GUICtrlCreateButton("Browse",600,58,60,22)
    $btn_import = GUICtrlCreateButton("Import",320,95,60,22)
    $btn_cancel = GUICtrlCreateButton("Cancel",390,95,60,22)
    $btn_format_card = GUICtrlCreateButton("Format Card",520,95,75,22)
EndFunc

Func CreateMenu()
    $mnu_import = GUICtrlCreateMenu("Import")
    $mnu_import_new = GUICtrlCreateMenuitem("New",$mnu_import)
    $mnu_import__view_imported = GUICtrlCreateMenuitem("View Imported",$mnu_import)
    $mnu_import_exit = GUICtrlCreateMenuitem("Exit",$mnu_import)
    $mnu_administration = GUICtrlCreateMenu("Administration")
    $mnu_administration_format_card = GUICtrlCreateMenuitem("Format Card",$mnu_administration )
    $mnu_administration_import_log = GUICtrlCreateMenuitem("Import Log",$mnu_administration )
    $mnu_administration_preferences = GUICtrlCreateMenuitem("Preferences",$mnu_administration )
    $mnu_administration_change_runas = GUICtrlCreateMenuitem("Change RunAs",$mnu_administration )
    $mnu_about = GUICtrlCreateMenu("About")
    $mnu_about_about_photo_import = GUICtrlCreateMenuitem("About Photo Import", $mnu_about )
EndFunc

Func OnMnuAbout_Photo_Import_Clicked()
    #include <GUIConstants.au3>
    #Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Forms\Importer UI about.kxf
    $Form1 = GUICreate("About Photo Import - Shermco Ind", 324, 237, 303, 219)
    GUISetIcon("D:\006.ico")
    GUISetBkColor(0xFFFFFF)
    $GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 185)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Image1 = GUICtrlCreatePic("\\shermco\dfs\public\Graphics\SiLogo-blue.gif", 16, 24, 105, 97, BitOR($SS_NOTIFY,$WS_GROUP))
    $Label1 = GUICtrlCreateLabel("Photo Importer", 152, 24, 78, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Label2 = GUICtrlCreateLabel("V 1.1.0 Beta", 152, 48, 63, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Label4 = GUICtrlCreateLabel("Created For ASD by Brian Harris", 16, 160, 155, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Label3 = GUICtrlCreateLabel("Copyright: Shermco Industries 2006", 16, 136, 171, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("&OK", 112, 208, 75, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                ExitLoop
            Case $Button1
                GUIDelete()
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Func OnBtnFolderBrowse_Clicked()
            $var123 = DriveGetDrive("all")
            $myflag = False
                If Not @error Then
                    For $i123=1 To $var123[0]
                        If FileExists($var123[$i123] & "\DCIM\100OLYMP\") Then
                            MsgBox(4096,"Folder Found",$var123[$i123] & "\DCIM\100OLYMP\")
                            $folder_name = FileSelectFolder("Choose a folder to import", "C;\", 6, $var123[$i123] & "\DCIM\100OLYMP")
                            $myflag = True
                        EndIf
                    Next
                    If $myflag = False Then
                        MsgBox(4096,"Error", "Please check the Card!")
                    EndIf
                EndIf
            StringUpper($folder_name)
            GuiCtrlSetData($txt_folder_to_import, $folder_name)
EndFunc

Func OnBtnJobBrowse_Clicked()
    $job_name = FileSelectFolder("Choose a job to save to", "\\shermco\dfs\reports\MSDReports_Data", 6, "\\shermco\dfs\reports\MSDReports_Data")
    ;MsgBox(4096,"Job Number",$job_name)
    GuiCtrlSetData($txt_job_number, $job_name)
EndFunc

Func OnBtnImport_Clicked()
    ;If $btn_import = 1 Then
    FileChangeDir($folder_name)
    ;FileChangeDir(GUICtrlRead($txt_folder_to_import))
    $search = FileFindFirstFile("*.jpg")
    $file = FileFindNextFile($search)
    If $search = -1 Then
        MsgBox(0, "Error", "No pictures to copy. Plese select a different directory.")
        ;$result = "unsuccessfully."
        ;Delete_Group($all)
        ;Import_New()
    EndIf
    FolName()
    PhotoChoose()
    ImporterStuff()
    ;EndIf
EndFunc

Func FolName()
    $fold = InputBox("Name oF Folder", "Name the folder to import the pictures into", $file2)
EndFunc

Func PhotoChoose()
    ;MsgBox(4096,"Function", "Photo Choose")
    ;MsgBox(4096,"$file",$file)
    $choose_pic_name = $file
    $pic = $folder_name & $file
    ;MsgBox(4096, "Photo Choose",$pic)
EndFunc
Func ImporterStuff()

    ;MsgBox(4096, "Importer Stuff", "Function Start")
    $importer_name_label = GUICtrlCreateLabel("Your Name:", 8, 176, 60, 17, $SS_RIGHT)
    $importer_name = GUICtrlCreateInput($name, 72, 176, 201, 21)
    $importer_date_label = GUICtrlCreateLabel("Date:", 8, 208, 60, 17, $SS_RIGHT)
    $importer_date = GUICtrlCreateInput(@MON & "/" & @MDAY & "/" & @YEAR, 72, 208, 201, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $importer_time_label = GUICtrlCreateLabel("Time:", 280, 176, 60, 17, $SS_RIGHT)
    $importer_time = GUICtrlCreateInput(@HOUR & ":" & @MIN, 344, 176, 201, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $importer_comp_label = GUICtrlCreateLabel("Computer:", 280, 208, 60, 17, $SS_RIGHT)
    $importer_comp = GUICtrlCreateInput(@ComputerName, 344, 208, 201, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $picture = GUICtrlCreatePic($pic, 8, 240, 264, 198, BitOR($SS_NOTIFY,$WS_GROUP))
    $choose_loc_label = GUICtrlCreateLabel("Name the folder you want to save the pictures to", 280, 256, 265, 117, $SS_CENTER)
    $choose_loc = GUICtrlCreateInput($fold, 280, 280, 265, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    ;$file2 = $choose_loc
    $choose_pic_name = GUICtrlCreateInput($choose_pic_name, 384, 320, 161, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $choose_pic_name_label = GUICtrlCreateLabel("Name of the Picture:", 280, 320, 101, 17, $SS_RIGHT)
    $choose_pic_import_label = GUICtrlCreateLabel("<---------- Do you want to import this picture?", 288, 360, 203, 17)
    $btn_yes = GUICtrlCreateButton("Yes", 288, 392, 57, 25, 0)
    $btn_no = GUICtrlCreateButton("No", 352, 392, 57, 25, 0)
    $btn_yes_to_all = GUICtrlCreateButton("Yes to All", 416, 392, 81, 25, 0)
    $progress_bar = GUICtrlCreateProgress(288,425,250,25)
    $lbl_percentage = GUICtrlCreateLabel("0 out of - are copied! ",288,450,200,30)
    ;MsgBox(4096, "Importer Stuff", "Function End")
EndFunc

Func OnMnuFormatCard()
    $var = DriveGetDrive("all")
    $folder_name = " "
    $myflag = False
    If Not @error Then
        For $i=1 To $var[0]
            If FileExists($var[$i] & "\DCIM\100OLYMP\") Then
                ;MsgBox(4096,"Folder Found",$var[$i] & "\DCIM\100OLYMP\")
                $folder_name = $var[$i] & "\DCIM\100OLYMP\"
                $myflag = True
            EndIf
        Next
        If $myflag=False Then
            MsgBox(4096,"Error", "Pleast check the Card!")
        Else
            $folder_name = StringUpper($folder_name)
            If MsgBox(4164,"Warning","All the files of " & $folder_name & " will be deleted!" & @LF & "Are you sure?") = 6 Then
                FileDelete($folder_name &"*.jpg")
                MsgBox(4096,"Message","Memory card formatted successfully!")
            EndIf
        EndIf
    EndIf
EndFunc

Func Rename()
    $tmp1 = 0
    $tmp2 = 0
    While $tmp1 = 0
        $tmp = MsgBox(4, "Duplicate Photo", "A photo with the name " & $choose_pic_name & " already exists in the destination folder. Do you want to rename " & $choose_pic_name & "?")
        Switch $tmp
            Case 6
                $choose_pic_name = InputBox("Photo Rename", "Enter New Photo Name: ", $choose_pic_name)
                If IfExist($tmp2) = 1 Then
                    Rename()
                EndIf
                $tmp1 = 1
            Case 7
                $result = "unsuccessfully."
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Func All()

    $file_count = 0
    $search = FileFindFirstFile("*.*")
    $count = 0
    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
            ;MsgBox(4096, "File:", $file)
            $file_count= $file_count + 1
    WEnd

    ; Close the search handle
    FileClose($search)
    FileClose($file)

    $file= " "
    $search = " "
    GUICtrlSetData($lbl_percentage, $count & " out of " & $file_count & " are copied! ")
    ;MsgBox(4096,"Total Files",$file_count)

    ;msgbox(4096,"folder name",$folder_name)

    $search = FileFindFirstFile("*.jpg")

    $file = FileFindNextFile($search)
    While 1

        $photo = GUICtrlRead($txt_job_number) & "\" & GUICtrlRead($choose_loc) & "\"
        FileCopy(GUICtrlRead($txt_folder_to_import) & $file, $photo , 8)
        $count = $count+1
        GUICtrlSetData($lbl_percentage, $count & " out of " & $file_count & " are copied! ")
        $percentage_completed = Int((100 * $count)/$file_count)
        ;MsgBox(4096,"Percentage",$percentage_completed)
        GUICtrlSetData($progress_bar,$percentage_completed)
        $file = FileFindNextFile($search)
        If @error Then
            MsgBox(0, "All Done", "Import Complete")
            ClearData()
            ;Delete_Group($all)
            ExitLoop
        EndIf
    WEnd
EndFunc

Func IfExist($value)
    If FileExists($photo & $choose_pic_name) Then
        $value = 1
    Else
        $value = 0
    EndIf
    Return $value
EndFunc

Func ClearData()
    GUICtrlSetData($txt_job_number,"Click browse and select job")
    GUICtrlSetData($txt_folder_to_import,$folder_name)

    GUICtrlDelete($importer_name)
    GUICtrlDelete($importer_name_label)
    GUICtrlDelete($importer_date_label)
    GUICtrlDelete($importer_date)
    GUICtrlDelete($importer_time_label)
    GUICtrlDelete($importer_time)
    GUICtrlDelete($importer_comp_label)
    GUICtrlDelete($importer_comp)
    GUICtrlDelete($picture)
    GUICtrlDelete($choose_loc_label)
    GUICtrlDelete($choose_loc)
    GUICtrlDelete($choose_pic_name_label)
    GUICtrlDelete($choose_pic_name)
    GUICtrlDelete($choose_pic_import_label)
    GUICtrlDelete($btn_yes)
    GUICtrlDelete($btn_no)
    GUICtrlDelete($btn_yes_to_all)

    GUICtrlDelete($progress_bar)
    GUICtrlDelete($lbl_percentage)
EndFunc
#endregion

CreateGUI()
GUISetState(@SW_SHOW)
; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btn_folder_browse
            OnBtnFolderBrowse_Clicked()

        Case $mnu_about_about_photo_import
            OnMnuAbout_Photo_Import_Clicked()

        Case $mnu_administration_format_card
            OnMnuFormatCard()

        Case $btn_job_browse
            OnBtnJobBrowse_Clicked()

        Case $btn_import
            If GUICtrlRead($txt_job_number) = "Click Browse and select job" Or GUICtrlRead($txt_job_number) = ""  Then
                MsgBox(4096,"Error","Please select Job Number First")
            Else
                OnBtnImport_Clicked()
            EndIf

    Case $btn_yes
        If IfExist($val) = 1 Then
            Rename()
            $photo = GUICtrlRead($txt_job_number) & "\" & GUICtrlRead($choose_loc) & "\"
            FileCopy(GUICtrlRead($txt_folder_to_import) & $file, $photo & $choose_pic_name, 8)
            $file = FileFindNextFile($search)
            If @error Then
                MsgBox(0, "All Done", "Import Complete")
                ClearData()
            EndIf
            PhotoChoose()
            ImporterStuff()
        Else
            $photo = GUICtrlRead($txt_job_number) & "\" & GUICtrlRead($choose_loc) & "\"
            FileCopy(GUICtrlRead($txt_folder_to_import) & $file, $photo & GUICtrlRead($choose_pic_name), 8)
            $file = FileFindNextFile($search)
            If @error Then
                If MsgBox(0, "All Done", "Import Complete") = 1 Then
                    ClearData()
                EndIf
            Else
                PhotoChoose()
                GUICtrlDelete($btn_yes)
                GUICtrlDelete($btn_no)
                ImporterStuff()
            EndIf
        EndIf

    Case $btn_no
        $file = FileFindNextFile($search)
        If @error Then
            MsgBox(0, "All Done", "Import Complete")
            ClearData()
        Else
            PhotoChoose()
            GUICtrlDelete($btn_yes)
            GUICtrlDelete($btn_no)
            ImporterStuff()
        EndIf

    Case $btn_yes_to_all
        All()
        ClearData()

    Case $btn_format_card
        OnMnuFormatCard()

    Case $btn_cancel
        ClearData()

    Case $mnu_import_exit
        ExitLoop

    EndSwitch
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
Wend
    FileClose($search)
Link to comment
Share on other sites

There is no function called RunAsSet() and you have two calls for this function, due to which you are getting compilation errors. I don't know what you want to do with this function, but as I see it you have two options:

1) Define the function.

2) Use some standard function like RunAsWait() in it's place.

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

I get these when I compile it.

C:\Scripts\Photo Copy new 09.au3(119,108) : WARNING: $SS_NOTIFY: possibly used before declaration.

$si_logo = GUICtrlCreatePic("\\shermco\dfs\public\Graphics\SiLogo-blue.gif",10,10,150,100,BitOR($SS_NOTIFY,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Scripts\Photo Copy new 09.au3(119,118) : WARNING: $WS_GROUP: possibly used before declaration.

$si_logo = GUICtrlCreatePic("\\shermco\dfs\public\Graphics\SiLogo-blue.gif",10,10,150,100,BitOR($SS_NOTIFY,$WS_GROUP)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Scripts\Photo Copy new 09.au3(122,86) : WARNING: $ES_READONLY: possibly used before declaration.

$txt_folder_to_import = GUICtrlCreateInput( $folder_name ,320,25,275,18,$ES_READONLY)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Scripts\Photo Copy new 09.au3(237,83) : WARNING: $SS_RIGHT: possibly used before declaration.

$importer_name_label = GUICtrlCreateLabel("Your Name:", 8, 176, 60, 17, $SS_RIGHT)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Scripts\Photo Copy new 09.au3(249,123) : WARNING: $SS_CENTER: possibly used before declaration.

$choose_loc_label = GUICtrlCreateLabel("Name the folder you want to save the pictures to", 280, 256, 265, 117, $SS_CENTER)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Scripts\Photo Copy new 09.au3(119,108) : ERROR: $SS_NOTIFY: undeclared global variable.

$si_logo = GUICtrlCreatePic("\\shermco\dfs\public\Graphics\SiLogo-blue.gif",10,10,150,100,BitOR($SS_NOTIFY,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Scripts\Photo Copy new 09.au3(100,37) : ERROR: RunAsSet(): undefined function.

RunAsSet($user, $domain, $password)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Scripts\Photo Copy new 09.au3 - 2 error(s), 5 warning(s)

If I continue past that and try to run the EXE I get:

Line -1:

Error: Variable used without being declared.

Link to comment
Share on other sites

There is no function called RunAsSet() and you have two calls for this function, due to which you are getting compilation errors. I don't know what you want to do with this function, but as I see it you have two options:

1) Define the function.

2) Use some standard function like RunAsWait() in it's place.

Ok, thanks. Did there use to be a RunAsSet()? We have the script working in the shop since mid 2007 exactly like the code I posted and it works fine.

Link to comment
Share on other sites

There have been quite a few changes to AutoIt in the last 2 years

The include files have been split into smaller more focused groupings

RunAsSet() no longer exists have a look in the helpfile at RunAs

I've made a couple of minor changes to your script and it should at least compile now with the latest version of AutoIt 

#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>


#region "Variable Declaration"
$name = @UserName
$file2 = "Photos"
$file = " "
$pic = " "
$fold = " "
$choose_pic_name = " "
$search = " "
$progress_bar = " "
$percentage_completed = " "
$btn_format_card = " "

$lbl_percentage = ""
Global $btn_yes = 3, $btn_no = 3,  $btn_yes_to_all = 3
$importer_name = ""
$importer_name_label = ""
$importer_date_label = ""
$importer_date = ""
$importer_time_label = ""
$importer_time = ""
$importer_comp_label = ""
$importer_comp = ""
$pic = ""
$picture = ""
$choose_loc_label = ""
$choose_loc = "photos"
$choose_pic_name_label = ""
$choose_pic_name = "test"
$choose_pic_import_label = ""

$val = ""                                               ; Variable passed to IfExist Function
$txt_folder_to_import = " "                     ;Folder To Import
$txt_job_number = " "                           ;Job Number
$lbl_folder = ""
$lbl_job = ""
$btn_folder_browse = " "
$btn_job_browse = " "
$btn_import = " "
$btn_cancel = " "
$mnu_import = " "
$mnu_import_new = " "
$mnu_import_view_imported = " "
$mnu_import_exit = " "
$mnu_administration = " "
$mnu_administration_format_card = " "
$mnu_administration_import_log = " "
$mnu_administration_preferences  = " "
$mnu_administration_change_runas = " "
$mnu_about = " "
$mnu_about_about_photo_import = " "
$folder_name = "Click Browse and select folder to import"   ; Variable for Initial folder location
                #comments-start
                    code inserted by Abhay
                #comments-end
                    $var = DriveGetDrive("all")

                    $myflag = False
                    If Not @error Then
                        For $i=1 To $var[0]
                            If FileExists($var[$i] & "\DCIM\100OLYMP\") Then
                                ;MsgBox(4096,"Folder Found",$var[$i] & "\DCIM\100OLYMP\")
                                $folder_name = $var[$i] & "\DCIM\100OLYMP\"
                                $myflag = True
                            EndIf
                        Next
                        If $myflag=False Then
                            MsgBox(4096,"Error", "Pleast check the Card!")
                        EndIf
                    EndIf

                #cs
                    code inserted by Abhay End
                #ce
$job_name = "Click Browse and select job"                           ;Job Number
$photo = " "                                ;Full path of the photo which is to be uploaded
$i = 0                                      ;Variable for loops
$j = 0                                      ;Variable for loops
$flg = False                                ;Variable for flag
$si_logo = ""                               ;Shermco logo picture
$si_label = ""                              ;Shermco label text
#endregion

#region "OnAutoItStart Function"
Func OnAutoItStart()
    ; Add User name
    $user = "ASDcamera"
    ; Add Domain name
    $domain = "shermco.ind"
    ; Add Password
    $password = "@SDcam3ra$"
    ;
    ; Check incomong parameters
    If Not $CMDLINE[0] Then
        ; No parameters then restart as admin
;~         RunAsSet($user, $domain, $password)
                RunAs ( $user, $domain, $password, 0, '"' & @ScriptFullPath & '" /admin')
;~         Run('"' & @ScriptFullPath & '" /admin')
;~         RunAsSet()
        Exit
    ElseIf $CMDLINE[1] <> '/admin' Then
        ; Exit script with error code 1
        Exit 1
    EndIf
EndFunc

#endregion

#region "GUI Func"


Func CreateGUI()
    GUICreate("Photo Import - Shermco Ind",800,600,115,50)
    GUISetBkColor(0xFFFFFF)
    CreateMenu()
    $si_logo = GUICtrlCreatePic("\\shermco\dfs\public\Graphics\SiLogo-blue.gif",10,10,150,100,BitOR($SS_NOTIFY,$WS_GROUP))
    $folder_label = GUICtrlCreateLabel("Select folder to import : ",200,27,150,18)
    $folder_name = StringUpper($folder_name)
    $txt_folder_to_import = GUICtrlCreateInput( $folder_name ,320,25,275,18,$ES_READONLY)
    $btn_folder_browse = GUICtrlCreateButton("Browse",600,23,60,22)
    $lbl_job = GUICtrlCreateLabel("Job Number : ",245,60,150,18)
    $txt_job_number = GUICtrlCreateInput( $job_name ,320,60,275,18,$ES_READONLY)
    $btn_job_browse = GUICtrlCreateButton("Browse",600,58,60,22)
    $btn_import = GUICtrlCreateButton("Import",320,95,60,22)
    $btn_cancel = GUICtrlCreateButton("Cancel",390,95,60,22)
    $btn_format_card = GUICtrlCreateButton("Format Card",520,95,75,22)
EndFunc

Func CreateMenu()
    $mnu_import = GUICtrlCreateMenu("Import")
    $mnu_import_new = GUICtrlCreateMenuitem("New",$mnu_import)
    $mnu_import__view_imported = GUICtrlCreateMenuitem("View Imported",$mnu_import)
    $mnu_import_exit = GUICtrlCreateMenuitem("Exit",$mnu_import)
    $mnu_administration = GUICtrlCreateMenu("Administration")
    $mnu_administration_format_card = GUICtrlCreateMenuitem("Format Card",$mnu_administration )
    $mnu_administration_import_log = GUICtrlCreateMenuitem("Import Log",$mnu_administration )
    $mnu_administration_preferences = GUICtrlCreateMenuitem("Preferences",$mnu_administration )
    $mnu_administration_change_runas = GUICtrlCreateMenuitem("Change RunAs",$mnu_administration )
    $mnu_about = GUICtrlCreateMenu("About")
    $mnu_about_about_photo_import = GUICtrlCreateMenuitem("About Photo Import", $mnu_about )
EndFunc

Func OnMnuAbout_Photo_Import_Clicked()
    #include <GUIConstants.au3>
    #Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Forms\Importer UI about.kxf
    $Form1 = GUICreate("About Photo Import - Shermco Ind", 324, 237, 303, 219)
    GUISetIcon("D:\006.ico")
    GUISetBkColor(0xFFFFFF)
    $GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 185)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Image1 = GUICtrlCreatePic("\\shermco\dfs\public\Graphics\SiLogo-blue.gif", 16, 24, 105, 97, BitOR($SS_NOTIFY,$WS_GROUP))
    $Label1 = GUICtrlCreateLabel("Photo Importer", 152, 24, 78, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Label2 = GUICtrlCreateLabel("V 1.1.0 Beta", 152, 48, 63, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Label4 = GUICtrlCreateLabel("Created For ASD by Brian Harris", 16, 160, 155, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Label3 = GUICtrlCreateLabel("Copyright: Shermco Industries 2006", 16, 136, 171, 17, $WS_GROUP)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("&OK", 112, 208, 75, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                ExitLoop
            Case $Button1
                GUIDelete()
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Func OnBtnFolderBrowse_Clicked()
            $var123 = DriveGetDrive("all")
            $myflag = False
                If Not @error Then
                    For $i123=1 To $var123[0]
                        If FileExists($var123[$i123] & "\DCIM\100OLYMP\") Then
                            MsgBox(4096,"Folder Found",$var123[$i123] & "\DCIM\100OLYMP\")
                            $folder_name = FileSelectFolder("Choose a folder to import", "C;\", 6, $var123[$i123] & "\DCIM\100OLYMP")
                            $myflag = True
                        EndIf
                    Next
                    If $myflag = False Then
                        MsgBox(4096,"Error", "Please check the Card!")
                    EndIf
                EndIf
            StringUpper($folder_name)
            GuiCtrlSetData($txt_folder_to_import, $folder_name)
EndFunc

Func OnBtnJobBrowse_Clicked()
    $job_name = FileSelectFolder("Choose a job to save to", "\\shermco\dfs\reports\MSDReports_Data", 6, "\\shermco\dfs\reports\MSDReports_Data")
    ;MsgBox(4096,"Job Number",$job_name)
    GuiCtrlSetData($txt_job_number, $job_name)
EndFunc

Func OnBtnImport_Clicked()
    ;If $btn_import = 1 Then
    FileChangeDir($folder_name)
    ;FileChangeDir(GUICtrlRead($txt_folder_to_import))
    $search = FileFindFirstFile("*.jpg")
    $file = FileFindNextFile($search)
    If $search = -1 Then
        MsgBox(0, "Error", "No pictures to copy. Plese select a different directory.")
        ;$result = "unsuccessfully."
        ;Delete_Group($all)
        ;Import_New()
    EndIf
    FolName()
    PhotoChoose()
    ImporterStuff()
    ;EndIf
EndFunc

Func FolName()
    $fold = InputBox("Name oF Folder", "Name the folder to import the pictures into", $file2)
EndFunc

Func PhotoChoose()
    ;MsgBox(4096,"Function", "Photo Choose")
    ;MsgBox(4096,"$file",$file)
    $choose_pic_name = $file
    $pic = $folder_name & $file
    ;MsgBox(4096, "Photo Choose",$pic)
EndFunc
Func ImporterStuff()

    ;MsgBox(4096, "Importer Stuff", "Function Start")
    $importer_name_label = GUICtrlCreateLabel("Your Name:", 8, 176, 60, 17, $SS_RIGHT)
    $importer_name = GUICtrlCreateInput($name, 72, 176, 201, 21)
    $importer_date_label = GUICtrlCreateLabel("Date:", 8, 208, 60, 17, $SS_RIGHT)
    $importer_date = GUICtrlCreateInput(@MON & "/" & @MDAY & "/" & @YEAR, 72, 208, 201, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $importer_time_label = GUICtrlCreateLabel("Time:", 280, 176, 60, 17, $SS_RIGHT)
    $importer_time = GUICtrlCreateInput(@HOUR & ":" & @MIN, 344, 176, 201, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $importer_comp_label = GUICtrlCreateLabel("Computer:", 280, 208, 60, 17, $SS_RIGHT)
    $importer_comp = GUICtrlCreateInput(@ComputerName, 344, 208, 201, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $picture = GUICtrlCreatePic($pic, 8, 240, 264, 198, BitOR($SS_NOTIFY,$WS_GROUP))
    $choose_loc_label = GUICtrlCreateLabel("Name the folder you want to save the pictures to", 280, 256, 265, 117, $SS_CENTER)
    $choose_loc = GUICtrlCreateInput($fold, 280, 280, 265, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    ;$file2 = $choose_loc
    $choose_pic_name = GUICtrlCreateInput($choose_pic_name, 384, 320, 161, 21)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $choose_pic_name_label = GUICtrlCreateLabel("Name of the Picture:", 280, 320, 101, 17, $SS_RIGHT)
    $choose_pic_import_label = GUICtrlCreateLabel("<---------- Do you want to import this picture?", 288, 360, 203, 17)
    $btn_yes = GUICtrlCreateButton("Yes", 288, 392, 57, 25, 0)
    $btn_no = GUICtrlCreateButton("No", 352, 392, 57, 25, 0)
    $btn_yes_to_all = GUICtrlCreateButton("Yes to All", 416, 392, 81, 25, 0)
    $progress_bar = GUICtrlCreateProgress(288,425,250,25)
    $lbl_percentage = GUICtrlCreateLabel("0 out of - are copied! ",288,450,200,30)
    ;MsgBox(4096, "Importer Stuff", "Function End")
EndFunc

Func OnMnuFormatCard()
    $var = DriveGetDrive("all")
    $folder_name = " "
    $myflag = False
    If Not @error Then
        For $i=1 To $var[0]
            If FileExists($var[$i] & "\DCIM\100OLYMP\") Then
                ;MsgBox(4096,"Folder Found",$var[$i] & "\DCIM\100OLYMP\")
                $folder_name = $var[$i] & "\DCIM\100OLYMP\"
                $myflag = True
            EndIf
        Next
        If $myflag=False Then
            MsgBox(4096,"Error", "Pleast check the Card!")
        Else
            $folder_name = StringUpper($folder_name)
            If MsgBox(4164,"Warning","All the files of " & $folder_name & " will be deleted!" & @LF & "Are you sure?") = 6 Then
                FileDelete($folder_name &"*.jpg")
                MsgBox(4096,"Message","Memory card formatted successfully!")
            EndIf
        EndIf
    EndIf
EndFunc

Func Rename()
    $tmp1 = 0
    $tmp2 = 0
    While $tmp1 = 0
        $tmp = MsgBox(4, "Duplicate Photo", "A photo with the name " & $choose_pic_name & " already exists in the destination folder. Do you want to rename " & $choose_pic_name & "?")
        Switch $tmp
            Case 6
                $choose_pic_name = InputBox("Photo Rename", "Enter New Photo Name: ", $choose_pic_name)
                If IfExist($tmp2) = 1 Then
                    Rename()
                EndIf
                $tmp1 = 1
            Case 7
                $result = "unsuccessfully."
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Func All()

    $file_count = 0
    $search = FileFindFirstFile("*.*")
    $count = 0
    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
            ;MsgBox(4096, "File:", $file)
            $file_count= $file_count + 1
    WEnd

    ; Close the search handle
    FileClose($search)
    FileClose($file)

    $file= " "
    $search = " "
    GUICtrlSetData($lbl_percentage, $count & " out of " & $file_count & " are copied! ")
    ;MsgBox(4096,"Total Files",$file_count)

    ;msgbox(4096,"folder name",$folder_name)

    $search = FileFindFirstFile("*.jpg")

    $file = FileFindNextFile($search)
    While 1

        $photo = GUICtrlRead($txt_job_number) & "\" & GUICtrlRead($choose_loc) & "\"
        FileCopy(GUICtrlRead($txt_folder_to_import) & $file, $photo , 8)
        $count = $count+1
        GUICtrlSetData($lbl_percentage, $count & " out of " & $file_count & " are copied! ")
        $percentage_completed = Int((100 * $count)/$file_count)
        ;MsgBox(4096,"Percentage",$percentage_completed)
        GUICtrlSetData($progress_bar,$percentage_completed)
        $file = FileFindNextFile($search)
        If @error Then
            MsgBox(0, "All Done", "Import Complete")
            ClearData()
            ;Delete_Group($all)
            ExitLoop
        EndIf
    WEnd
EndFunc

Func IfExist($value)
    If FileExists($photo & $choose_pic_name) Then
        $value = 1
    Else
        $value = 0
    EndIf
    Return $value
EndFunc

Func ClearData()
    GUICtrlSetData($txt_job_number,"Click browse and select job")
    GUICtrlSetData($txt_folder_to_import,$folder_name)

    GUICtrlDelete($importer_name)
    GUICtrlDelete($importer_name_label)
    GUICtrlDelete($importer_date_label)
    GUICtrlDelete($importer_date)
    GUICtrlDelete($importer_time_label)
    GUICtrlDelete($importer_time)
    GUICtrlDelete($importer_comp_label)
    GUICtrlDelete($importer_comp)
    GUICtrlDelete($picture)
    GUICtrlDelete($choose_loc_label)
    GUICtrlDelete($choose_loc)
    GUICtrlDelete($choose_pic_name_label)
    GUICtrlDelete($choose_pic_name)
    GUICtrlDelete($choose_pic_import_label)
    GUICtrlDelete($btn_yes)
    GUICtrlDelete($btn_no)
    GUICtrlDelete($btn_yes_to_all)

    GUICtrlDelete($progress_bar)
    GUICtrlDelete($lbl_percentage)
EndFunc
#endregion

CreateGUI()
GUISetState(@SW_SHOW)
; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btn_folder_browse
            OnBtnFolderBrowse_Clicked()

        Case $mnu_about_about_photo_import
            OnMnuAbout_Photo_Import_Clicked()

        Case $mnu_administration_format_card
            OnMnuFormatCard()

        Case $btn_job_browse
            OnBtnJobBrowse_Clicked()

        Case $btn_import
            If GUICtrlRead($txt_job_number) = "Click Browse and select job" Or GUICtrlRead($txt_job_number) = ""  Then
                MsgBox(4096,"Error","Please select Job Number First")
            Else
                OnBtnImport_Clicked()
            EndIf

    Case $btn_yes
        If IfExist($val) = 1 Then
            Rename()
            $photo = GUICtrlRead($txt_job_number) & "\" & GUICtrlRead($choose_loc) & "\"
            FileCopy(GUICtrlRead($txt_folder_to_import) & $file, $photo & $choose_pic_name, 8)
            $file = FileFindNextFile($search)
            If @error Then
                MsgBox(0, "All Done", "Import Complete")
                ClearData()
            EndIf
            PhotoChoose()
            ImporterStuff()
        Else
            $photo = GUICtrlRead($txt_job_number) & "\" & GUICtrlRead($choose_loc) & "\"
            FileCopy(GUICtrlRead($txt_folder_to_import) & $file, $photo & GUICtrlRead($choose_pic_name), 8)
            $file = FileFindNextFile($search)
            If @error Then
                If MsgBox(0, "All Done", "Import Complete") = 1 Then
                    ClearData()
                EndIf
            Else
                PhotoChoose()
                GUICtrlDelete($btn_yes)
                GUICtrlDelete($btn_no)
                ImporterStuff()
            EndIf
        EndIf

    Case $btn_no
        $file = FileFindNextFile($search)
        If @error Then
            MsgBox(0, "All Done", "Import Complete")
            ClearData()
        Else
            PhotoChoose()
            GUICtrlDelete($btn_yes)
            GUICtrlDelete($btn_no)
            ImporterStuff()
        EndIf

    Case $btn_yes_to_all
        All()
        ClearData()

    Case $btn_format_card
        OnMnuFormatCard()

    Case $btn_cancel
        ClearData()

    Case $mnu_import_exit
        ExitLoop

    EndSwitch
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
Wend
    FileClose($search)
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Things change in AutoIt: http://www.autoitscript.com/autoit3/docs/history.htm ... Sometimes, these changes are breaking. Meaning they break any existing scripts. Your script has undergone a few script breaking changes, and that's why it currently does not compile.

There's quite an extended list available here: http://www.autoitscript.com/autoit3/docs/script_breaking_changes.htm take particular note of the changes on 16th May, 2008 - v3.2.12.0

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...