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
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