Jump to content

File IO Help


Recommended Posts

I have a few questions. I've migrated to AutoIt from VB and its very similar and very different in ways. I have made this program that will help me keep track of releases that I do at work.

Here is what I need it to do.

1. Fill in information in Text boxes and combo boxes and click save.

2. Saves all information into a file.(I don't care how or what kind)

3. If Any box is empty EXCEPT NOTES then Msg box with "Fill in all fields"

3. If you fill in just a few boxes then click search then it will bring up anything in that file that matches all of the things you put in EXCEPT DATE.

4. If more then 1 exist use a 2D grid array and show all matching.

5. Clear obviously clears all boxes.

I've tried a few ways with arrays and such that I've found on other forums but they don't seem to work for what I need. I can import the entire CSV.csv file but not put them into the individual boxes and combos.

;Release spreadsheet update
;Adam Fowler
;10-26-2007
;GUI interface to update spreadsheet for release Process

#include <GuiConstants.au3>
#include <array.au3>


; GUI
GuiCreate("Release Status update", 280, 400)
GuiSetIcon(@SystemDir & "\clipbrd.exe", 0)

; LABEL Environment
GuiCtrlCreateLabel("Environment", 10, 15, 120, 15)
; COMBO Environment
GuiCtrlCreatecombo("", 10, 30, 120, 100)
GUICtrlSetData(-1,"ENG|SaturnIDMS|WPS Internal|Legacy","Environment")

; LABEL Developer
GuiCtrlCreateLabel("Developer", 150, 15, 120, 15)
; COMBO Developer
GuiCtrlCreatecombo("", 150, 30, 120, 100)
GUICtrlSetData(-1,"Pramer|Fryman|Mathes|Flaute|Schmidt|Carter|Kirchner|Hoeve|Carter|Dahlinghaus","Developer")

; LABEL Deployer
GuiCtrlCreateLabel("Deployer", 150, 65, 120, 15)
; COMBO Deployer
GuiCtrlCreatecombo("", 150, 80, 120, 100)
GUICtrlSetData(-1,"Strawser|Schmidt|Fowler|Mathes|Denslow","Deployer")

; LABEL Status
GuiCtrlCreateLabel("Status", 150, 115, 120, 15)
; COMBO Production Deploy status
GuiCtrlCreatecombo("", 150, 130, 120, 100)
GUICtrlSetData(-1,"Canceled|Complete|Open|Successful","Status")

; LABEL Area
GuiCtrlCreateLabel("Area", 10, 65, 120, 15)
; COMBO Area
GuiCtrlCreatecombo("", 10, 80, 120, 100)
GUICtrlSetData(-1,"CM|eBusiness|Internal","Area")

; LABEL Application
GuiCtrlCreateLabel("Application", 10, 115, 120, 15)
; COMBO Application
GuiCtrlCreatecombo("", 10, 130, 120, 100)
GUICtrlSetData(-1,"AutoMark|BASIS|BPM|CCR|CM|CommonCust|CTI|CustomerFirst|ENG|eSupport|FADD|FastTrac|FICO|PriceBook


|ReySource|RUOnlone","Application")

; Name
GuiCtrlCreateInput("", 10, 180, 120, 20)
; LABEL Name
GuiCtrlCreateLabel("Name", 10, 165, 120, 15)

; Notes
GuiCtrlCreateInput("", 150, 180, 120, 20)
; LABEL Notes
GuiCtrlCreateLabel("Notes", 150, 165, 120, 15)

; Number
GuiCtrlCreateInput("", 10, 230, 120, 20)
GuiCtrlCreateLabel("Version", 10, 215, 120, 15)

; Test
GuiCtrlCreateDate("", 10, 270, 200, 20)
GuiCtrlCreateLabel("Test", 220, 270, 200, 20)

; Prod
GuiCtrlCreateDate("", 10, 310, 200, 20)
GuiCtrlCreateLabel("Prod", 220, 310, 200, 20)

;Save
$Save = GUICtrlCreateButton("Save", 10, 350, 50)
GUICtrlSetState(-1, $GUI_FOCUS); the focus is on this button
;Search
$Search = GUICtrlCreateButton("Search", 80, 350, 50)
;Clear
$Clear = GUICtrlCreateButton("Clear", 150, 350, 50)
;Exit
$Exit = GUICtrlCreateButton("Exit", 220, 350, 50)

Global $sString, $aLineArray, $aSplit, $nCount
$sString = FileRead("C:\Documents and Settings\FowlerAd\Desktop\CSV.csv")

;Create an array of each line
$aLineArray = StringSplit(StringStripCR($sString), @LF)


; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
    While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit;Click Exit
            Exit
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Save;click Save
            MsgBox(0, "Click","You clicked Save!")
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Search;click Search
            MsgBox(0, "Click", "You clicked Search!")
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Clear; Click clear
            MsgBox(0, "Click", "You clicked Clear!")
    EndSelect
WEnd

GUIDelete()

Exit
WEnd
Edited by Pantera975
Link to comment
Share on other sites

2. Saves all information into a file.(I don't care how or what kind)

Well, you're not going to get very far until you decide what kind. You seem to use a .csv. Is the format of your .csv solid: every first line is column headers and all following lines have the same number of columns, all comma separated? If you already know how many colums, then creating a 2D array of the .csv will be easy. If you don't know how many, but they will all at least be the same as the first line, then creating the 2D array will be easy. If you really don't know or care, then quit right now.

; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
    While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit;Click Exit
            Exit
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Save;click Save
            MsgBox(0, "Click","You clicked Save!")
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Search;click Search
            MsgBox(0, "Click", "You clicked Search!")
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Clear; Click clear
            MsgBox(0, "Click", "You clicked Clear!")
    EndSelect
WEnd
Why are you testing for $GUI_Event_Close over and over again?

I personally prefer GuiOnEventMode, but if you must have a message loop:

; GUI MESSAGE LOOP
GuiSetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Save ; click Save
            MsgBox(0, "Click","You clicked Save!")
        Case $Search ; click Search
            MsgBox(0, "Click", "You clicked Search!")
        Case $Clear ; Click clear
            MsgBox(0, "Click", "You clicked Clear!")
    EndSwitch
WEnd

The first one in the list of functional parts is save. OK. Save how? Have you decided on the format yet?

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I guess you mis understood when I said I don't care. I used a .CSV just as a trial. I don't know what will be easiest. As of right now the information is in a .xls

Area|Application|Name|Number|Test date|Production Date|Developer|Deployer|Status|Notes

**There will not always be notes** The reason I don't care how the file is saved is because I wanted to make it easier on anyone who helped me. If they think Saving as .Xls or .Dat or .CSV would work better I was leaving that option available. Idealy I would like it to read from the .xls

The first one in the list of functional parts is save. OK. Save how? Have you decided on the format yet?

I would like it to save to a .xls in the order described above. But if someone neglects to put in anything EXCEPT NOTES AND PROD DATE then msg box would tell them to complete all fields

Also can you make Date fields blank to start? instead of showing todays date?

Edited by Pantera975
Link to comment
Share on other sites

I guess you mis understood when I said I don't care. I used a .CSV just as a trial. I don't know what will be easiest. As of right now the information is in a .xls

Area|Application|Name|Number|Test date|Production Date|Developer|Deployer|Status|Notes

**There will not always be notes** The reason I don't care how the file is saved is because I wanted to make it easier on anyone who helped me. If they think Saving as .Xls or .Dat or .CSV would work better I was leaving that option available. Idealy I would like it to read from the .xls

I would like it to save to a .xls in the order described above. But if someone neglects to put in anything EXCEPT NOTES AND PROD DATE then msg box would tell them to complete all fields

It's your script. This is not a script writing service. Pick a file format, and start coding towards it. If you get stuck, post your code and you'll get lots of help with your code. If you need someone to design and code it for you, see the Rent-A-Coder link in my sig.

You can use MS Excel COM objects with the ExcelCOM_UDF.au3 UDF by locodarwin. It has functions to read data directly into a 2D array.

Also can you make Date fields blank to start? instead of showing todays date?

I don't think you can. The date could be made something obviously not yet right, like 1900/01/01, before the GUI is presented. Perhaps to get the blank visual effect, you could create and empty Combo control, and when it gets opened your script would replace it with a Date control.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Tahnks for the Excel stuff. I used what I could.. Still stuck

;Release spreadsheet update
;Adam Fowler
;10-26-2007
;GUI interface to update spreadsheet for release Process

#include <GuiConstants.au3>
#include <array.au3>
#include <ExcelCOM_UDF.au3> ; Include the collection


; GUI
GuiCreate("Release Status update", 280, 400)
GuiSetIcon(@SystemDir & "\clipbrd.exe", 0)

; LABEL Environment
GuiCtrlCreateLabel("Environment", 10, 15, 120, 15)
; COMBO Environment
$Environment = GuiCtrlCreatecombo("", 10, 30, 120, 100)
GUICtrlSetData(-1,"ENG|SaturnIDMS|WPS Internal|Legacy","Environment")

; LABEL Developer
GuiCtrlCreateLabel("Developer", 150, 15, 120, 15)
; COMBO Developer
$Developer = GuiCtrlCreatecombo("", 150, 30, 120, 100)
GUICtrlSetData(-1,"Pramer|Fryman|Mathes|Flaute|Schmidt|Carter|Kirchner|Hoeve|Carter|Dahlinghaus","Developer")

; LABEL Deployer
GuiCtrlCreateLabel("Deployer", 150, 65, 120, 15)
; COMBO Deployer
$Deployer = GuiCtrlCreatecombo("", 150, 80, 120, 100)
GUICtrlSetData(-1,"Strawser|Schmidt|Fowler|Mathes|Denslow","Deployer")

; LABEL Status
GuiCtrlCreateLabel("Status", 150, 115, 120, 15)
; COMBO Production Deploy status
$Status = GuiCtrlCreatecombo("", 150, 130, 120, 100)
GUICtrlSetData(-1,"Canceled|Complete|Open|Successful","Status")

; LABEL Area
GuiCtrlCreateLabel("Area", 10, 65, 120, 15)
; COMBO Area
$Area = GuiCtrlCreatecombo("", 10, 80, 120, 100)
GUICtrlSetData(-1,"CM|eBusiness|Internal","Area")

; LABEL Application
GuiCtrlCreateLabel("Application", 10, 115, 120, 15)
; COMBO Application
$Application = GuiCtrlCreatecombo("", 10, 130, 120, 100)
GUICtrlSetData(-1,"AutoMark|BASIS|BPM|CCR|CM|CommonCust|CTI|CustomerFirst|ENG|eSupport|FADD|FastTrac|FICO|PriceBook

|ReySource|RUOnlone","Application")

; Name
$Name = GuiCtrlCreateInput("", 10, 180, 120, 20)
; LABEL Name
GuiCtrlCreateLabel("Name", 10, 165, 120, 15)

; Notes
$Notes = GuiCtrlCreateInput("", 150, 180, 120, 20)
; LABEL Notes
GuiCtrlCreateLabel("Notes", 150, 165, 120, 15)

; Number
$Number = GuiCtrlCreateInput("", 10, 230, 120, 20)
GuiCtrlCreateLabel("Version", 10, 215, 120, 15)

; Test
$TestDate = GuiCtrlCreateDate("", 10, 270, 200, 20)
GuiCtrlCreateLabel("Test", 220, 270, 200, 20)

; Prod
$ProdDate = GuiCtrlCreateDate("", 10, 310, 200, 20)
GuiCtrlCreateLabel("Prod", 220, 310, 200, 20)

;Save
$Save = GUICtrlCreateButton("Save", 10, 350, 50)
GUICtrlSetState(-1, $GUI_FOCUS); the focus is on this button
;Search
$Search = GUICtrlCreateButton("Search", 80, 350, 50)
;Clear
$Clear = GUICtrlCreateButton("Clear", 150, 350, 50)
;Exit
$Exit = GUICtrlCreateButton("Exit", 220, 350, 50)

Global $sString, $aLineArray, $aSplit, $nCount
$sString = FileRead("C:\Documents and Settings\FowlerAd\Desktop\CSV.csv")

;Create an array of each line
$aLineArray = StringSplit(StringStripCR($sString), @LF)


; GUI MESSAGE LOOP
GuiSetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
[b]     Case $Save; click Save
            
        ; Open new book, make it invisible
Local $oExcel = _ExcelBookNew(0)

        _ExcelWriteCell GUICtrlRead($Developer),1,1)

; Now we save it into the directory; overwrite existing file if necessary
_ExcelBookSaveAs($oExcel, "" & "C:\Documents and Settings\FowlerAd\Desktop\temp78.xls", "xls", 0, 1)

; And finally we close out
_ExcelBookClose($oExcel)[/b]
       
       Case $Search; click Search
            MsgBox(0, "Click", "You clicked Search!")
        Case $Clear; Click clear
            MsgBox(0, "Click", "You clicked Clear!")
        Case $Exit; Click Exit
            Exit
    EndSwitch
WEnd

The bold part.. makes a new book and ATTEMPTS to save the value of $Developer into it... What I need is to open C:\Documents and Settings\FowlerAd\Desktop\temp78.xls and put the data in the next available lin e in the next available line in the right order $Area|$Application|$Name|$Number|$TestDate|$ProdDate|$Developer|$Deployer|$Status|$Notes

Link to comment
Share on other sites

I got alot done on the code... Thanks for the excel info PsaltyDS I am having new problems now. I need the code to write the info to next open row. (If the top 354 rows have something in them then go to row 355)

;Release spreadsheet update
;Adam Fowler
;10-26-2007
;GUI interface to update spreadsheet for release Process

#include <GuiConstants.au3>
#include <array.au3>
#include <ExcelCOM_UDF.au3> ; Include the collection


; GUI
GuiCreate("Release Status update", 280, 400)
GuiSetIcon(@SystemDir & "\clipbrd.exe", 0)

; LABEL Environment
GuiCtrlCreateLabel("Environment", 10, 15, 120, 15)
; COMBO Environment
$Environment = GuiCtrlCreatecombo("", 10, 30, 120, 100)
GUICtrlSetData(-1,"ENG|SaturnIDMS|WPS Internal|Legacy","Environment")

; LABEL Developer
GuiCtrlCreateLabel("Developer", 150, 15, 120, 15)
; COMBO Developer
$Developer = GuiCtrlCreatecombo("", 150, 30, 120, 100)
GUICtrlSetData(-1,"Pramer|Fryman|Mathes|Flaute|Schmidt|Carter|Kirchner|Hoeve|Carter|Dahlinghaus","Developer")

; LABEL Deployer
GuiCtrlCreateLabel("Deployer", 150, 65, 120, 15)
; COMBO Deployer
$Deployer = GuiCtrlCreatecombo("", 150, 80, 120, 100)
GUICtrlSetData(-1,"Strawser|Schmidt|Fowler|Mathes|Denslow","Deployer")

; LABEL Status
GuiCtrlCreateLabel("Status", 150, 115, 120, 15)
; COMBO Production Deploy status
$Status = GuiCtrlCreatecombo("", 150, 130, 120, 100)
GUICtrlSetData(-1,"Canceled|Complete|Open|Successful","Status")

; LABEL Area
GuiCtrlCreateLabel("Area", 10, 65, 120, 15)
; COMBO Area
$Area = GuiCtrlCreatecombo("", 10, 80, 120, 100)
GUICtrlSetData(-1,"CM|eBusiness|Internal","Area")

; LABEL Application
GuiCtrlCreateLabel("Application", 10, 115, 120, 15)
; COMBO Application
$Application = GuiCtrlCreatecombo("", 10, 130, 120, 100)
GUICtrlSetData(-1,"AutoMark|BASIS|BPM|CCR|CM|CommonCust|CTI|CustomerFirst|ENG|eSupport|FADD|FastTrac|FICO|PriceBook

|ReySource|RUOnlone","Application")

; Name
$Name = GuiCtrlCreateInput("", 10, 180, 120, 20)
; LABEL Name
GuiCtrlCreateLabel("Name", 10, 165, 120, 15)

; Notes
$Notes = GuiCtrlCreateInput("", 150, 180, 120, 20)
; LABEL Notes
GuiCtrlCreateLabel("Notes", 150, 165, 120, 15)

; Number
$Number = GuiCtrlCreateInput("", 10, 230, 120, 20)
GuiCtrlCreateLabel("Version", 10, 215, 120, 15)

; Test
$TestDate = GuiCtrlCreateDate("", 10, 270, 200, 20)
GuiCtrlCreateLabel("Test", 220, 270, 25, 20)

; Prod
$ProdDate = GuiCtrlCreateDate("", 10, 310, 200, 20)
GuiCtrlCreateLabel("Prod", 220, 310, 25, 20)

;Radio Buttons
$Testradio = GuiCtrlCreateRadio("", 250, 260, 80)
GuiCtrlSetState(-1, $GUI_CHECKED)
$Prodradio = GuiCtrlCreateRadio("", 250, 300, 80)

;Save
$Save = GUICtrlCreateButton("Save", 10, 350, 50)
GUICtrlSetState(-1, $GUI_FOCUS); the focus is on this button
;Search
$Search = GUICtrlCreateButton("Search", 80, 350, 50)
;Clear
$Clear = GUICtrlCreateButton("Clear", 150, 350, 50)
;Exit
$Exit = GUICtrlCreateButton("Exit", 220, 350, 50)

Global $sString, $aLineArray, $aSplit, $nCount
$sString = FileRead("C:\Documents and Settings\FowlerAd\Desktop\CSV.csv")

;Create an array of each line
$aLineArray = StringSplit(StringStripCR($sString), @LF)


; GUI MESSAGE LOOP
GuiSetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Save; click Save

    If GUICtrlRead($Area) = "" then
        MsgBox(0, "Error", "Please fill out Area")
    EndIf

    [b] ; Open new book, make it invisible
Local $oExcel = _ExcelBookOpen("C:\Documents and Settings\FowlerAd\Desktop\temp78.xls",0,False);1 = visable 0 = invisable

        _ExcelWriteCell($oExcel, GUICtrlRead($Environment),2, 1)
        _ExcelWriteCell($oExcel, GUICtrlRead($Area), 2, 2)
        _ExcelWriteCell($oExcel, GUICtrlRead($Application), 2, 3)
        _ExcelWriteCell($oExcel, GUICtrlRead($Name), 2, 4)
        _ExcelWriteCell($oExcel, GUICtrlRead($Number), 2, 5)
            If GUICtrlRead($Testradio) = 1 Then
        _ExcelWriteCell($oExcel, GUICtrlRead($TestDate), 2, 6)
            EndIf
            If GUICtrlRead($Prodradio) = 1 Then
        _ExcelWriteCell($oExcel, GUICtrlRead($ProdDate), 2, 7)
            EndIf
        _ExcelWriteCell($oExcel, GUICtrlRead($Developer), 2, 8)
        _ExcelWriteCell($oExcel, GUICtrlRead($Deployer), 2, 9)
        _ExcelWriteCell($oExcel, GUICtrlRead($Status), 2, 10)
        _ExcelWriteCell($oExcel, GUICtrlRead($Notes), 2, 11)

; Now we save it into the directory; overwrite existing file if necessary
_ExcelBookSaveAs($oExcel, "" & "C:\Documents and Settings\FowlerAd\Desktop\temp78.xls", "xls", 0, 1)

; And finally we close out
_ExcelBookClose($oExcel)[/b]
       
        Case $Search; click Search
            MsgBox(0, "Click", "Search")
        Case $Clear; Click clear
            GuiCtrlSetData($Environment,"")
            GUICtrlSetData($Area,"")
            GUICtrlSetData($Area, "CM|eBusiness|Internal","Area")
            GUICtrlSetData($Application,"")
            GUICtrlSetData($Application,"AutoMark|BASIS|BPM|CCR|CM|CommonCust|CTI|CustomerFirst|ENG|eSupport|FADD|FastTrac|FICO|PriceBook

|ReySource|RUOnlone","Application")
            GUICtrlSetData($Name,"")
            GuiCtrlSetData($Number,"")
            GUICtrlSetData($Developer,"")
            GUICtrlSetData($Developer,"Pramer|Fryman|Mathes|Flaute|Schmidt|Carter|Kirchner|Hoeve|Carter|Dahlinghaus","Developer")
            GUICtrlSetData($Deployer,"")
            GUICtrlSetData($Deployer,"Strawser|Schmidt|Fowler|Mathes|Denslow","Deployer")
            GUICtrlSetData($Status,"")
            GuiCtrlSetData($Notes,"")
        Case $Exit; Click Exit
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

I got alot done on the code... Thanks for the excel info PsaltyDS I am having new problems now. I need the code to write the info to next open row. (If the top 354 rows have something in them then go to row 355)

You might want to look at the function _ExcelSheetUsedRangeGet() in that UDF. It will tell you what the last used row in the sheet is.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...