Other structure my code

hub73

Active Member
Licensed User
Longtime User
Hi !
As i've now a lot of dim ... as edittext on my main file code, i'm searching a way to better structure my code.

I know how to add code module and use some functions in it without GUI access. But i don't know how to 'extract the 'sub Globals' with the dim 'gui' items (edittext, button, ...)

My goal is to have for each data base form code inside it's own file :


B4X:
(form diaporama)

Dim Diaporama_title as Editext
Dim Diaporama_text as Editext
Dim Diaporama_button_save as Button
...

sub Diaporama_button_save_click()
..
..
end sub

sub diaporama_add_to_db (dsfds, fdsfsd)
..
...
end sub

Sub diaporama_Delete ...
End sub

(form articles)

Dim Articles_title as EditText
Dim Article_text as Editext

sub article_add ()
end sub

Hope you u
nderstand me with my poor english.


(as php include if you prefer !)

Thanks !
 
Last edited:

KMatle

Expert
Licensed User
Longtime User
Please use code tags (even if it's an example) :)

One way is:

- create a texfile where you define all the views with a form name (here you can define the names, input types, length, positions, ..., too)

Example:

B4X:
Form-Name      View-Number         View-Type   ....

Articles            1                Label
Articles            2                Edittext
Articels            3                Button

- when the app starts, load the file
- for each form create a panel (1 panel = 1 form) and create the views dynamically

Another
way is:

- Download all the Culumns of the database via HttpUtils/php (assuming you have 1 table for each object, like article). So you get the fields (= views) you need. Search Google how to select culumns from a table.

Pro:

- instead of the file in example 1 create an own table for your forms and download the definitions


At the end there is no perfect way. Play with it to see what is the best way for you.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Another way is to set the target view asva parameter when calling the custom class sub
 
Upvote 0

hub73

Active Member
Licensed User
Longtime User
Nice idea kMatle. But I've already all the forms (into bal files). In fact i just want organize my code and split the main code inside several 'code module' to avoid edit a long file ! it seems that you can't define the 'Dim Title as EditText' into another module than the main code 'sub Globals' ?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Why are all these *.bal in the same module? Seems to me that you could load a new activity for each of some of your bals since I think that these are all forms.
 
Upvote 0

hub73

Active Member
Licensed User
Longtime User
i load the '*.bal forms' into a panel.

(Main)

B4X:
select menu

case "dongle"
pnl_edition.LoadLayout ("bdd_dongle")

case "diaporama"
pnl_edition.LoadLayout ("bdd_diaporama")

end select
so i use only one activity.
 
Upvote 0
Top