PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WEBDEV 2024 → Having problem in writing input in a text file
Having problem in writing input in a text file
Débuté par Ashutosh dixit, 14 déc. 2012 11:58 - 9 réponses
Posté le 14 décembre 2012 - 11:58
Hello,
i want to write binary input of 5 edit boxes into a text file like this,
11001111
11111111
10111000
11000000
but i don't know how to do it,i used "..." in fwrite but it didn't work.
please help me !!
thanks in advance !
Membre enregistré
47 messages
Popularité : +2 (2 votes)
Posté le 22 décembre 2012 - 21:00
Let me see your code


--
Roy van der Lee
Posté le 23 décembre 2012 - 10:34
Info("Submited")

FileNum is int
FileName is string = "F:\Studies\Electronics\verilog files\Modelsim\data.txt"
Res is int

//FileNum3 is string
//Res = fWrite(FileNum,Asd)
//asd=...
// Reopen the file
FileNum = fOpen(FileName,foWrite)
//FileNum3 = fOpen(FileName,foWrite)
IF FileNum = -1 THEN
Info("Error opening "+FileName)
ELSE
Res = fWrite(FileNum,EDT_data_1)
Res = fWrite(FileNum,EDT_data_2)
Res = fWrite(FileNum,EDT_data_3)
Res = fWrite(FileNum,EDT_data_4)
Res = fWrite(FileNum,EDT_data_5)

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



I Want to write the EDT_data_2 in next line and then data 3 on next line .....
and all these EDT are integers
Posté le 23 décembre 2012 - 10:35
Info("Submited")

FileNum is int
FileName is string = "F:\Studies\Electronics\verilog files\Modelsim\data.txt"
Res is int

//FileNum3 is string
//Res = fWrite(FileNum,Asd)
//asd=...
// Reopen the file
FileNum = fOpen(FileName,foWrite)
//FileNum3 = fOpen(FileName,foWrite)
IF FileNum = -1 THEN
Info("Error opening "+FileName)
ELSE
Res = fWrite(FileNum,EDT_data_1)
Res = fWrite(FileNum,EDT_data_2)
Res = fWrite(FileNum,EDT_data_3)
Res = fWrite(FileNum,EDT_data_4)
Res = fWrite(FileNum,EDT_data_5)

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


i want to add EDT_DAta2 file in the next line and so on, and remember all the edit boxes are integer
Thank you in advance.
Membre enregistré
47 messages
Popularité : +2 (2 votes)
Posté le 23 décembre 2012 - 16:07
// I don't see the creation of the file, so I insert code: fCreate(FileName)
// You want each value at a new line, for that I change fwrite in fwriteline

Info("Submited")

FileNum is int
FileName is string = "C:\Ashutosh\data1.txt"
Res is int

res = fCreate(FileName)
IF res = -1 THEN
Info("Error create: "+FileName)
END
FileNum = fOpen(FileName,foWrite)
//FileNum3 = fOpen(FileName,foWrite)
IF FileNum = -1 THEN
Info("Error opening "+FileName)
ELSE
Res = fWriteLine(FileNum,EDT_Data_1)
Res = fWriteLine(FileNum,EDT_Data_2)
Res = fWriteLine(FileNum,EDT_Data_3)
Res = fWriteLine(FileNum,EDT_Data_4)
Res = fWriteLine(FileNum,EDT_Data_5)

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

// IF you use an edit control Type Numeric and your input is: 11110000 11011011 0000011 00011010 1000000
// The result in the file is: 11110000
// 11011011
// 11
// 11010
// 10000000

// I think this is not what you want.
// change the fwriteline in: res = fWriteLine(FileNum,NumToString(EDT_Data_1, "08d")

FileName = "C:\Ashutosh\data2.txt"
res = fCreate(FileName)
IF res = -1 THEN
Info("Error create: "+FileName)
END
FileNum = fOpen(FileName,foWrite)
//FileNum3 = fOpen(FileName,foWrite)
IF FileNum = -1 THEN
Info("Error opening "+FileName)
ELSE
Res = fWriteLine(FileNum,NumToString(EDT_Data_1, "08d"))
Res = fWriteLine(FileNum,NumToString(EDT_Data_2, "08d"))
Res = fWriteLine(FileNum,NumToString(EDT_Data_3, "08d"))
Res = fWriteLine(FileNum,NumToString(EDT_Data_4, "08d"))
Res = fWriteLine(FileNum,NumToString(EDT_Data_5, "08d"))

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

// The result in the file is: 11110000
// 11011011
// 00000011
// 00011010
// 10000000

// This is what you want?
//
// I have some suggestions for better input. The user must enter 8 digits: 0 or 1

// Suggestions 1:
// Fill the inputmask in the numeric editcontrole with: 00000000
// Choose Alignment (Tab GUI) of the numeric edit controle: Left


// Suggestion 2: (better)
// Change the the type of the edit controltype into: Text and Input size: 8
// Code under: ENTRY control:
MySelf..InputMask = "regexp:[0-1]{0,8}"
// Code under EXIT control:
Length(MySelf) < 8 THEN
ReturnToCapture()
END

// Now the user must enter 8 digits 0 or 1
// In the situation that the edit controltype = Text, you must use
fWriteLine(FileNum,EDT_Data_1)

I hope this code will help you.


--
Roy van der Lee
Posté le 24 décembre 2012 - 12:05
Thank you
Roy van der Lee
you have helped me a lot in my project.I am creating a compiler for my micro controller and i was stuck here from last week. i am new to this program.
thank you for you help !!

Ashutosh Dixit
Posté le 25 décembre 2012 - 11:39
Van
i also want to know that i want to create a compiler using an edit box. like
if i will write
MOV a,#45h;
i have to read this instruction in three segments so that i can understand
MOV value 45 to a(location)
i don't know how to do this
can you help me?
Membre enregistré
47 messages
Popularité : +2 (2 votes)
Posté le 26 décembre 2012 - 16:40
// Windev code

// If you want to split your inputcode into parts then you first has to know what are
// the character(s) that can seperate the codestring.
// I think it can be a space, a comma and maybe a semicolon and a TAB


sInstructionfield is string
Field1, Field2, Field3, Field4, field5, field6, field7, field8, field9 are strings

sInstructionfield = "Mov a,#45h;"


Field1 = ExtractString(sInstructionfield,1,[" ", ",", ";", TAB]) // Mov
Field2 = ExtractString(sInstructionfield,2,[" ", ",", ";", TAB]) // a
Field3 = ExtractString(sInstructionfield,3,[" ", ",", ";", TAB]) // #45h
Field4 = ExtractString(sInstructionfield,4,[" ", ",", ";", TAB]) //
field5 = ExtractString(sInstructionfield,5,[" ", ",", ";", TAB]) //
field6 = ExtractString(sInstructionfield,6,[" ", ",", ";", TAB]) //
field7 = ExtractString(sInstructionfield,7,[" ", ",", ";", TAB]) //
field8 = ExtractString(sInstructionfield,8,[" ", ",", ";", TAB]) //
field9 = ExtractString(sInstructionfield,9,[" ", ",", ";", TAB]) //

// It will be better to discard needless spaces (NOSPACE) and change the assemblycode
// to lower (LOWER) characters.
// you can do it by the "FOR loop"

sInstructionfield = "Push offset msg"
fieldvalue is string
code is string
fieldnr is int = 1
FOR i = 1 TO 9
fieldvalue = Lower(NoSpace(ExtractString(sInstructionfield,i,[" ", ",", ";" , TAB])))
IF fieldvalue <> "" THEN
code = "field" + fieldnr
{code} = fieldvalue // if fieldnr has a value 3 then {code} changes in Field3
fieldnr++ // increase fieldnr by 1
END
END

// the fields 1 to 9 represents the seperated words of your assembly instruction.
// When a field (1 to 9)the value <EOT> then you can skip this field.

//Field1: push
//field2: offset
//Field3: msg
//Field4 - 9 <EOT>


--
Roy van der Lee
Posté le 30 décembre 2012 - 11:23
OK i got it.
i am having a problem in converting a HEX number 45 to an 8 bit binary number
01000101. please tell me if there is any way to do that.
i tried hextobuff but it is giving only one output "E"

sBlock is UNICODE string
sBlock = fReadLine(nFileNum) //MOV A,#45h
asd is buffer
Asd= HexaToInt(sInput2][i][[2 TO 3]) // this means 45
Info(Asd)
Membre enregistré
47 messages
Popularité : +2 (2 votes)
Posté le 31 décembre 2012 - 18:21
Create a Global procedure "TransformHexToBinary(Hex)" and copy this code in the procedure.


PROCEDURE TransformHexToBinary(Hex)

// YOU CAN USE THIS PROCEDURE FOR CONVERTING A HEXVALUE (00 UNTIL FF) TO A BINARY VALUE
//
// TransformHexToBinary( your hex-value )

// Example

// binary_value is string
// hexvalue is string = <your value>

// binary_value = TransformHexToBinary(hexvalue)

// End of example


// If the input is #45H then result = 01000101
// If the input is #2Fh then result = 00101111
// If the input is #ah then result = 00001010

// Characters # and H are optional
// Maximum 2 of characters each from 0-9 and A-F
//
// This procedure filters the characters #, h and H
// It sets all values in uppercase
// It converts the digits 0 to 9 and the characters A to F to binary values

sveld is string = NumToString(NoSpace(Replace(Replace(Upper(Hex),"H"," "),"#"," ")),"02d")
IF Length(sveld) = 1 THEN
sveld = "0" + sveld
END
bin is string
FOR i = 1 TO 2
SWITCH sveld[[i on 1]]
CASE "0" : bin[[i*4-3 on 4]] = "0000"
CASE "1" : bin[[i*4-3 on 4]] = "0001"
CASE "2" : bin[[i*4-3 on 4]] = "0010"
CASE "3" : bin[[i*4-3 on 4]] = "0011"
CASE "4" : bin[[i*4-3 on 4]] = "0100"
CASE "5" : bin[[i*4-3 on 4]] = "0101"
CASE "6" : bin[[i*4-3 on 4]] = "0110"
CASE "7" : bin[[i*4-3 on 4]] = "0111"
CASE "8" : bin[[i*4-3 on 4]] = "1000"
CASE "9" : bin[[i*4-3 on 4]] = "1001"
CASE "A" : bin[[i*4-3 on 4]] = "1010"
CASE "B" : bin[[i*4-3 on 4]] = "1011"
CASE "C" : bin[[i*4-3 on 4]] = "1100"
CASE "D" : bin[[i*4-3 on 4]] = "1101"
CASE "E" : bin[[i*4-3 on 4]] = "1110"
CASE "F" : bin[[i*4-3 on 4]] = "1111"
OTHER CASE : bin[[i*4-3 on 4]] = "0000"
END
END
Hex = bin





--
Roy van der Lee