Declaring and Use of Variables

Can anyone help me with multi-dimensional arrays?

I need to create a 3 dimensional array as a Property with upper bounds of variable(2000,50,20)
Not sure how to do this.

what is the meaning of 2000,50,20
usually u not need a fix ubound.
and i guess you get a better solution with classes.

2000,50,20 are the number of variables which will go into each array position.

Need to know how to declare a 3 dimensional array.

it is mentioned here
https://documentation.xojo.com/api/language/arrays.html

i thought more 2000 = books, 50 = pages, 20 = markings or answer like this.

Yes, but the documentation doesn’t say how to create a 3 dimensional array as a property. I need the array to be used by my whole app and not just one control

you mean this?


1 Like

Great. That works perfectly. Thanks! :slight_smile:
I was trying Untitled(,) and Xojo was rejecting it.
In C# it’s valid but evidently the limits have to be explicit in Xojo.

This is a good starting point for understanding classes and objects.

https://documentation.xojo.com/getting_started/object-oriented_programming/oop_classes.html

3 Likes

ah ok
empty would be
Untitled(-1,-1,-1)
because the index is from 0 to count-1

1 Like

But what are these?
If they represent 2000 buses, then they may each have 50 passengers
The passengers may have 20 phone contacts

In this case, you may be better off considering a passenger class.
The passenger class has an array or dictionary property to hold the contacts

The bus class has an array or dictionary of passengers

So you set it up like this:

var Buses() as BusClass
for x as integer = 0 to 1999
     var bc_obj as new busClass
 Buses.append bc_obj

     // add passengers here if you like
    //or do it later

    //example
     var po as new passenger // creates a passenger, initialises the contacts to empty
      po.AddContact "Fred"
     bc_obj.AddPassenger bc_obj


next
4 Likes

Thanks. This is useable :slight_smile:

Thanks Jeff. I was reading through the forum and it seems that the dictionary class is the route to take.
Your example is very interesting - will have to experiment with it. Certainly something new for me.

How would I adapt this for reading from a text file that is comma delineated?
Most of my data is stored in external text files that are either single lines, or columns of data - sometimes read into individual strings else into arrays.

I’m a bit at sea with this. The code needs to read 2000 lines of text and separate 4 fields from each line into their variables.

var f as FolderItem
var t as integer
var bookField1(2000) as string
var bookField2(2000) as string
var bookField3(2000) as string
var bookField4(2000) as string
Var comma As String = ChrB(44)
Var rowFromFile

f="c:/books/data/books-and-chapters.txt"

var input As TextInputStream
input = TextInputStream.Open(f)

For t = 1 To 2000
rowFromFile = textInput.ReadLine
****Not sure what to put here****
next
textInput.Close

Well again, ‘it depends’
What lives in ‘bookfield’?
To me this looks like 4 attributes of a book.
Author, ISDN, pagecount, Title ?

If so, create a Book class
Give it these properties
Read the 2000 rows.
Create a new book object , set the attributes, add to an array

BUT.
‘it depends’

Frankly, armed with that 2000 row text file, Id me more tempted to put it into an in-memory SQLite database

From the 2000 books, you can then instantly do a query to return all the books by Stephen King, or ones with a page count > 500, or with ‘Cuckoo’ in the title.

What do the first 3 rows of that test file look like,
and what (ultimately) will your app do with this list?

1 Like

Aren’t we all :wink:. I understand how frustrating it is coding with a new language/system and you can’t easily get your code working because of the lack of knowledge and experience.

Well I have used VB 5 and VB 6. Both have classes - even VBA ! - but you can create an application without ever creating a class. VB .Net is OOP as well as Xojo: you need to use classes.

What ??? In Xojo you can’t create a procedural app.

To add on to what Jeff has said, the beauty of making a Book class is that you could start off doing it with properties to get going, but then change it to use a database later if you decide you need those features (or once you learn enough to feel comfortable moving on to databases). You wouldn’t have to change the rest of your code, just write a new Book class and swap it out.

1 Like

So the one app I’m doing is an adaption of my Bible app which will access the book and article data directly and use sections and keyphrases / tags for locations.
Here is the data I use to index the Bible (first 7 lines)

50,gen,Gen,Genesis,ge
40,exo,Exo,Exodus,ex
27,lev,Lev,Leviticus,le
36,num,Num,Numbers,nu
34,deu,Deut,Deuteronomy,de
24,jos,Josh,Joshua,jos
21,jud,Judg,Judges,judg

The principle is the same. Each variable is unique and used in different parts of the app for various purposes.

  1. Number of chapters.
    2 short string identifier name
  2. Short Display name
  3. Fullname
  4. Quick Entry string, ie. the minimum number of characters needed to identify the book.

The database idea is really interesting but think it would be more long term though.

Lots of redundancy here.
A database holding

50,Genesis
40,Exodus
27,Leviticus
36,Numbers
34,Deuteronomy
24,jJoshua

Is all you need.

Select * from books where name like 'Deu%'

will get you a record holding 34,Deuteronomy

Want a list of just the short books?

Select * from books where chaptercount < 25

Anything with a v in the name?

Select * from books where name like '%v%'

1 Like

I’m pretty sure any dev language can be adapted for procedural use. ^^
VB6 is Object driven but the pure modern-day mechanics of OOP are lacking or absent.
Xojo as far as I can see can either be used for OOP or procedural. I don’t see any barriers to that.

Unfortunately as I’m self taught, I’m more results driven rather than worrying about how my code adheres to certain standards. Having said that, I do try to make my code -

  1. Neat
  2. Readable
  3. Referable
  4. Streamlined
  5. Adaptable
  6. Expandable
  7. Manageable

For many parts I could be using a more correct syntax, but my coding has improved considerably from what it was. My coding friend from college (who happened to come first in South Africa for all the languages he took) used to look at me like I was sacrilegious moron, which looking back was an accurate summation. Sometimes I’m very hasty to get things done and use what I call ‘force programming’, where coding and patches are added until the results are correct, however knowing that if the dataset differed out of the known norms there would be diverging results and errrors. When I use this technique I go back, analyse everything and make it as perfect as possible. Note that sometimes you learn more this way. Also it can be more of a headache.