|
How to read data from a txt file |
Iniciado por Ashutosh, 25,dic. 2012 11:41 - 1 respuesta |
| |
| | | |
|
| |
Publicado el 25,diciembre 2012 - 11:41 |
I want to create a compiler using edit box so that i can input a program code like MOV A,#45H; //MOVE 45 to A MOV R2,#20H; //MOVE 20 to R2 ADD A,R2; //add a,r2 i want to read this prog line by line and want to separate mov and add instruction, A and R2 Register ,#45 and #20 value , in different inputs. please help me with this
i used this method but it is in effective because i cannot differentiate A and R2
FileNum is int FileName is string Res is string cmd is string Input1 is string Input2 is string
FileName = "G:\Studies\Electronics\verilog files\Modelsim\Microcontroller\Prog.txt" FileNum = fOpen(FileName,foWrite) IF FileNum = -1 THEN Info("Error opening "+FileName) ELSE Res = fReadLine(FileNum) //fWriteLine(FileNum,EDT_prog) Info(Res) cmd = Res[[1 TO 3]] Input1=Res[[5 TO 5]] Info(Input1) IF Res = -1 THEN Info("Error writing into "+FileName) ELSE // Close the file fClose(FileNum) Info("End of write-to-file operation "+FileName,... "File closed") END END |
| |
| |
| | | |
|
| | |
| |
Publicado el 26,diciembre 2012 - 15:15 |
Hi
1. your test IF Res = -1 THEN - is incorrect (freadline never returns -1, see help for details) - should be done IMMEDIATELY after the freadline, as you don't want to set your variables if there was an error
2. To extract A and R2, you cannot rely on the position only, as the ending position/length of the string changes. Therefore, you should instead do something like this
input1=res[[5 to position(res,",")-1]] input2=res[[position(res,",")+1 to position(res,";")-1]]
Best regards
-- Fabrice Harari Consultant WinDev, WebDev et WinDev Mobile International
Plus d'information sur http://fabriceharari.com/index_FR.html
On 12/25/2012 5:41 AM, Ashutosh wrote:
I want to create a compiler using edit box so that i can input a program code like MOV A,#45H; //MOVE 45 to A MOV R2,#20H; //MOVE 20 to R2 ADD A,R2; //add a,r2 i want to read this prog line by line and want to separate mov and add instruction, A and R2 Register ,#45 and #20 value , in different inputs. please help me with this
i used this method but it is in effective because i cannot differentiate A and R2
FileNum is int FileName is string Res is string cmd is string Input1 is string Input2 is string
FileName = "G:\Studies\Electronics\verilog files\Modelsim\Microcontroller\Prog.txt" FileNum = fOpen(FileName,foWrite) IF FileNum = -1 THEN Info("Error opening "+FileName) ELSE Res = fReadLine(FileNum) //fWriteLine(FileNum,EDT_prog) Info(Res) cmd = Res[[1 TO 3]] Input1=Res[[5 TO 5]] Info(Input1) IF Res = -1 THEN Info("Error writing into "+FileName) ELSE // Close the file fClose(FileNum) Info("End of write-to-file operation "+FileName,... "File closed") END END
|
| |
| |
| | | |
|
| | | | |
| | |
|