jrmm Posted July 21, 2005 Posted July 21, 2005 Hello - I'm making a AutoIt Gui to read in a text document... (database) and would like to be able to edit records and then re-wite the corrected data over the original line... or else be able to delete the original line and write the corrected data to a new line.I am currently trying using filewriteline, but cannot figure out a way to write over an existing line. Any help/ comments would be greatly appreciated.I love Autoit and would really love to figure out a way to make this work without any third party programming language.Thanks,John PS: I'm attaching my code and I apologize for it not being neat... I have been tinkering with it a lot and am new to autoit. Also I am having a few other glitches, but can probably figure them out on my own. (the biggest being where I delete the listview and re add it - trying to clear it. GUICtrlDelete ($listview)$listview = GUICtrlCreateListView ............john.michna@clarkmemorial.org-----------------expandcollapse popup#region --- GuiBuilder code Start --- ; Scri generated by AutoBuilder 0.5 Prototype #include <GuiConstants.au3> ;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 $type=0 $listview=0 GuiCreate("Data Editor", 798, 462,(@DesktopWidth-798)/2, (@DesktopHeight-594)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $In1 = GuiCtrlCreateInput("", 20, 270, 240, 30);Name GUICtrlSetLimit(-1,26) $In2 = GuiCtrlCreateInput("", 270, 270, 240, 30);Address1 GUICtrlSetLimit(-1,35) $In3 = GuiCtrlCreateInput("", 520, 270, 250, 30);Address2 GUICtrlSetLimit(-1,35) $In4 = GuiCtrlCreateInput("", 20, 340, 100, 30);City GUICtrlSetLimit(-1,20) $Label_6 = GuiCtrlCreateLabel(" Name (last, First MI)", 30, 250, 120, 20) $Label_7 = GuiCtrlCreateLabel(" Address Line 1", 280, 250, 220, 20) $Label_8 = GuiCtrlCreateLabel(" Address Line 2", 530, 250, 240, 20) $Label_9 = GuiCtrlCreateLabel("City", 30, 320, 80, 20) $In5 = GuiCtrlCreateInput("", 130, 340, 50, 30);State GUICtrlSetLimit(-1,3) $Label_11 = GuiCtrlCreateLabel("State", 140, 320, 30, 20) $In6 = GuiCtrlCreateInput("", 190, 340, 90, 30);Zip GUICtrlSetLimit(-1,11) $Label_13 = GuiCtrlCreateLabel("Zip", 200, 320, 60, 20) $In7 = GuiCtrlCreateInput("", 290, 340, 130, 30);BirthDate GUICtrlSetLimit(-1,11) $Label_15 = GuiCtrlCreateLabel("DOB (mm/dd/yyyy)", 300, 320, 110, 20) $In8 = GuiCtrlCreateInput("", 430, 340, 120, 30);AdmitDate GUICtrlSetLimit(-1,11) $Label_17 = GuiCtrlCreateLabel("Admit Date (mm/dd/yyyy)", 430, 320, 120, 20) $In9 = GuiCtrlCreateInput("", 560, 340, 110, 30);Dsch Date GUICtrlSetLimit(-1,11) $Label_19 = GuiCtrlCreateLabel("MR #", 570, 320, 50, 20) $In10 = GuiCtrlCreateInput("", 680, 340, 100, 30);MR# GUICtrlSetLimit(-1,15) $Label_21 = GuiCtrlCreateLabel(" #", 690, 320, 60, 20) $In11 = GuiCtrlCreateInput("", 220, 410, 100, 30);# GUICtrlSetLimit(-1,15) $Label_23 = GuiCtrlCreateLabel("Adm MD #", 230, 390, 60, 20) $In12 = GuiCtrlCreateInput("", 340, 410, 50, 30);Adm MD # GUICtrlSetLimit(-1,8) $Label_25 = GuiCtrlCreateLabel(" Age", 350, 390, 40, 20) $In13 = GuiCtrlCreateInput("", 400, 410, 50, 30); Age GUICtrlSetLimit(-1,8) $Label_27 = GuiCtrlCreateLabel(" Sex", 410, 390, 40, 20) $Add1=GUICtrlCreateButton("Save",500, 400, 95, 50) $clear1=GUICtrlCreateButton("Clear Input",600, 400, 95, 50) $edit1=GUICtrlCreateButton("Edit Record",700, 400, 95, 50) $listview = GUICtrlCreateListView (" Name | Address Line 1 | Address Line 2 |City |State|Zip |Birthdate|Admit Date|MR# |# |Adm MD# | Age| Sex",10,10,778,200);,$LVS_SORTDESCENDING) Readin() ;StringLen ( "string" ) String Leingth GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $clear1 clearform() Case $msg = $edit1 $click1=GUICtrlRead(GUICtrlRead($listview)) if $click1<>"0" then ;msgbox(0,"You clicked",$click1) $split=StringSplit($click1,"|") guictrlsetdata($in1,$split[1]) guictrlsetdata($in2,$split[2]) guictrlsetdata($in3,$split[3]) guictrlsetdata($in4,$split[4]) guictrlsetdata($in5,$split[5]) guictrlsetdata($in6,$split[6]) guictrlsetdata($in7,$split[7]) guictrlsetdata($in8,$split[8]) guictrlsetdata($in9,$split[9]) guictrlsetdata($in10,$split[10]) guictrlsetdata($in11,$split[11]) guictrlsetdata($in12,$split[12]) guictrlsetdata($in13,$split[13]) Else msgbox(0, "Blank Record", "Click on a record to edit it") endif Case $msg = $add1 If GUICtrlRead($in1)="" or GUICtrlRead($in2)="" or GUICtrlRead($in4)="" or GUICtrlRead($in5)="" or GUICtrlRead($in6)="" Then msgbox (48, "Error - Blank Data", " information cannot be blank" & @crlf & "Please fill in missing information and retry.") Else ;;;;;;;;;;;;;MsgBox(0,"listview", "clicked="& GUICtrlGetState($listview),2) ;MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview))) $file = FileOpen("test.txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file. " & $file) Exit EndIf FileWriteLine($file, GUICtrlRead($in1) & "|" & GUICtrlRead($in2) & "|" & GUICtrlRead($in3) & "|" & GUICtrlRead($in4) & "|" & GUICtrlRead($in5) & "|" & GUICtrlRead($in6) & "|" & GUICtrlRead($in7) & "|" & GUICtrlRead($in8) & "|" & GUICtrlRead($in9) & "|" & GUICtrlRead($in10) & "|" & GUICtrlRead($in11) & "|" & GUICtrlRead($in12) & "|" & GUICtrlRead($in13) & @CRLF) FileClose($file) endif GUICtrlDelete ($listview) $listview = GUICtrlCreateListView (" Name | Address Line 1 | Address Line 2 |City |State|Zip |Birthdate|Admit Date|MR# |# |Adm MD# | Age| Sex",10,10,778,200);,$LVS_SORTDESCENDING) Readin() clearform() Case Else ;;; EndSelect WEnd func Readin() ;################################################################################################ ######################### if FileExists ("test.txt") then $file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;MsgBox(0, "Line read:", $line) ;StringSplit($line,"|") ;GUICtrlSetData($listview,"") ;sleep(100) ;$listview = GUICtrlCreateListView (" Name | Address Line 1 | Address Line 2 |City |State|Zip |Birthdate|Admit Date|MR# |# |Adm MD# | Age| Sex",10,10,778,200);,$LVS_SORTDESCENDING) $item1=GUICtrlCreateListViewItem($line,$listview ) Wend FileClose($file) endif EndFunc ;################################################################################################ ##################################### func clearform() ;################################# guictrlsetdata($in1,"") guictrlsetdata($in2,"") guictrlsetdata($in3,"") guictrlsetdata($in4,"") guictrlsetdata($in5,"") guictrlsetdata($in6,"") guictrlsetdata($in7,"") guictrlsetdata($in8,"") guictrlsetdata($in9,"") guictrlsetdata($in10,"") guictrlsetdata($in11,"") guictrlsetdata($in12,"") guictrlsetdata($in13,"") EndFunc ;########################################### Exit #endregion --- GuiBuilder generated code End ---
seandisanti Posted July 21, 2005 Posted July 21, 2005 Hello - I'm making a AutoIt Gui to read in a text document... (database) and would like to be able to edit records and then re-wite the corrected data over the original line... or else be able to delete the original line and write the corrected data to a new line.I am currently trying using filewriteline, but cannot figure out a way to write over an existing line. Any help/ comments would be greatly appreciated.I love Autoit and would really love to figure out a way to make this work without any third party programming language.Thanks,John<{POST_SNAPBACK}>ok, have to admit i didn't really look through your code, but one way to do what you want, would be to write to a temp file as you make changes... like:$input = fileopen("c:\blah.txt",0) $output = fileopen("c:\blah.tmp",2) while 1 $line = filereadline($input) if $line = -1 then exitloop if stringinstr($line,"text i don't want") then $newline = "i'd rather have this" filewriteline($output,$newline) else filewriteline($output,$line) endif wend fileclose($input) fileclose($output) filecopy($output,$input,1) filedelete($output) that will allow you to do what you want i think...
flyingboz Posted July 22, 2005 Posted July 22, 2005 As I recall Larry or Cyberslug developed a UDF / DllCall based methodology for writing to files in place sometime back. Don't have time to search, but check the UDF library, scripts and scraps, etc. Someone has skinned this cat before. I think the approach that allows for binary file handling would work, too. Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
jrmm Posted July 27, 2005 Author Posted July 27, 2005 Thanks so much for the reads and responses. I ended up using the INFILE / OUTFILE idea submitted. It works GREAT!!! Thanks sooo much! I love the way the GUI app is turning out. ~ John
seandisanti Posted July 27, 2005 Posted July 27, 2005 Thanks so much for the reads and responses. I ended up using the INFILE / OUTFILE idea submitted. It works GREAT!!!Thanks sooo much! I love the way the GUI app is turning out.~ John<{POST_SNAPBACK}>glad we could help
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