Immensee Posted June 4, 2006 Share Posted June 4, 2006 Hey, i've got a problem...again :"> I don't know how to fix this, i'm very bad with Arrays and Global/Local and that kind of things... here's my script: expandcollapse popup;; .Au3 Includes ;; #include <GUIConstants.au3> #include <String.au3> #include <File.au3> ;; Setup ;; Global $width = @DesktopWidth/2 Global $height = @DesktopHeight/2 Global $title = "File Converter Program" Global $handle = GUICreate($title,$width,$height) Global $file_data = "feed.dat" Global $file_map = "Files" ;; Arrays ;; Global $LoadedFilePass Dim $LoadedFilePass[_FileCountLines($file_data)] ;; Menu Objects ;; $menu_file = GUICtrlCreateMenu("File") $menu_view = GUICtrlCreateMenu("View") ;; Menu File Items ;; $menu_file_add = GUICtrlCreateMenuitem("Add File",$menu_file) GUICtrlCreateMenuLoadFile() $menu_file_exit = GUICtrlCreateMenuitem("Exit",$menu_file) ;; Menu View Items ;; $status_default = "Statusbar" $menu_view_status = GUICtrlCreateMenuitem($status_default,$menu_view) GUICtrlSetState($menu_view_status,$GUI_CHECKED) ;; TreeView Objects ;; $TreeView_main = GUICtrlCreateTreeView($width*0.01,$height*0.01,$width*0.25,$height*0.89,-1,$WS_EX_CLIENTEDGE) $TreeView_general = GUICtrlCreateTreeViewItem("General",$TreeView_main) ;; Statuslabel ;; $statusbar = GUICtrlCreateLabel("Ready",0,$height*0.91,$width,$height,BitOr($SS_SIMPLE,$SS_SUNKEN)) GUISetState(@SW_SHOW,$handle) While 1 $event = GUIGetMsg() Select Case $event = $GUI_EVENT_CLOSE Or $event = $menu_file_exit Exit Case $event = $menu_file_add func_add_file() Case $event = $menu_view_status If BitAnd(GUICtrlRead($menu_view_status),$GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($menu_view_status,$GUI_UNCHECKED) GUICtrlSetState($statusbar,$GUI_HIDE) Else GUICtrlSetState($menu_view_status,$GUI_CHECKED) GUICtrlSetState($statusbar,$GUI_SHOW) GUICtrlSetData($statusbar,"Statusbar revealed",$status_default) EndIf EndSelect func_load_file() WEnd Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func func_add_file() $fileOpen = FileOpenDialog("Add a file",@WorkingDir,"All Files (*.*)",1+2) If @error = 0 Then $fileGet = StringSplit($fileOpen,"\") ;; Split the full path $fileName = $fileGet[$fileGet[0]] ;; $FileGet[LAST_ARRAY] $fileType = StringRight($fileName,3) ;; Get last 3 chars (txt) $filePath = @ScriptDir&"\"&$file_data ;; feed.dat @ScriptDir $fileStr = $fileType&" | "&$fileOpen&@CRLF ;; ex. txt | C:\docu..etc. FileWrite($filePath,$fileStr) ;; Write to $Filepath,$FileStr $string = FileRead($fileOpen,FileGetSize($fileOpen)) $stringLeft = StringLeft($string,30) $stringLeft = _StringReverse($stringLeft) $InputString= "You can password protect this file by entering a password below." $password = InputBox("Password Protection",$InputString) $string = _StringEncrypt(1,$stringLeft & StringTrimLeft($string,30),$password,1) $LoadedFilePass[_FileCountLines($file_data)] = $password $fileSName = StringLeft($fileName, StringLen($fileName)-4) $filePath = @ScriptDir&"\"&$file_map&"\"&$fileSName&".fls" FileWrite($filePath,$string) EndIf EndFunc Func GUICtrlCreateMenuLoadFile() If (FileExists($file_data)) Then $lines = _FileCountLines($file_data) If ($lines>0) Then $menu_file_load = GUICtrlCreateMenu("Load File",$menu_file) Global $loadedFileName Global $LoadedFileMenu Dim $loadedFileName[$lines] Dim $LoadedFileMenu[$lines] For $lines_read = 1 To $lines Step +1 $fileRead = FileReadLine($file_data,$lines_read) $fileGet = StringSplit($fileRead,"\") $item_name = StringTrimRight($fileGet[$fileGet[0]],4) $loadedFileName[$lines_read] = $fileRead $LoadedFileMenu[$lines_read] = GUICtrlCreateMenuitem($item_name,$menu_file_load) Next EndIf Else _FileCreate($file_data) EndIf EndFunc Func func_load_file() $event = GUIGetMsg() $size = _FileCountLines($file_data) For $filenumber = 1 To $size Step +1 if $event = $LoadedFileMenu[$filenumber] Then $error = 0 $fileOpen = FileOpen($loadedFileName[$filenumber],0) If @error <> -1 Then $string = FileRead($fileOpen,FileGetSize($fileOpen)) $stringLeft = StringLeft($string,30) $stringLeft = _StringReverse($stringLeft) $string = _StringEncrypt(0,$stringLeft & StringTrimLeft($string,30),$LoadedFilePass[$filenumber],1) $fileType = StringRight($loadedFileName[$filenumber],3) func_preview_file($fileType) EndIf EndIf Next EndFunc Check below, there's the bug. It says: C:\Documents and Settings\Administrator\Desktop\New MyGUI\File Converter.au3(130,44) : WARNING: $LoadedFileMenu: possibly used before declaration. if $event = $LoadedFileMenu[$filenumber] Then ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ But on the previous function i said: Global $LoadedFileMenu GLOBAL.... so it sends the thing to the global thingy so it can be reached everywhere? OMG... Please help me.. - ImMenSe Link to comment Share on other sites More sharing options...
SlimShady Posted June 4, 2006 Share Posted June 4, 2006 Put the Global $LoadedFileMenu line at the top of your script. Link to comment Share on other sites More sharing options...
exodius Posted June 4, 2006 Share Posted June 4, 2006 Yeah, you shouldn't declare Global variables inside of functions, the idea is that they are GLOBAL and thereby exist higher in the hiearchy than functions do. Link to comment Share on other sites More sharing options...
Nomad Posted June 4, 2006 Share Posted June 4, 2006 Also, you are correct about the meaning of Global, but until it has been declared it doesn't exist. So, if you call the variable before it is declared.. Nomad Link to comment Share on other sites More sharing options...
Immensee Posted June 4, 2006 Author Share Posted June 4, 2006 Also, you are correct about the meaning of Global, but until it has been declared it doesn't exist. So, if you call the variable before it is declared..Nomad You'll get a huge error that requires help from two people that are discussing about that and causes two topic pages ?Thanks for the help Link to comment Share on other sites More sharing options...
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