Sign in to follow this  
Followers 0
MariusN

2 Identical programs 1 as Function, other as normal -not working

4 posts in this topic

#1 ·  Posted (edited)

Hi folks...I made a small utility to expand a file from a cd to a file in, lets say, your system32 directory. I have one slight problem...

The FIRST one works 100% as a STANDALONE program...see below:

#RequireAdmin
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=filesExpander.ico
#AutoIt3Wrapper_Outfile=......CD-MenuAnti-Virusexpander.exe
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
;Global $sLogFile = @ScriptDir & "Logfile.txt"
;Global $iLogState = 0
Opt("MustDeclareVars", 1)
Opt("GUICloseOnESC", 0)
Global $Cabinet, $destination, $file, $gui, $sSourceFolder, $Button_1, $MSG, $box1, $box2, $Button_2, $Button_OK, $file, $var, $string2, $box1a
Global $first, $recurse, $string1, $read1, $string3, $array, $string, $read2, $read3, $attrib, $first1, $first1a, $first2, $first2a, $Research
Global $check = 0
Global $label, $test1, $test2, $label2, $read4, $read5, $hImage, $image1, $BUTTON_1a, $msg1, $Date, $label3
Global $joker = 0
Global $font = "Comic Sans MS"
$gui = GUICreate(" -= Expander v1.1 =-", 650, 200)
$Date = GUICtrlCreateLabel("Build: ( 14 Dec 2011 )", 300, 10, 340, 30)
GUICtrlCreateIcon(@TempDir & "penguin.ico", "", 545, 65, 48, 48)
$label = GUICtrlCreateLabel("", 200, 83, 340, 30)
GUICtrlSetFont(-1, 8.5, 600, 0)
GUICtrlSetColor(-1, 0x3300cc)
$label2 = GUICtrlCreateLabel("", 400, 83, 100, 30)
GUICtrlSetFont(-1, 8.5, 600, 0)
GUICtrlSetColor(-1, 0xff0000)
$label3 = GUICtrlCreateLabel("Compiled By: Marius Nieuwenhuizen", 475, 185, 340, 30)
$Button_1 = GUICtrlCreateButton("File to Change...", 40, 25, 130, 50)
_GUICtrlButton_SetImageList($Button_1, _GetImageListHandle("shell32.dll", 45, True), 1)
$Button_2 = GUICtrlCreateButton("Source File...", 40, 105, 130, 50)
_GUICtrlButton_SetImageList($Button_2, _GetImageListHandle("shell32.dll", 22, True), 1)
$Button_OK = GUICtrlCreateButton("I'm Satisfied...Replace Windows's file...!", 225, 150, 250, 30)
$box1 = GUICtrlCreateInput("", 200, 40, 300, 20)
$box2 = GUICtrlCreateInput("", 200, 120, 300, 20)
$hImage = _GUIImageList_Create(32, 32, 5)
$image1 = _GUIImageList_AddIcon($hImage, @TempDir & "Forward.ico", 0, True)
GUISetState()
While 1
$MSG = GUIGetMsg()
Select
Case $MSG = $GUI_EVENT_CLOSE
FileDelete(@TempDir & "penguin.ico")
FileDelete(@TempDir & "Forward.ico")
ExitLoop
Case $MSG = $Button_1 ; File to Change
$check = 0
$joker = 1
$destination = FileOpenDialog("File to Change", @SystemDir & "", "(*.*)", 1)
GUICtrlSetData($box1, $destination)
$first1 = StringTrimRight($destination, 1)
If $joker = 1 Then _loop($sSourceFolder)
Case $MSG = $Button_2 ; Source- File
$box1a = GUICtrlRead($box1)
If $box1a = "" Then
$msg1 = MsgBox(16, "Oops!", 'Get "File to Change" first...')
Else
$check = 0
$sSourceFolder = FileSelectFolder("Copy From ...", "", 2)
If $sSourceFolder = "" Then
     $msg1 = MsgBox(16 + 5, "Oops!", 'No "Source" Selected...Please do so now...')
Else
     _loop($sSourceFolder)
EndIf
If $check = 0 Then
     GUICtrlSetData($box2, "Finished.....Nothing found!")
     GUICtrlSetData($label, "Finished.....Nothing found!")
     GUICtrlSetData($label2, "")
EndIf
EndIf
Case $MSG = $Button_OK
If $check <> 1 Then
MsgBox(16, "ERROR", "Nothing to Expand!")
Else
$read5 = GUICtrlRead($box2)
$attrib = FileSetAttrib($read4, "-R+A-S-H")
$var = Run(@ComSpec & " /c " & "expand.exe " & $read5 & " " & $read4, "", @SW_HIDE)
If $attrib = 1 Then
     MsgBox(0, "Success!", "Successfuly extracted " & $read5 & " to " & $read4)
Else
     MsgBox(16, "Error!", "Could not replace file in " & $read4)
EndIf
EndIf
EndSelect
WEnd

;==>_Research
Func _loop($sSourceFolder)
Local $hSearch, $sFile
If StringRight($sSourceFolder, 1) <> "" Then $sSourceFolder &= ""
$read4 = GUICtrlRead($box1)
$first1 = StringTrimRight($read4, 1)
$hSearch = FileFindFirstFile($sSourceFolder & "*.*")
If $hSearch = -1 Then Return
While 1
; START CALCULATES 2ND INPUT !!!
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
If @extended Then
_loop($sSourceFolder & $sFile)
Else
If $check = 1 Then
ExitLoop
EndIf
$first2 = StringTrimRight($sFile, 1)
$test1 = GUICtrlSetData($box2, $sSourceFolder & $sFile)
If StringInStr($read4, $first2) Then
$test1 = GUICtrlSetData($box2, $sSourceFolder & $sFile)
$check = 1
GUICtrlSetData($label, ".......................File FOUND!!!")
Return
EndIf
EndIf
WEnd
EndFunc ;==>_loop
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
Local $iSize = 16
If $fLarge Then $iSize = 32
Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
_GUIImageList_AddBitmap($hImage, $sFile)
Else
_GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
EndIf
Return $hImage
EndFunc ;==>_GetImageListHandle

BUT....As soon as i change it to a FUNCTION, it doesnt work...(see below)

#RequireAdmin
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=filesExpander.ico
#AutoIt3Wrapper_Outfile=......CD-MenuAnti-Virusexpander.exe
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
Opt("MustDeclareVars", 1)
Opt("GUICloseOnESC", 0)

_expander()
Func _expander()
Opt("GUICloseOnESC", 0)
Global $Cabinet, $destination, $file, $gui, $sSourceFolder, $BUTTON_1, $MSG, $box1, $box2, $BUTTON_2, $Button_OK, $file, $var, $string2
Global $first, $recurse, $string1, $read1, $string3, $array, $string, $read2, $read3, $attrib, $first1, $first1a, $first2, $first2a, $Research
Global $check = 0
Global $label, $test1, $test2, $label2, $read4, $read5, $hImage, $image1, $BUTTON_1a, $msg1, $Date, $label3, $box1a
Global $joker = 0
Global $font = "Comic Sans MS"
$gui = GUICreate(" -= Expander v1.1 =-", 650, 200)
$Date = GUICtrlCreateLabel("Build: ( 14 Dec 2011 )", 300, 10, 340, 30)
GUICtrlCreateIcon(@TempDir & "penguin.ico", "", 545, 65, 48, 48)
$label = GUICtrlCreateLabel("", 200, 83, 340, 30)
GUICtrlSetFont(-1, 8.5, 600, 0)
GUICtrlSetColor(-1, 0x3300cc)
$label2 = GUICtrlCreateLabel("", 400, 83, 100, 30)
GUICtrlSetFont(-1, 8.5, 600, 0)
GUICtrlSetColor(-1, 0xff0000)
$label3 = GUICtrlCreateLabel("Compiled By: Marius Nieuwenhuizen", 475, 185, 340, 30)
$BUTTON_1 = GUICtrlCreateButton("File to Change...", 40, 25, 130, 50)
_GUICtrlButton_SetImageList($BUTTON_1, _GetImageListHandle("shell32.dll", 45, True), 1)
$BUTTON_2 = GUICtrlCreateButton("Source File...", 40, 105, 130, 50)
_GUICtrlButton_SetImageList($BUTTON_2, _GetImageListHandle("shell32.dll", 22, True), 1)
$Button_OK = GUICtrlCreateButton("I'm Satisfied...Replace Windows's file...!", 225, 150, 250, 30)
$box1 = GUICtrlCreateInput("", 200, 40, 300, 20)
$box2 = GUICtrlCreateInput("", 200, 120, 300, 20)
$hImage = _GUIImageList_Create(32, 32, 5)
$image1 = _GUIImageList_AddIcon($hImage, @TempDir & "Forward.ico", 0, True)
GUISetState()
While 1
$MSG = GUIGetMsg()
Select
Case $MSG = $GUI_EVENT_CLOSE
FileDelete(@TempDir & "penguin.ico")
FileDelete(@TempDir & "Forward.ico")
ExitLoop
Case $MSG = $BUTTON_1 ; File to Change
$check = 0
$joker = 1
$destination = FileOpenDialog("File to Change", @SystemDir & "", "(*.*)", 1)
GUICtrlSetData($box1, $destination)
$first1 = StringTrimRight($destination, 1)
If $joker = 1 Then
     _loop($sSourceFolder)
EndIf
Case $MSG = $BUTTON_2 ; Source- File
$box1a = GUICtrlRead($box1)
If $box1a = "" Then
     $msg1 = MsgBox(16, "Oops!", 'Get "File to Change" first...')
Else
     $check = 0
     $sSourceFolder = FileSelectFolder("Copy From ...", "", 2)
     If $sSourceFolder = "" Then
     $msg1 = MsgBox(16 + 5, "Oops!", 'No "Source" Selected...Please do so now...')
     Else
     _loop($sSourceFolder)
     EndIf
     If $check = 0 Then
     GUICtrlSetData($box2, "Finished.....Nothing found!")
     GUICtrlSetData($label, "Finished.....Nothing found!")
     GUICtrlSetData($label2, "")
     EndIf
EndIf
Case $MSG = $Button_OK
If $check <> 1 Then
     MsgBox(16, "ERROR", "Nothing to Expand!")
Else
     $read5 = GUICtrlRead($box2)
     $attrib = FileSetAttrib($read4, "-R+A-S-H")
     $var = Run(@ComSpec & " /c " & "expand.exe " & $read5 & " " & $read4, "", @SW_HIDE)
     If $attrib = 1 Then
     MsgBox(0, "Success!", "Successfuly extracted " & $read5 & " to " & $read4)
     Else
     MsgBox(16, "Error!", "Could not replace file in " & $read4)
     EndIf
EndIf
EndSelect
WEnd
GUIDelete()
EndFunc ;==>_expander
Func _loop($sSourceFolder)
Local $hSearch, $sFile1, $box1, $read4, $first1, $first2, $test1, $box2, $label, $first
If StringRight($sSourceFolder, 1) <> "" Then $sSourceFolder &= ""
$read4 = GUICtrlRead($box1)
$first1 = StringTrimRight($read4, 1)
$hSearch = FileFindFirstFile($sSourceFolder & "*.*")
If $hSearch = -1 Then Return
While 1
; START CALCULATES 2ND INPUT !!!
$sFile1 = FileFindNextFile($hSearch)
If @error Then ExitLoop
If @extended Then
_loop($sSourceFolder & $sFile1)
Else
If $check = 1 Then
ExitLoop
EndIf
$first2 = StringTrimRight($sFile1, 1)
$test1 = GUICtrlSetData($box2, $sSourceFolder & $sFile1)
If StringInStr($read4, $first2) Then
$test1 = GUICtrlSetData($box2, $sSourceFolder & $sFile1)
$check = 1
GUICtrlSetData($label, ".......................File FOUND!!!")
Return
EndIf
EndIf
WEnd
EndFunc ;==>_loop
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
Local $iSize = 16
If $fLarge Then $iSize = 32
Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
_GUIImageList_AddBitmap($hImage, $sFile)
Else
_GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
EndIf
Return $hImage
EndFunc ;==>_GetImageListHandle

What am i doing wrong with the "function" one? You'll notice its EXACTLY the same "coding" as the above, with the only exception that it starts like a function...Thing is, i wrote a huge utility program that has a lot of other programs "embedded" in it (Programs that i created as functions and WORKS....except THIS one). It looks like a small programming fault on my side, but do you think i can FIND it? lol

(You can enter the programs in AutoIt, as it is 2 complete programs)

...Hope someone can help me "spot" my fault regarding the "function"-one?

...tia

Edited by MariusN

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Maybe it works in your other post Posted Image

a geez...sorry guys...double post...lol

Can you delete the previous for me please Admin?

tia

Edited by MariusN

Share this post


Link to post
Share on other sites

I found my prob....had the variable in the wrong place....thx folks...

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