Hello,
I need to create a file from an excel sheet.
The VBA project reads values of cells and write them into the file (ofln):
Open OFLN For Output As 1
For IR = 1 To 72
XLINE =""
For IC = 11 To 19
A$ = LTrim(RTrim(Cells(IR, IC).Value))
XLINE = XLINE + Chr$(32) + A$
Next IC
XLINE = LTrim(RTrim(XLINE))
Print #1, XLINE
Next IR
Close 1
What is supposed to do, is reading in a loop (IR) a section of a row and write it on the OFLN.
The problem I have, is that some cells have the value ‘0’ (number zero) and the input file created, needs to include integers as well as real numbers.
If A2=0 (format in excel is “number”, “decimals=0”) it needs to write 0
If B2=0.0 (format in excel is “number”, “decimals=1”) it needs to write 0.0
For other values the ‘rules’ are the same:
If A2=5 (format in excel is “number”, “decimals=0”) it needs to write 5
If B2=5.0 (format in excel is “number”, “decimals=1”) it needs to write 5.0
The module, as shown above, always writes the value of the celsl in the OFLN always without decimals, which is a problem, since the code that later on reads OFLN, needs to recognize and differentiate between integers and decimals.
Any ideas?
Thanks
Katto01
I need to create a file from an excel sheet.
The VBA project reads values of cells and write them into the file (ofln):
Open OFLN For Output As 1
For IR = 1 To 72
XLINE =""
For IC = 11 To 19
A$ = LTrim(RTrim(Cells(IR, IC).Value))
XLINE = XLINE + Chr$(32) + A$
Next IC
XLINE = LTrim(RTrim(XLINE))
Print #1, XLINE
Next IR
Close 1
What is supposed to do, is reading in a loop (IR) a section of a row and write it on the OFLN.
The problem I have, is that some cells have the value ‘0’ (number zero) and the input file created, needs to include integers as well as real numbers.
If A2=0 (format in excel is “number”, “decimals=0”) it needs to write 0
If B2=0.0 (format in excel is “number”, “decimals=1”) it needs to write 0.0
For other values the ‘rules’ are the same:
If A2=5 (format in excel is “number”, “decimals=0”) it needs to write 5
If B2=5.0 (format in excel is “number”, “decimals=1”) it needs to write 5.0
The module, as shown above, always writes the value of the celsl in the OFLN always without decimals, which is a problem, since the code that later on reads OFLN, needs to recognize and differentiate between integers and decimals.
Any ideas?
Thanks
Katto01