It was said numerous time that we can add .txt file in the Navigation pane and use it as a Variable.
In a small (very small) project, I had to add a list (actually 26 lines, but can grow).
I do not wanted to add lines of codes to copy the .txt file into Application Support, code to open it, etc.
Then I dropped the .txt file in the Navigation pane, and add that code:
API (1, sorry) Code:
Sub Open() Handles Open
Dim Loop_Idx As Integer
Dim Line_Cnt As Integer
Dim AnEntry As String
// How many entries in Character_List_CK ?
// 0-based & 1 EndOfLine at the end of the document = -2
Line_Cnt = CountFields(Character_List_CK, EndOfLine)-2
// Scan the whole Character_List_CK contents
For Loop_Idx = 0 To Line_Cnt
// Get a Character and URL
AnEntry = NthField(Character_List_CK, EndOfLine, Loop_Idx+1)
// Add a Row and put a Character and URL
Me.AddRow NthField(AnEntry, Chr(9), 1)
Me.RowTag(Loop_Idx) = NthField(AnEntry, Chr(9), 2)
// In case of… trouble
If UserCancelled Then Exit
Next
End Sub
Enjoy.
PS: The original project (not that code) was in API2 (Xojo 21r2.1), once converted to 2015r1, the project was smaller than the original in API2 (do not know why). But not by far, this is a very small project.
For anyone curious about what is being discussed here, forgive me for mansplaining…
Emile has a text file called Character_List_CK.txt
It contains 26 rows of text
By dragging it into the IDE, it becomes part of the app.
(It will also appear in the resources folder of the compiled app as a file called Character_List_CK.txt)
But having dragged it into the project in this way, you can ALSO refer to the contents as if they are a string constant called
Character_List_CK
So it is possible to msgbox Character_List_CK,
and to parse the contents as Emile has shown above.
As an alternative, would it not also be possible just to create a string constant in the application and place the text there during development? After that, it could be accessed in essentially the same way. And this would avoid having it end up in the resources folder.
Does anyone know of an actual limitation of how big this text constant can be? I have one application with a text constant of 1.4MB and I have not had any trouble with it.
I routinely have string constants embedded in my programs that contain end of lines
I have string constants that are larger than 1.4MB – with, I think, 2.5MB being the biggest – in one of my projects, and EOLs aren’t a problem. I don’t usually do that, but there’s a specific reason this project requires it.