Android Question Strangest Problem I've Ever Seen...

TheWind777

Active Member
Licensed User
Longtime User
I am trying to load in a text file that is in the DirAssets folder.

I define a string named "FileName" (I tried changing the name to just "Name") and I've even tried printing the sequence Exercise_" & EditTextWBLesson.Text & ".txt" using a library routine sf.mb("Exercise_" & EditTextWBLesson.Text & ".txt")

Dim FileName As String

I set up the string

FileName = "Exercise_" & EditTextWBLesson.Text & ".txt"

Where EditTextWBLesson.Text is a numeric string from an EditText box.

I have used EditTextWBLesson.Text numerous times in the routine.

When I print FileName, I don't get the filename, I get THE CONTENTS OF THE TEXT FILE.

So, the combined text sequence is equaling the CONTENTS OF THE FILE.

I have never seen such a thing, and I can't get it to stop doing it.

In the very same subroutine I am doing the very same thing, and in that case I get the concatenated filename, properly... and when I print it, it of course prints the filename. It doesn't automatically load the filename just by having the word sequence equal that filename. That is insane.

You might say, "Well, why don't you just go..."

Dim Contents as String
Contents = "Exercise_" & EditTextWBLesson.Text & ".txt"

and then I will have what I want, a string named Contents which equals the contents of the text file?

Yep... and when I try that, that's what happens. It works. No, you probably won't believe it - but it works. Afterwards Contents equals the CONTENTS OF THE TEXT FILE... not the text file's name.

I thought, somehow, it might have something do with BASIC2Android's automatic ability to cast types... can't imagine how; but I see nowhere where I'm casting it wrong.

And it happens whether I assign to a FileName string, or just use the string sequence, or even try building the filename string in fragments. In the end, always, I end up with the entire contents of the text file rather than the text file's name.

Any ideas as to what might be happening?

I am returning a small array in a completely different subroutine and I thought it might somehow be overwriting the string area in memory???

No idea. You got any?

I'm doing a returned array like this, in case that is any part of my very strange problem.

Sub GetWBLastLesson(BlankString AsString) AsString()
Dim TheMapFile AsMap
Dim ReturnArray(2) AsString

'Read what the last lesson filename was
' Returns array(0) = filename
' Return array(1) = LastType, where LastType = "0" If regular txt File, "1" If intro, "2" If "theme"

TheMapFile = ReadInitFile("")
ReturnArray(0) = TheMapFile.Get("LastLesson")
ReturnArray(1) = TheMapFile.Get("LastType")
Return ReturnArray
End Sub

Is that the proper way to return an array? It works.

In that case, the calling subroutine goes:

Dim TheLastLesson(2) AsString

TheLastLesson = GetWBLastLesson("")
LastLessonNum = TheLastLesson(0)
LastLessonType = TheLastLesson(1)

It works, and I think it's right; but it's the only thing I can think of as to what might be causing such a strange problem.

Here's a zip file containing the whole project, minimized to just the 1.txt and exercise.txt files.

Type 1 in the text box in the upper-left and ENTER. It should bring up an sf.mb() that SHOULD be the filename; but instead is the file's contents.


http://www.filedropper.com/problem
 

stevel05

Expert
Licensed User
Longtime User
Looking at Sub GetWBText you have EditTextWBLesson.Text that holds the text of the lesson, and EditTextWBNumber.Text that holds the lesson number. Are you sure your not mixing the two up?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Please enclose code in code brackets.

I would also watch out for Reserved Keywords, which you might start to impinge on.
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
Looking at Sub GetWBText you have EditTextWBLesson.Text that holds the text of the lesson, and EditTextWBNumber.Text that holds the lesson number. Are you sure your not mixing the two up?

Yeah, but at that moment I haven't even loaded the text file in. I'm just creating the file name. And, the instant I create the file name, without even using any function at all that might load the text file in... the FileName becomes the contents of the text file.

There is no text loaded-in yet, from that text file.

it is just the assignment of the name of the textfile which, before even using the name of the text file - becomes the text of the text file.

Install the project and enter 1 in the upper-left text box (between the forward/backward gadgets) and press enter. A messagebox will come up with the contents of the text file as the string even though I haven't even called any FUNCTION that reads a text file yet. The filename, itself, is the contents of the text file (and it doesn't get much stranger than that).
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
Please enclose code in code brackets.

I would also watch out for Reserved Keywords, which you might start to impinge on.

I always use long descriptive words for my variables, EditText, and such. Hard to imagine I am impinging on any Reserved Keywords.

Titles such as EditTextWBLesson.Text

I generally start the name with the thing it belongs with, like an EditText box... so my my EditText names are EditTextWBTheText.Text, EditTextSuchAndSuch; whereas labels are generally LabelWBLesson, LabelWBResources, etc.
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
Looking at Sub GetWBText you have EditTextWBLesson.Text that holds the text of the lesson, and EditTextWBNumber.Text that holds the lesson number. Are you sure your not mixing the two up?

Yes, I was mixing the two up. Sometimes long programming sessions make you see double. The text wasn't the text inside the file, it was the exact same text as was in the Lesson box. You hit it right on the nose. Thank you.
 
Upvote 0
Top