Sign in to follow this  
Followers 0
OrthodoxyUSA

Combo Box, Text File Read and Write

8 posts in this topic

#1 ·  Posted (edited)

Dear all,

Pardon my noobness,

I am wanting to design a combo box that will list files of a certain type from a directory. Then be able to select one of those files, and have it populate a group of editable boxes using each line from the text file and write these lines when I hit the save button or new button, whichever is appropriate.

In other words just be able to open a file, change things and save them on a per line basis... that's all.

This is where I am...

I just can't seem to wrap my head around how to do this.

(This is just a small piece of a much larger project, so I hope you don't find the coding confusing. IOW ~ You may see a lot of includes that are not needed just for this, and the variables may seem odd.)

; CSA Toolbox v1.0
#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ListviewConstants.au3>
#include <ProgressConstants.au3>
#include <file.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <Date.au3>
#include <StaticConstants.au3>
#include <GUIComboBox.au3>
#include <Constants.au3>
#Include <GuiComboBoxEx.au3>


#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

Global $filemenu, $exititem, $tab, $tab0, $tab1, $tab2, $tab3, $tab4, $tab5, $tab6

GuiCreate("CSA Toolbox v1.0", 600, 660, @DesktopWidth / 4 - 160, @DesktopHeight / 10 - 45, -1, 0x00000018)
GuiSetIcon(@SystemDir & "\wpabaln.exe", 0)
FileChangeDir("c:\csatoolbox")

; MENU
$filemenu = GuiCtrlCreateMenu("File")
$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

; TABS
$tab = GuiCtrlCreateTab(10, 0, 580, 630)


; TAB5
$tab5 = GuiCtrlCreateTabItem("Utilities")
; For creating files containing information needed about each server contacted by this program.
Local $T5iStyle = BitOR($TVS_EDITLABELS, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
local $T5Util, $T5msg, $T5Diff, $T5DBIP, $T5Save, $T5CRW, $T5FTP, $T5Addins, $T5Backup, $T5search, $T5filelist, $hItemT5, $T5selected, $T5fileopen, $T5FileText, $T5OpenFile
local $T5search[40] 
; local $T5selected[10]

; TREEVIEW
    $T5filelist = GuiCtrlCreateCombo("", 20, 53, 400, 150, $WS_VSCROLL)
   
    _GUICtrlTreeView_BeginUpdate($T5filelist)
    $T5Listfiles = _GUICtrlComboBox_AddDir($T5filelist, "c:\csatoolbox\*.utl")
    _GUICtrlTreeView_Sort($T5filelist)
    _GUICtrlTreeView_EndUpdate($T5filelist)

; LABELS
    GuiCtrlCreateLabel("Utility Number '000'.", 20, 205)
    GuiCtrlCreateLabel("Utility Name.", 150, 205)
    GuiCtrlCreateLabel("Time Difference 'in minutes'.", 20, 250)
    GuiCtrlCreateLabel("IP address of the 'DB' Server.",20, 300)
    GuiCtrlCreateLabel("IP address of the 'Term' Server.",180, 300)
    GuiCtrlCreateLabel("Well known 'CRW' folder.",20, 402)
    GuiCtrlCreateLabel("Well known 'FTP' folder.",20, 452)
    GuiCtrlCreateLabel("Well known 'AddIns' folder.",20, 502)
    GuiCtrlCreateLabel("Well known 'Backup' folder.",20, 552)
    GuiCtrlCreateLabel("Select a Utility File to modify.   (No leading '0' in file names.)",20, 35)
    
; INPUT (Type in the Utility Number)
   $T5Util = GuiCtrlCreateInput("000", 20, 223, 100, 20)
   $msg0 = 0
    
; INPUT (Type in the Utility Name)
   $T5Util = GuiCtrlCreateInput("", 150, 223, 200, 20)
   $msg0 = 0

; INPUT (Type in the difference in time 'in minutes'.)
   $T5Diff = GuiCtrlCreateInput("0", 20, 270, 100, 20)
   $msg0 = 0
   
; INPUT (Type in the IP for the 'DB Server'.)
   $T5DBIP = GuiCtrlCreateInput("10.0.0.0", 20, 324, 100, 20)
   $msg0 = 0
   
; INPUT (Type in the IP for the 'TERM Server'.)
   $T5TERMIP = GuiCtrlCreateInput("10.0.0.0", 180, 324, 100, 20)
   $msg0 = 0
   
; INPUT (Type in the 'well known CRW folder'.)
   $T5CRW = GuiCtrlCreateInput("c:\crw", 20, 424, 400, 20)
   $msg0 = 0
   
; INPUT (Type in the 'well known FTP folder'.)
   $T5FTP = GuiCtrlCreateInput("c:\Inetpub\ftproot", 20, 474, 400, 20)
   $msg0 = 0
   
; INPUT (Type in the 'well known AddIns folder'.)
   $T5Addins = GuiCtrlCreateInput("c:\Program Files\Microsoft Dynamics\GP\Addins", 20, 524, 400, 20)
   $msg0 = 0   

; INPUT (Type in the 'well known Backup folder'.)
   $T5Backup = GuiCtrlCreateInput("c:\Backup", 20, 574, 400, 20)
   $msg0 = 0  

; BUTTONS
    $T5New  = GuiCtrlCreateButton("New",  430, 53, 100, 20)

$T5Save = GuiCtrlCreateButton("Save", 430, 80, 100, 20)
GUICtrlCreateTabItem(""); end tabitem definition
; END TABS

GUISetState()   


; MAIN ROUTINE
While 1
    $msg0 = GUIGetMsg()         
    Select
            Case $msg0 = $GUI_EVENT_CLOSE Or $msg0 = $exititem
                ExitLoop
                        
            Case $T5filelist = _GUICtrlComboBoxEx_GetItemText($T5filelist, $T5Listfiles, $T5FileText)
                
                If @error = -1 Then ContinueLoop
                $T5OpenFile = ("c:\csatoolbox\"&$T5FileText)
                $T5Util = FileReadLine($T5OpenFile,1)
                $T5Diff = FileReadLine($T5OpenFile,2)
                $T5DBIP = FileReadLine($T5OpenFile,3)
                $T5TERMIP = FileReadLine($T5OpenFile,4)
                $T5CRW = FileReadLine($T5OpenFile,5)
                $T5FTP = FileReadLine($T5OpenFile,6)
                $T5Addins = FileReadLine($T5OpenFile,7)
                $T5Backup = FileReadLine($T5OpenFile,8)
    EndSelect
WEnd

Currently when I select a file from the list nothing changes.

Thanks for all your help in advance!

Forgive me...

Paul

Edited by OrthodoxyUSA

Share this post


Link to post
Share on other sites



Maybe something like this

just concept!

While 1
    $msg0 = GUIGetMsg() 
               Select
            Case $msg0 = $GUI_EVENT_CLOSE Or $msg0 = $exititem
                ExitLoop
                                    Case $msg0 = $T5filelist
;~              _GUICtrlComboBoxEx_GetItemText($T5filelist, $T5Listfiles, $T5FileText)
;~            If @error = -1 Then ContinueLoop
                $T5FileText = GUICtrlRead($T5filelist)
                $T5OpenFile = ("c:\csatoolbox\"&$T5FileText)
                $T5Util = FileReadLine($T5OpenFile,1)
                $T5Diff = FileReadLine($T5OpenFile,2)
                $T5DBIP = FileReadLine($T5OpenFile,3)
                $T5TERMIP = FileReadLine($T5OpenFile,4)
                $T5CRW = FileReadLine($T5OpenFile,5)
                $T5FTP = FileReadLine($T5OpenFile,6)
                $T5Addins = FileReadLine($T5OpenFile,7)
                $T5Backup = FileReadLine($T5OpenFile,8)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

Maybe something like this

just concept!

While 1
    $msg0 = GUIGetMsg() 
               Select
            Case $msg0 = $GUI_EVENT_CLOSE Or $msg0 = $exititem
                ExitLoop
                                    Case $msg0 = $T5filelist
;~              _GUICtrlComboBoxEx_GetItemText($T5filelist, $T5Listfiles, $T5FileText)
;~            If @error = -1 Then ContinueLoop
                $T5FileText = GUICtrlRead($T5filelist)
                $T5OpenFile = ("c:\csatoolbox\"&$T5FileText)
                $T5Util = FileReadLine($T5OpenFile,1)
                $T5Diff = FileReadLine($T5OpenFile,2)
                $T5DBIP = FileReadLine($T5OpenFile,3)
                $T5TERMIP = FileReadLine($T5OpenFile,4)
                $T5CRW = FileReadLine($T5OpenFile,5)
                $T5FTP = FileReadLine($T5OpenFile,6)
                $T5Addins = FileReadLine($T5OpenFile,7)
                $T5Backup = FileReadLine($T5OpenFile,8)
    EndSelect
WEnd

Hmm... nothing seems to have changed.

Thanks though.

Share this post


Link to post
Share on other sites

I'm almost certain that I'm going about this all wrong.

Change the attached file to 27.utl and put it in a folder called c:\csatoolbox.

If you run the script "as is" you should see what it is that I'm after.

Thanks much!

Paul

27.txt

Share this post


Link to post
Share on other sites

Doh ... messy code dude ...

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ListviewConstants.au3>
#include <ProgressConstants.au3>
#include <file.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <Date.au3>
#include <StaticConstants.au3>
#include <GUIComboBox.au3>
#include <Constants.au3>
#Include <GuiComboBoxEx.au3>


#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

Global $filemenu, $exititem, $tab, $tab0, $tab1, $tab2, $tab3, $tab4, $tab5, $tab6

GuiCreate("CSA Toolbox v1.0", 600, 660, @DesktopWidth / 4 - 160, @DesktopHeight / 10 - 45, -1, 0x00000018)
GuiSetIcon(@SystemDir & "\wpabaln.exe", 0)
FileChangeDir("c:\csatoolbox")

; MENU
$filemenu = GuiCtrlCreateMenu("File")
$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

; TABS
$tab = GuiCtrlCreateTab(10, 0, 580, 630)


; TAB5
$tab5 = GuiCtrlCreateTabItem("Utilities")
; For creating files containing information needed about each server contacted by this program.
Local $T5iStyle = BitOR($TVS_EDITLABELS, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
local $T5Util, $T5msg, $T5Diff, $T5DBIP, $T5Save, $T5CRW, $T5FTP, $T5Addins, $T5Backup, $T5search, $T5filelist, $hItemT5, $T5selected, $T5fileopen, $T5FileText, $T5OpenFile
local $T5search[40] 
; local $T5selected[10]

; TREEVIEW
    $T5filelist = GuiCtrlCreateCombo("", 20, 53, 400, 150, $WS_VSCROLL)
    $T5Listfiles = _GUICtrlComboBox_AddDir($T5filelist, "c:\csatoolbox\*.utl")

; LABELS
    GuiCtrlCreateLabel("Utility Number '000'.", 20, 205)
    GuiCtrlCreateLabel("Utility Name.", 150, 205)
    GuiCtrlCreateLabel("Time Difference 'in minutes'.", 20, 250)
    GuiCtrlCreateLabel("IP address of the 'DB' Server.",20, 300)
    GuiCtrlCreateLabel("IP address of the 'Term' Server.",180, 300)
    GuiCtrlCreateLabel("Well known 'CRW' folder.",20, 402)
    GuiCtrlCreateLabel("Well known 'FTP' folder.",20, 452)
    GuiCtrlCreateLabel("Well known 'AddIns' folder.",20, 502)
    GuiCtrlCreateLabel("Well known 'Backup' folder.",20, 552)
    GuiCtrlCreateLabel("Select a Utility File to modify.   (No leading '0' in file names.)",20, 35)
    
; INPUT (Type in the Utility Number)
   $T5Util = GuiCtrlCreateInput("000", 20, 223, 100, 20)
; INPUT (Type in the Utility Name)
   $T5Util = GuiCtrlCreateInput("", 150, 223, 200, 20)
; INPUT (Type in the difference in time 'in minutes'.)
   $T5Diff = GuiCtrlCreateInput("0", 20, 270, 100, 20)
; INPUT (Type in the IP for the 'DB Server'.)
   $T5DBIP = GuiCtrlCreateInput("10.0.0.0", 20, 324, 100, 20)
; INPUT (Type in the IP for the 'TERM Server'.)
   $T5TERMIP = GuiCtrlCreateInput("10.0.0.0", 180, 324, 100, 20)
; INPUT (Type in the 'well known CRW folder'.)
   $T5CRW = GuiCtrlCreateInput("c:\crw", 20, 424, 400, 20)
; INPUT (Type in the 'well known FTP folder'.)
   $T5FTP = GuiCtrlCreateInput("c:\Inetpub\ftproot", 20, 474, 400, 20)
; INPUT (Type in the 'well known AddIns folder'.)
   $T5Addins = GuiCtrlCreateInput("c:\Program Files\Microsoft Dynamics\GP\Addins", 20, 524, 400, 20)  
; INPUT (Type in the 'well known Backup folder'.)
   $T5Backup = GuiCtrlCreateInput("c:\Backup", 20, 574, 400, 20) 
; BUTTONS
    $T5New  = GuiCtrlCreateButton("New",  430, 53, 100, 20)
    $T5Save = GuiCtrlCreateButton("Save", 430, 80, 100, 20)
    GUICtrlCreateTabItem(""); end tabitem definition
; END TABS

GUISetState()     


; MAIN ROUTINE
While 1
    $msg0 = GUIGetMsg()            
    Select
            Case $msg0 = $GUI_EVENT_CLOSE Or $msg0 = $exititem
                ExitLoop
                        
            Case $T5filelist
                $T5OpenFile = FileOpen("c:\csatoolbox\"&GUICtrlRead($T5filelist), 0)
                GUICtrlSetData($T5Util, FileReadLine($T5OpenFile,1))
                GUICtrlSetData($T5Diff, FileReadLine($T5OpenFile,2))
                ;change all that follows using my 2 lines above
                $T5DBIP = FileReadLine($T5OpenFile,3)
                $T5TERMIP = FileReadLine($T5OpenFile,4)
                $T5CRW = FileReadLine($T5OpenFile,5)
                $T5FTP = FileReadLine($T5OpenFile,6)
                $T5Addins = FileReadLine($T5OpenFile,7)
                $T5Backup = FileReadLine($T5OpenFile,8)
                ;----- till here ----
                FileClose($T5OpenFile)
    EndSelect
WEnd

Pay attention to your main loop, I have changed the code for 2 input boxes. Try to understand what I did and why.

After that change the code on the next lines accordingly.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Doh ... messy code dude ...

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ListviewConstants.au3>
#include <ProgressConstants.au3>
#include <file.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <Date.au3>
#include <StaticConstants.au3>
#include <GUIComboBox.au3>
#include <Constants.au3>
#Include <GuiComboBoxEx.au3>


#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

Global $filemenu, $exititem, $tab, $tab0, $tab1, $tab2, $tab3, $tab4, $tab5, $tab6

GuiCreate("CSA Toolbox v1.0", 600, 660, @DesktopWidth / 4 - 160, @DesktopHeight / 10 - 45, -1, 0x00000018)
GuiSetIcon(@SystemDir & "\wpabaln.exe", 0)
FileChangeDir("c:\csatoolbox")

; MENU
$filemenu = GuiCtrlCreateMenu("File")
$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

; TABS
$tab = GuiCtrlCreateTab(10, 0, 580, 630)


; TAB5
$tab5 = GuiCtrlCreateTabItem("Utilities")
; For creating files containing information needed about each server contacted by this program.
Local $T5iStyle = BitOR($TVS_EDITLABELS, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
local $T5Util, $T5msg, $T5Diff, $T5DBIP, $T5Save, $T5CRW, $T5FTP, $T5Addins, $T5Backup, $T5search, $T5filelist, $hItemT5, $T5selected, $T5fileopen, $T5FileText, $T5OpenFile
local $T5search[40] 
; local $T5selected[10]

; TREEVIEW
    $T5filelist = GuiCtrlCreateCombo("", 20, 53, 400, 150, $WS_VSCROLL)
    $T5Listfiles = _GUICtrlComboBox_AddDir($T5filelist, "c:\csatoolbox\*.utl")

; LABELS
    GuiCtrlCreateLabel("Utility Number '000'.", 20, 205)
    GuiCtrlCreateLabel("Utility Name.", 150, 205)
    GuiCtrlCreateLabel("Time Difference 'in minutes'.", 20, 250)
    GuiCtrlCreateLabel("IP address of the 'DB' Server.",20, 300)
    GuiCtrlCreateLabel("IP address of the 'Term' Server.",180, 300)
    GuiCtrlCreateLabel("Well known 'CRW' folder.",20, 402)
    GuiCtrlCreateLabel("Well known 'FTP' folder.",20, 452)
    GuiCtrlCreateLabel("Well known 'AddIns' folder.",20, 502)
    GuiCtrlCreateLabel("Well known 'Backup' folder.",20, 552)
    GuiCtrlCreateLabel("Select a Utility File to modify.   (No leading '0' in file names.)",20, 35)
    
; INPUT (Type in the Utility Number)
   $T5Util = GuiCtrlCreateInput("000", 20, 223, 100, 20)
; INPUT (Type in the Utility Name)
   $T5Util = GuiCtrlCreateInput("", 150, 223, 200, 20)
; INPUT (Type in the difference in time 'in minutes'.)
   $T5Diff = GuiCtrlCreateInput("0", 20, 270, 100, 20)
; INPUT (Type in the IP for the 'DB Server'.)
   $T5DBIP = GuiCtrlCreateInput("10.0.0.0", 20, 324, 100, 20)
; INPUT (Type in the IP for the 'TERM Server'.)
   $T5TERMIP = GuiCtrlCreateInput("10.0.0.0", 180, 324, 100, 20)
; INPUT (Type in the 'well known CRW folder'.)
   $T5CRW = GuiCtrlCreateInput("c:\crw", 20, 424, 400, 20)
; INPUT (Type in the 'well known FTP folder'.)
   $T5FTP = GuiCtrlCreateInput("c:\Inetpub\ftproot", 20, 474, 400, 20)
; INPUT (Type in the 'well known AddIns folder'.)
   $T5Addins = GuiCtrlCreateInput("c:\Program Files\Microsoft Dynamics\GP\Addins", 20, 524, 400, 20)  
; INPUT (Type in the 'well known Backup folder'.)
   $T5Backup = GuiCtrlCreateInput("c:\Backup", 20, 574, 400, 20) 
; BUTTONS
    $T5New  = GuiCtrlCreateButton("New",  430, 53, 100, 20)
    $T5Save = GuiCtrlCreateButton("Save", 430, 80, 100, 20)
    GUICtrlCreateTabItem(""); end tabitem definition
; END TABS

GUISetState()     


; MAIN ROUTINE
While 1
    $msg0 = GUIGetMsg()            
    Select
            Case $msg0 = $GUI_EVENT_CLOSE Or $msg0 = $exititem
                ExitLoop
                        
            Case $T5filelist
                $T5OpenFile = FileOpen("c:\csatoolbox\"&GUICtrlRead($T5filelist), 0)
                GUICtrlSetData($T5Util, FileReadLine($T5OpenFile,1))
                GUICtrlSetData($T5Diff, FileReadLine($T5OpenFile,2))
                ;change all that follows using my 2 lines above
                $T5DBIP = FileReadLine($T5OpenFile,3)
                $T5TERMIP = FileReadLine($T5OpenFile,4)
                $T5CRW = FileReadLine($T5OpenFile,5)
                $T5FTP = FileReadLine($T5OpenFile,6)
                $T5Addins = FileReadLine($T5OpenFile,7)
                $T5Backup = FileReadLine($T5OpenFile,8)
                ;----- till here ----
                FileClose($T5OpenFile)
    EndSelect
WEnd

Pay attention to your main loop, I have changed the code for 2 input boxes. Try to understand what I did and why.

After that change the code on the next lines accordingly.

Thanks so much from down under! (didn't know I'd have to go around the world to get a solution...)

Forgive my messy code... It's not what I do for a living.

Paul

Share this post


Link to post
Share on other sites

just a quick observation you have 2. $T5Util

; INPUT (Type in the Utility Number)

$T5Util = GuiCtrlCreateInput("000", 20, 223, 100, 20)

; INPUT (Type in the Utility Name)

$T5Util = GuiCtrlCreateInput("", 150, 223, 200, 20)

Share this post


Link to post
Share on other sites

No worries ;) It happens to the best of us ... sometime :D


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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