how to read a number from a text file

SarahWard

Banned
I need to read a text file which holds an integer number (in this case '6').

How can I read this value into a variable?

Everything I try keeps coming up with that annoying and pointless error message "numberformatexception". :(

I have tried using a textreader in readline mode but without luck....


dim TR as TextReader
dim xsize as string
dim sdcard_folder as string: sdcard_folder = "testfolder"

TR.Initialize(File.OpenInput(File.DirRootExternal, sdcard_folder & "xsize.txt"))
xsize = TR.ReadLine
If IsNumber(xsize) = False Then 'DIDN'T READ THE VALUE
TR.Close


When running this code the value of '6', found in the text file, should be read into the string variable 'size'. But it isn't and the if-then test for a number fails. Why isn't the number read as the first line of a text file?

(I have simplified this code for ease of reading)
 
Last edited:

Widget

Well-Known Member
Licensed User
Longtime User
Sarah,

Maybe you need to trim xSize to remove any blanks or LF/CR? What is the xSize.Length?

B4X:
xSize = TR.Readline.Trim
MsgBox("Length="&xSize.Length, "")

Widget
 
Upvote 0

SarahWard

Banned
Erel and Widget

Thank you but those ideas still come up with numberformatexception. :(

I can't believe it is so hard to do something that should be so simple. :BangHead:
 
Upvote 0

SarahWard

Banned
File.WriteString / ReadString (as well as the other methods) should work without any problems. It is most likely that the issue is somewhere else. QUOTE]

Yes, Erel. You are right. The problem seems to be in using a string that holds the integer/numerical value.

I am unable to actually *use* to the number held by that string variable or string array without getting a number.format.error.
These don't work...

I would suggest there is something basic missing from B4A here. You NEED some way of converting the string to an integer or numeric variable otherwise you will find users will keep coming up against this generic error message. Frankly, it shouldn't be this complicated to use or access a number held in a string.

The string-held number is only really easily used as a string (in printing it out in a message box, for example. When you actually come to USING it as a number you get errors all over the place. I even get errors when I try to copy the number value from the string variable/array into an INT variable!

This is the most basic level of code use and I can't believe I am struggling with this. The numberformaterror message is useless as it is a generic, no information message.
 
Last edited:
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
What results do you get if you do something like:

B4X:
xSize = TR.Readline.Trim
Log("{" & xSize & "}")
I use the above to double-check strings are 'clean'
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes, Erel. You are right. The problem seems to be in using a string that holds the integer/numerical value.
This is not what I said, and this is not correct. There is no problem with using a string variable to hold a number.
What I said is:
It is most likely that the issue is somewhere else. If you can upload your project we can further help you.
 
Upvote 0

SarahWard

Banned
This is not what I said, and this is not correct. There is no problem with using a string variable to hold a number.
What I said is:

Yes, sorry. I was making my own assumptions.

The integer value (held in a string or string array) can be seen in a Toast or msgbox display. It is correct.

The error comes when I try to use it.

Example...

dim a(10) as string 'string array
a(1) = "1" 'integer into the first array

dim b as int 'an integer variable to hold number in string array

b = a(1) ' causes NumberFormatError when trying to pass '1' to variable b

------------------

a(1) should = "1"
b should = 1

but what happens is I get an error.:BangHead:
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Something does not add up here, I copied and pasted this code
B4X:
dim a(10) as string 'string array
a(1) = "1" 'integer into the first array 

dim b as int 'an integer variable to hold number in string array

b = a(1) ' causes NumberFormatError when trying to pass '1' to variable b

into a test project and it worked, no errors and b was set to 1.

Could there be something wrong elsewhere?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try this code:
B4X:
[SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Process_Globals[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] a([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Int[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Globals[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Reader [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]TextReader[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Writer [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]TextWriter[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Activity_Create(FirstTime [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Boolean[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] i [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Int[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] txt [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]String[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]  Writer.Initialize([/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]File[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].OpenOutput([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]File[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].DirInternal,[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"test.txt"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  For[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] i = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]To [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]    Writer.WriteLine(i)[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  Next[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]  Writer.Close[/SIZE][/FONT]
 
[SIZE=2][FONT=Courier New]  Reader.Initialize([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]File[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].OpenInput([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]File[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].DirInternal,[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"test.txt"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  For[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] i = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]To [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]    txt = Reader.ReadLine[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    a(i) = txt[/FONT][/SIZE]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]    Log[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](txt & [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]" / "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] & a(i))[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  Next[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]  Reader.Close[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

Best regards.
 
Upvote 0

SarahWard

Banned
Thanks guys. I will try out your code, klaus. :)

I think I may have discovered the problem.

When the first line in a text file is a number it cannot be used without causing these numberformaterrors.

My text file originally had one line with the first text line a number...

1

I found other numbers in the text file worked as expected so I added a dummy line of text in the file's 'line-one' position, pushing the original '1' text down a line...

dummy text
1

I read the dummy text and then the 1. Now the 1 value works without giving errors in arrays, etc.

What is going on here?? It seems the first line in a text file is not quite standard. The length of this number on the file's first-line, when read into a string, was length=2. Is a hidden control character also being read?
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Are you saying that this code
B4X:
dim a(10) as string 'string array
a(1) = "1" 'integer into the first array 

dim b as int 'an integer variable to hold number in string array

b = a(1) ' causes NumberFormatError when trying to pass '1' to variable b
works, even though you claimed it did not work?

It is impossible to help people who invent non-existant problems:BangHead:
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It seems that there is a problem in B4A reading UTF-8 text files.
In the attached code I try to read 4 files:
- test_b4a.txt written with B4A with Writer.WriteLine(i) i = 0, 1 , 2 etc.
- test_b4ppc.txt, the 'same' file written with B4PPC
- test_notepad.txt, the 'same' file written with the Notepad.
- test_b4a_1.txt written with B4A with Writer.WriteLine(txt) txt = "0", "1" etc, (reading back the lines from test_b4a.txt and writing back to test_b4a_1.txt not included in the test program).

Reading test_b4a.txt no problem
Reading test_b4ppc.txt, text_notepad.txt and test_b4a_1.txt raise the NumberFormatError error.
To get the correct value we need to remove the first byte of the first line.
All three files, test_b4ppc.txt, test_notepad.txt and test_b4a_1.txt have the first 3 bytes (hex EF BB BF) of the UTF-8 encoding.
File test_b4a.txt doesn't have those 3 bytes.
But the length of the first line, in the three files, is 2, so it seems that B4A removes the first two bytes but not the third one ?

Attached the test program with the files.

Best regards.
 

Attachments

  • TestReadInteger.zip
    4.9 KB · Views: 256
Last edited:
Upvote 0

SarahWard

Banned
It seems that there is a problem in B4A reading UTF-8 text files.
In the attached code I try to read 4 files:
- test_b4a.txt written with B4A with Writer.WriteLine(i) i = 0, 1 , 2 etc.
- test_b4ppc.txt, the 'same' file written with B4PPC
- test_notepad.txt, the 'same' file written with the Notepad.
- test_b4a_1.txt written with B4A with Writer.WriteLine(txt) txt = "0", "1" etc, (reading back the lines from test_b4a.txt and writing back to test_b4a_1.txt not included in the test program).

Reading test_b4a.txt no problem
Reading test_b4ppc.txt, text_notepad.txt and test_b4a_1.txt raise the NumberFormatError error.
To get the correct value we need to remove the first byte of the first line.
All three files, test_b4ppc.txt, test_notepad.txt and test_b4a_1.txt have the first 3 bytes (hex EF BB BF) of the UTF-8 encoding.
File test_b4a.txt doesn't have those 3 bytes.
But the length of the first line, in the three files, is 2, so it seems that B4A removes the first two bytes but not the third one ?

Attached the test program with the files.

Best regards.

Klaus, you have discovered the problem! Thank you! :sign0188:

All the files I am using are UTF-8 from B4PPC use. I use UTF-8 so that people can alter the English texts of my Nature programs into their own European languages. I got around this byte problem by putting a dummy text onto the first line of each text file I wanted to read a number from. The number then became the second line and the problem didn't occur.

I don't think this is the only problem B4A has with UTF-8 either. Some of these text files display in a text box really strangely, as though they are centre justified and with lots of space between characters and lines. I may have to write a program to convert all the 2000+ text files from UTF-8 into B4A's version of UFT-8. Hmmm...
 
Last edited:
Upvote 0
Top