B4J Question How to set column names on a list

Mikelgiles

Active Member
Licensed User
Longtime User
I have a list with multiple columns and I want to use SortType which requires a column name. I know how to set them on a table but I cannot figure out how to set them on a list.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hi Mikel!

The SortType function uses a special variable called type
(If you write type in the searchbox in the forum you will see this information)

Type
Declares a structure.
Can only be used inside sub Globals or sub Process_Globals.
Syntax:
Type type-name (field1, field2, ...)
Fields include name and type.
Example:
Type MyType (Name As String, Items(10) As Int)
Dim a, b As MyType
a.Initialize
a.Items(2) = 123

Declare the type.
Create one or more variables with that type.
Store them on a list
And you use the SortType function
(The column you use for the type is the name of the field)
 
Upvote 0

Mikelgiles

Active Member
Licensed User
Longtime User
Enrique, Thanks. You have been a great help!

I am wondering if SortType will even work with what i am doing. I am using
B4XSerializator that Erel suggested would work for saving a multi column list. I decided to test using a list for all the underlying functions and just re-displaying the data in a TableView after any changes to the list. My understanding is that a TableView is just a way of displaying the data in a list anyway. The master table needs to be editable on several columns, sortable on those same columns, filtered on a few columns, and saved back to disk. I was thinking about doing all of these functions to the master list and only use the master view to show the results. At this point this is just a trial to see if this is a good way to go.

'Process_Globals
Private ser As B4XSerializator
Private lstMaster As List

'here is how I am getting the list off of disk
lstMaster = ser.ConvertBytesToObject(Bit.InputStreamToBytes(File.OpenInput(dirData, "CashFlow.dat")))

'here is how i am putting it back on disk
Dim out As OutputStream = File.OpenOutput(dirData, "CashFlow.dat", False)
Dim byt() As Byte = ser.ConvertObjectToBytes(lstMaster)
out.WriteBytes(byt, 0, byt.Length)
out.Close

Is it possible to use SortType ( or any kind of sort) When building the list like this?

Mikel
 
Upvote 0

Mikelgiles

Active Member
Licensed User
Longtime User
I have tried to figure out what I am doing wrong for several days now.
I get a error every time I try to use SortType on a list. I have stripped out most of the code in the app leaving only the parts needed to show the error. I think I must be missing something easy. I have included the source and have remarked where I get the error. Look for 'always a error on this line in the code'

Also getting a error on another line but only when I dont pause. It looks like I am trying to use the list before the previous reference to the list has finished. Is it possible that the ConvertBytesToObject does not hold while the process is completing or is it more likely that I have a computer problem? Look for 'If I dont pause here I get errors on' in the code.
 

Attachments

  • CashFlow.zip
    3.3 KB · Views: 201
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hi mikel!
i just downloaded your file and an error ocurred because it cannot find the .dat file, You can attach it with fake data if you want!
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Mikel
The problem is in how you are saving the .dat file, you are still saving the list with arrays and not with the masterflds type.

Yet its easy to convert the Arr into a Mf. look at the sub arrToMf
 

Attachments

  • CashFlow.zip
    22.5 KB · Views: 218
Upvote 0
Top