Program to big,redundent!

cdeane

Member
Hello all,

Up front I want to say Im new to B4ppc.
I just finished my first program using B4ppc for my ppc
(its huge).
After I learned a few things I knew most of it was redundant.
60 to 80% must be all nummpads(I dont want to use the keypad In
my ppc).

I know now Ill need at least 5 to 8 Forms in my program and that I

will need to write some controls at run time.As you may have guesset
I worked soley with visual designer in my last program.

If I could ask for some held in this area it would be greatly
apreciated.
I think if I got off to yhe right start I could take it from there.

Main problem:
Form1 three Buttons(plus exit and enter,as exit and enter will be
in most all the forms).

form1.
button1,button2 and button3

Button1,2 and 3 will load a form with numberd buttons 0 through 9
along with the usaual exit and enter buttons and textbox to see what
buttons were clicked.This will be my numpad(EX:Formnum).
I would like to use this to give the indevisual button.text a
difrent value when I use the Enter button to load the textbox.text in
to the button I used to load the numpad in the first place.

I would like to ask that ANY and ALL input would be very helpfull
as it may help in my understanding in this prosses.

Please forgive any long awaited reply,for my wife tells me the
grass needs attending in the back 40.
 

cdeane

Member
for i = 0 to alTextBox.Count -1 'Adds the gotfocus event to all textboxes.

Please explane (i) and (-1)

What will that do for me.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
[SIZE=2]alTextBox.Add("textbox1") [/SIZE][SIZE=2][COLOR=#008000]'Textboxes names. Must be lower case. You can add as many as you like.[/COLOR][/SIZE]
[SIZE=2]alTextBox.Add("textbox2")[/SIZE]
[SIZE=2]alTextBox.Add("textbox3")[/SIZE]
[SIZE=2]alTextBox.Add("textbox4")[/SIZE]
[SIZE=2][COLOR=#0000ff]for [/COLOR][/SIZE][SIZE=2]i = 1 [/SIZE][SIZE=2][COLOR=#0000ff]to [/COLOR][/SIZE][SIZE=2]11 [/SIZE][SIZE=2][COLOR=#008000]'Adds the click event to all regular number buttons.[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][SIZE=2]("Button" & i, Click, "Numbers_Click")[/SIZE]
[SIZE=2][COLOR=#0000ff]next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for [/COLOR][/SIZE][SIZE=2][COLOR=#000000]i = 0 [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]to [/COLOR][/SIZE][SIZE=2][COLOR=#000000]alTextBox.Count -1 [/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Adds the gotfocus event to all textboxes.[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][SIZE=2][COLOR=black](alTextBox.Item(i),GotFocus, "TextBoxes_GotFocus")[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]next[/COLOR][/SIZE]
[SIZE=2][COLOR=black]focused = alTextBox.Item(0)[/COLOR][/SIZE]
[COLOR=black][SIZE=2]Control[/SIZE][SIZE=2](focused).Focus[/SIZE][/COLOR]
[/COLOR][/SIZE]
In this example the numpad is being used to edit four textboxes.
First we add the textboxes names to an arraylist (alTextBox).
The second For loop connects all the textboxes GotFocus event with Sub TextBoxes_GotFocus. The other option is to manually create one sub for each control (with duplicated code).
At the end of this code we use the global variable 'focused' with the Control keyword to set the focus to the first textbox.
I recommend you to go over the help of Control and AddEvent which both are very useful for working with a large number of similar controls.
 

cdeane

Member
B4X:
[SIZE=2]alTextBox.Add("textbox1") [/SIZE][SIZE=2][COLOR=#008000]'Textboxes names. Must be lower case. You can add as many as you like.[/COLOR][/SIZE]
[SIZE=2]alTextBox.Add("textbox2")[/SIZE]
[SIZE=2]alTextBox.Add("textbox3")[/SIZE]
[SIZE=2]alTextBox.Add("textbox4")[/SIZE]
[SIZE=2][COLOR=#0000ff]for [/COLOR][/SIZE][SIZE=2]i = 1 [/SIZE][SIZE=2][COLOR=#0000ff]to [/COLOR][/SIZE][SIZE=2]11 [/SIZE][SIZE=2][COLOR=#008000]'Adds the click event to all regular number buttons.[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][SIZE=2]("Button" & i, Click, "Numbers_Click")[/SIZE]
[SIZE=2][COLOR=#0000ff]next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for [/COLOR][/SIZE][SIZE=2][COLOR=#000000]i = 0 [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]to [/COLOR][/SIZE][SIZE=2][COLOR=#000000]alTextBox.Count -1 [/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Adds the gotfocus event to all textboxes.[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][SIZE=2][COLOR=black](alTextBox.Item(i),GotFocus, "TextBoxes_GotFocus")[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]next[/COLOR][/SIZE]
[SIZE=2][COLOR=black]focused = alTextBox.Item(0)[/COLOR][/SIZE]
[COLOR=black][SIZE=2]Control[/SIZE][SIZE=2](focused).Focus[/SIZE][/COLOR]
[/COLOR][/SIZE]
In this example the numpad is being used to edit four textboxes.
First we add the textboxes names to an arraylist (alTextBox).
The second For loop connects all the textboxes GotFocus event with Sub TextBoxes_GotFocus. The other option is to manually create one sub for each control (with duplicated code).
At the end of this code we use the global variable 'focused' with the Control keyword to set the focus to the first textbox.
I recommend you to go over the help of Control and AddEvent which both are very useful for working with a large number of similar controls.
First we add the textboxes names to an arraylist (alTextBox).


Thanks Erel,
Thats what I needed.

Just need a little nug now and then.
 

cdeane

Member
Sorry for the extinsive quote.
Ill better my threads,replyes and quotes in the future.
 
Top