Declaring and Use of Variables

This helps. :slight_smile:
By indexing I meant Short display name is a shortened version of the book name, so no reference to the length of the book. The Short display name is a human chosen format of the name and not something that can be generated by a computer.

The short string identifier is the same as the short display name and is used for filenames. So the data is stored in files with the shortened name with lowercase and no spaces. This format has other uses as well.

Quick Entry refers to the fewest characters a user has to enter for the correct book to be selected.
So if a user types ‘G’, the book could be Genesis or Galatians. Typing ‘E’ or ‘A’ determines what the intended book is. This is a list that could be calculated by a function.

I have completed the browsing part of the app, including word lookup, a reading plan, history, different displays, using VB6. The interface is also completely responsive.

Here are the screenshots -

https://imgur.com/a/nX1OsGt

https://imgur.com/a/r3B6Ilv

Ah, nostalgia. I’ve not used a goto since I stopped programming in FORTRAN in 1978.

1 Like

Danger with this is that two days later you’ll look at it, and won’t have a clue why it works. Or it works 95% of the time and the problem now is, that the logic is so convoluted that as you mess with it to fix the 5%, the proportion of problems stays at 5% but it’s a different 5% each time.

2 Likes

Absolutely. Lately I’ve done force programming for my new app as I need to see results pronto, and then I just re-code the sub-routines from scratch, which I’m happy with as I have a working app and I don’t mind re-doing things. Some code I reduce by a factor of 10. I find making notes help and also print out my code and pour over it for an hour or two to find the optimal solution. If I really get stuck then I write an essay detailing every aspect of the processes at the beginning of each relevant sub routine. Basically stop at nothing until it can’t be optimised any further.

Actually, Xojo DOES have a goto statement. It’s undocumented for obvious reasons. I assume that it’s there for backwards compatibility with ancient Basic programs.

Edit:
My mistake. It is documented:
https://documentation.xojo.com/api/code_execution/goto.html

2 Likes

Oh yes. Something to include in my Xojo apps for historical reasons. Bit like, but not as bad as that stupid plugin that Wordpress insists every website should have. The definition of cranky.

Unfortunately GoTo is still very much alive. It’s one of those things I wish they’d remove as I sometimes get OPC (other peoples’ code) to work on and it’s just covered in a maze of GoTos.

1 Like

Danger Will Robinson, DANGER.

I went there some days ago:

Time wasting, but I love the result: neat code. Less needed comments.

Lovely when I removed the old code (commented during the process).

And in the process I forget some code (a part of a file name, the image in Drag and Drop, …) and I’ve done that on M1 so I was asking myself if this (Drag and Drop with an image displayed) works on M1…

Can someone please provide me with the simplest code for opening a text file and reading 2 strings that are separated by a comma.

https://documentation.xojo.com/api/files/textinputstream.html

below is a example with reading tab separated

Yes thanks. I saw that. But I’m needing a simpler example with just 2 strings.
(Comma would be character 44.)

Small change to the example:

Var f As FolderItem
Var textInput As TextInputStream
Var rowFromFileAs String
var fields() as string
Var i As Integer
f = FolderItem.ShowOpenFileDialog("text/plain") // defined as a FileType
If f <> Nil And f.Exists Then

  textInput = TextInputStream.Open(f)
  While Not textInput.EndOfFile
    rowFromFile = textInput.ReadLine
    fields = rowFromFile.split(",")
 
//now do what you want with fields(0) and fields(1)
    
   
  Wend
  textInput.Close
End If
1 Like

Awesome. That’s exactly what I was needing. I can make sense of it all. :white_check_mark:
Thanks Jeff :slight_smile:

BTW - Recommendation for anyone reading this. I use Scrivener to save all my code snippets, which I find very handy.

https://www.literatureandlatte.com/scrivener/download

Everything is running perfectly.
Able to populate the listboxes with booknames and have the relevant chapters appear when a book is clicked, so I’m happy. :slight_smile:

Var f As FolderItem
Var textInput As TextInputStream
Var rowFromFile As String
var fields() as string
Var i As Integer
var counter as integer

f = New FolderItem("c:/Bible_Study_Assistant/data/books-and-chapters.txt")

textInput = TextInputStream.Open(f)
While Not textInput.EndOfFile
  rowFromFile = textInput.ReadLine
  counter=counter+1
  fields = rowFromFile.split(",")
  ChapterNumbers(counter)=fields(0)
  BookAbbrev(counter)=fields(1)
  BookShort(counter)=fields(2)
  bookLong(counter)=fields(3)
  QuickBookEntry(counter)=fields(4)
Wend
textInput.Close

for counter=1 to 39
  nav1LT.AddRow(booklong(counter))
  if counter<28 then nav2LT.AddRow(booklong(counter+39))
next
1 Like

Wow, why do all these tutorial videos use ‘var’ when ‘static’ is the declaration method most people will use for large apps? Starting people off on the wrong foot.

‘static’ is rarely needed. The job of ‘static’ in other languages is mostly done by Properties in Xojo. A typical project for me has hundreds of 'var’s but only 3 'static’s, and those three are always the same: a couple of small utility methods in my helper library use it for optimization. Outside of those two methods, I haven’t used ‘static’ in longer than I can remember.

2 Likes

Yes I agree. Having become more familiar with this, Properties and var are the main declaration operations, which is why they should have Properties front and center in the tutorials.