Jump to content

Need a little help!


mr_carter
 Share

Recommended Posts

I'm new GUI but see unlimited uses with it. I have created a form with several buttons. One button for each facility my company operates. I currently have text files of all our locations with all our netwrok settings and PC related notes. I want to be able to click the button and it loads or writes the contents of that text file somewhere in the GUI with out any other interaction. This way I can keep all info in one location and make life on helpdesk staff easier.. Any help would be much Appreciated!!!

:whistle:

c2

#include <GUIConstants.au3>;Generated with Form Designer previewGUICreate("Form1", 512, 863, 745, -13, $WS_OVERLAPPEDWINDOW)GUISetBkColor(0xA0A0A4)$Image1 = GUICtrlCreatePic("TPicture", 16, 8, 481, 169)$Button1 = GUICtrlCreateButton("Tacoma", 24, 224, 85, 25)$Button2 = GUICtrlCreateButton("Portland Honda", 120, 224, 85, 25)$Button3 = GUICtrlCreateButton("Portland Hyundai", 216, 224, 85, 25)$Button4 = GUICtrlCreateButton("Vancouver", 312, 224, 85, 25)$Button5 = GUICtrlCreateButton("Alliance", 408, 224, 85, 25)$Button6 = GUICtrlCreateButton("Avon Lake", 24, 264, 85, 25)$Button7 = GUICtrlCreateButton("Cottage Grove", 120, 264, 85, 25)$Button8 = GUICtrlCreateButton("East Liberty", 216, 264, 85, 25)$Button9 = GUICtrlCreateButton("Lake Orion", 312, 264, 85, 25)$Button10 = GUICtrlCreateButton("Lincoln", 408, 264, 85, 25)$Button11 = GUICtrlCreateButton("Lordstown", 24, 304, 85, 25)$Button12 = GUICtrlCreateButton("Normal", 120, 304, 85, 25)$Button13 = GUICtrlCreateButton("Petersburg", 216, 304, 85, 25)$Button14 = GUICtrlCreateButton("Richmond", 312, 304, 85, 25)$Button15 = GUICtrlCreateButton("Spring Hill", 408, 304, 85, 25)$Button16 = GUICtrlCreateButton("Toledo", 24, 344, 85, 25)$Button17 = GUICtrlCreateButton("Woodhaven", 120, 344, 85, 25)$Button18 = GUICtrlCreateButton("New Boston", 216, 344, 85, 25)$Button19 = GUICtrlCreateButton("Newark", 312, 344, 85, 25)$Button20 = GUICtrlCreateButton("Wayne", 408, 344, 85, 25)$Button21 = GUICtrlCreateButton("Company Phone List", 64, 736, 125, 25)$Button22 = GUICtrlCreateButton("Remote Desktop", 200, 736, 125, 25)$Button23 = GUICtrlCreateButton("AP Checker", 336, 736, 125, 25)$Button24 = GUICtrlCreateButton("Exit", 200, 784, 125, 25)$Label2 = GUICtrlCreateLabel("September 2005", 432, 840, 78, 13)GUICtrlSetBkColor(-1, 0x020000)$ListView1 = GUICtrlCreateListView("", 24, 408, 474, 302, $LVS_ICON)GUISetState(@SW_SHOW)While 1   $msg = GuiGetMsg()  Select  Case $msg = $GUI_EVENT_CLOSE        ExitLoop    Case Else       ;;; EndSelectWEndExit


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


Stumpii
            
            
                Posted 
                
            
        
    
    
        


Stumpii
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 472
                            
                                
                            
                        
                        
                    
                
            
            
                

    
    
        
Mr. Stumpii
    
    

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            How about something like the following. Just edit for the correct file names. You should really use an array to hold the control IDs and use an INI file to hold the corresponding filename info, that way when you change the file name, you will not have to recomile the exe.

Also remember to put 

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstants.au3>
;Generated with Form Designer preview
GUICreate("Form1", 512, 863, 745, -13, $WS_OVERLAPPEDWINDOW)
GUISetBkColor(0xA0A0A4)
$Image1 = GUICtrlCreatePic("TPicture", 16, 8, 481, 169)
$Button1 = GUICtrlCreateButton("Tacoma", 24, 224, 85, 25)
$Button2 = GUICtrlCreateButton("Portland Honda", 120, 224, 85, 25)
$Button3 = GUICtrlCreateButton("Portland Hyundai", 216, 224, 85, 25)
$Button4 = GUICtrlCreateButton("Vancouver", 312, 224, 85, 25)
$Button5 = GUICtrlCreateButton("Alliance", 408, 224, 85, 25)
$Button6 = GUICtrlCreateButton("Avon Lake", 24, 264, 85, 25)
$Button7 = GUICtrlCreateButton("Cottage Grove", 120, 264, 85, 25)
$Button8 = GUICtrlCreateButton("East Liberty", 216, 264, 85, 25)
$Button9 = GUICtrlCreateButton("Lake Orion", 312, 264, 85, 25)
$Button10 = GUICtrlCreateButton("Lincoln", 408, 264, 85, 25)
$Button11 = GUICtrlCreateButton("Lordstown", 24, 304, 85, 25)
$Button12 = GUICtrlCreateButton("Normal", 120, 304, 85, 25)
$Button13 = GUICtrlCreateButton("Petersburg", 216, 304, 85, 25)
$Button14 = GUICtrlCreateButton("Richmond", 312, 304, 85, 25)
$Button15 = GUICtrlCreateButton("Spring Hill", 408, 304, 85, 25)
$Button16 = GUICtrlCreateButton("Toledo", 24, 344, 85, 25)
$Button17 = GUICtrlCreateButton("Woodhaven", 120, 344, 85, 25)
$Button18 = GUICtrlCreateButton("New Boston", 216, 344, 85, 25)
$Button19 = GUICtrlCreateButton("Newark", 312, 344, 85, 25)
$Button20 = GUICtrlCreateButton("Wayne", 408, 344, 85, 25)
$Button21 = GUICtrlCreateButton("Company Phone List", 64, 736, 125, 25)
$Button22 = GUICtrlCreateButton("Remote Desktop", 200, 736, 125, 25)
$Button23 = GUICtrlCreateButton("AP Checker", 336, 736, 125, 25)
$Button24 = GUICtrlCreateButton("Exit", 200, 784, 125, 25)
$Label2 = GUICtrlCreateLabel("September 2005", 432, 840, 78, 13)
GUICtrlSetBkColor(-1, 0x020000)
$ListView1 = GUICtrlCreateListView("", 24, 408, 474, 302, $LVS_ICON)
$myedit = GUICtrlCreateEdit("", 5, 5, 500, 200, -1)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button1
            _LoadFile("c:\autoexec.bat")
        Case $msg = $Button2
            _LoadFile("c:\autoexec.bat")
        Case $msg = $Button3
            _LoadFile("c:\autoexec.bat")
        Case $msg = $Button4
            _LoadFile("c:\autoexec.bat")
        Case $msg = $Button5
            _LoadFile("c:\autoexec.bat")
        Case $msg = $Button6
            _LoadFile("c:\autoexec.bat")
        Case Else
        ;;;
    EndSelect
WEnd
Exit

Func _LoadFile($Filename)
    
    $file = FileOpen($Filename, 0)
    
; Check if file opened for reading OK
    If $file <> - 1 Then
    ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            GUICtrlSetData($myedit, $line & @CRLF, 1)
        WEnd
    EndIf
    
    FileClose($file)
EndFunc  ;==>_LoadFile

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Link to comment
Share on other sites

Here is a little help with the control array. Note that I removed a bunch of buttons to make it easier. Have fun!

#include <GUIConstants.au3>

Local $aButtons[24]
Local $aFileNames[24]
$aFileNames[0] = "c:\autoexec.bat"
$aFileNames[1] = "c:\hpfr5550.log"
$aFileNames[2] = "c:\QuickFolder.qfl"

;Generated with Form Designer preview
GUICreate("Form1", 512, 863, 745, -13, $WS_OVERLAPPEDWINDOW)
GUISetBkColor(0xA0A0A4)
$Image1 = GUICtrlCreatePic("TPicture", 16, 8, 481, 169)
$aButtons[0] = GUICtrlCreateButton("Tacoma", 24, 224, 85, 25)
$aButtons[1] = GUICtrlCreateButton("Portland Honda", 120, 224, 85, 25)
$aButtons[2] = GUICtrlCreateButton("Portland Hyundai", 216, 224, 85, 25)

; ...

$Label2 = GUICtrlCreateLabel("September 2005", 432, 840, 78, 13)
GUICtrlSetBkColor(-1, 0x020000)
$ListView1 = GUICtrlCreateListView("", 24, 408, 474, 302, $LVS_ICON)
$myedit = GUICtrlCreateEdit("", 5, 5, 500, 200, -1)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = 0
        ; Continue
        Case Else
        ;;;
        ; Check button array
            For $iIndex = 0 To 23
                If $msg = $aButtons[$iIndex] Then
                    _LoadFile($aFileNames[$iIndex])
                EndIf
            Next
    EndSelect
WEnd
Exit

Func _LoadFile($Filename)
    
    $file = FileOpen($Filename, 0)
    
; Check if file opened for reading OK
    If $file <> - 1 Then
    ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            GUICtrlSetData($myedit, $line & @CRLF, 1)
        WEnd
    EndIf
    
    FileClose($file)
EndFunc  ;==>_LoadFile

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Link to comment
Share on other sites

One more quick question? Is the a way to clear the text of the box. maybe a control or somthing that is run before the next text file is loaded up? When I hit the first button it loads everything right when i hit the next button text remains and new text file is loaded. I just want the text file that goes with the correct button to show. Thanks again for the help!!

Link to comment
Share on other sites

One more quick question? Is the a way to clear the text of the box. maybe a control or somthing that is run before the next text file is loaded up? When I hit the first button it loads everything right when i hit the next button text remains and new text file is loaded. I just want the text file that goes with the correct button to show. Thanks again for the help!!

<{POST_SNAPBACK}>

If you use the GUICtrlSetData command without the last option, it will clear the field. So you can add GUICtrlSetData($myedit, "") before the while loop to clear the field before it starts, as shown below. Hope this is what you're looking for!

    ; Read in lines of text until the EOF is reached

    GUICtrlSetData($myedit, "")

        While 1

            $line = FileReadLine($file)

            If @error = -1 Then ExitLoop

            GUICtrlSetData($myedit, $line & @CRLF, 1)

        WEnd

Link to comment
Share on other sites

If you use the GUICtrlSetData command without the last option, it will clear the field. So you can add GUICtrlSetData($myedit, "") before the while loop to clear the field before it starts, as shown below. Hope this is what you're looking for!

<{POST_SNAPBACK}>

PERFECT!! Thanks so much!
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...