jorgev Posted June 10, 2009 Share Posted June 10, 2009 Hello all, I'm looking for a way to split a textfile i want to read and display the contens in 3 different edit windows. The content of the file are actually 3 seperate files that i merged. And inside the file I added a line like "-----end of part 1-----" and "------end of part 2-------" I did that to be able to split the files again. But now i'm not sure how i have to do that. The code i have to start is this: Case $Buttonloadsetup $var2 = FileOpenDialog( "Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2) $File = FileOpen ( $var2 , 0 ) GUICtrlSetData ( $Edit1 , FileRead ( $File ) ) FileClose ( $File );close the file $File = FileOpen ( $var2 , 0 ) GUICtrlSetData ( $Edit11 , FileRead ( $File ) ) FileClose ( $File ) $File = FileOpen ( $var2 , 0 ) GUICtrlSetData ( $EditC , FileRead ( $File ) ) FileClose ( $File ) Offcours this just reads the complete file and displays that file in each edit window($Edit1, $Edit11, $EditC) Can anyone point me to a methode how i can read until "-----end of part 1-----" and write that to $Edit1, then read further until "-----end of part 2-----" and write that to $Edit11, and then read until the end of the file and write that to $EditC Any help with this would be much appriciated. kind regards, Jorgev Link to comment Share on other sites More sharing options...
ofLight Posted June 10, 2009 Share Posted June 10, 2009 (edited) Something like this I think ? Case $Buttonloadsetup $var2 = FileOpenDialog( "Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2) $File = FileOpen ( $var2 , 0 ) $Data = FileRead($File) FileClose ( $File );close the file GUICtrlSetData ( $Edit1 , StringMid($Data,1,StringInStr($Data,"-----end of part 1-----")) ) GUICtrlSetData ( $Edit11 , StringMid($Data,StringInStr($Data,"-----end of part 1-----")),StringInStr($Data,"-----end of part 2-----")) ) GUICtrlSetData ( $EditC , StringMid($Data,StringInStr($Data,"-----end of part 2-----")),StringInStr($Data,"-----end of part 3-----")) ) Edit: extra code was in there Edited June 10, 2009 by ofLight There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly Link to comment Share on other sites More sharing options...
martin Posted June 10, 2009 Share Posted June 10, 2009 Something like this I think ? Case $Buttonloadsetup $var2 = FileOpenDialog( "Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2) $File = FileOpen ( $var2 , 0 ) $Data = FileRead($File) FileClose ( $File );close the file GUICtrlSetData ( $Edit1 , StringMid($Data,1,StringInStr($Data,"-----end of part 1-----")) ) GUICtrlSetData ( $Edit11 , StringMid($Data,StringInStr($Data,"-----end of part 1-----")),StringInStr($Data,"-----end of part 2-----")) ) GUICtrlSetData ( $EditC , StringMid($Data,StringInStr($Data,"-----end of part 2-----")),StringInStr($Data,"-----end of part 3-----")) ) Edit: extra code was in thereI think that is close, but you will include the separator at th estart, and the length of the stringmid is not calculated correctly. Maybe this Case $Buttonloadsetup $var2 = FileOpenDialog("Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2) $allText = FileRead($var2) $start = 1 $End = StringInStr($allText, "-----end of part 1-----") GUICtrlSetData($Edit1, StringMid($allText, $start, $End - $start) $start = $End + StringLen("-----end of part 1-----") $End = StringInStr($allText, "-----end of part 2-----") GUICtrlSetData($Edit11, StringMid($allText, $start, $End - $start) $start = $End + StringLen("-----end of part 2-----") $End = StringInStr($allText, "-----end of part 3-----") GUICtrlSetData($EditC, StringMid($allText, $start, $End - $start) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jorgev Posted June 11, 2009 Author Share Posted June 11, 2009 I think that is close, but you will include the separator at th estart, and the length of the stringmid is not calculated correctly. Maybe this Case $Buttonloadsetup $var2 = FileOpenDialog("Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2) $allText = FileRead($var2) $start = 1 $End = StringInStr($allText, "-----end of part 1-----") GUICtrlSetData($Edit1, StringMid($allText, $start, $End - $start) $start = $End + StringLen("-----end of part 1-----") $End = StringInStr($allText, "-----end of part 2-----") GUICtrlSetData($Edit11, StringMid($allText, $start, $End - $start) $start = $End + StringLen("-----end of part 2-----") $End = StringInStr($allText, "-----end of part 3-----") GUICtrlSetData($EditC, StringMid($allText, $start, $End - $start) That worked like a charm Martin, tx alot i just had to add ) at the end of each GUICtrlSetData line. Thanks Martin and ofLight for the input. Cheers jorgev 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