Program start

Post

Posted
Rating:
#1 (In Topic #132)
Avatar
Guru
cogier is in the usergroup ‘Guru’
Has anybody go a way to start a Sub without coming back to Sub Form_Open(). I can do it with a Timer, as below, but it seems to me there should be an easier way.

Code (gambas)

  1.  
  2. Public Sub Form_Open()
  3.  
  4.   Timer1.Trigger
  5.  
  6.  
  7.  
  8.   Print "Hello world!"
  9.  
  10.  
  11. Public Sub Timer1_Timer()
  12.  
  13.  
  14.  
  15.  
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
jornmo is in the usergroup ‘Regular’
Can you elaborate on what it is you want to accomplish? Why is it that Form_Open() is not sufficient? You could call it from a different class or module if you make it public.

You can also call it at the constructor, a.k.a. _new() (probably _init() and _ready() as well).

Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
OK here is what I am working on. If you Rem out line 30 and run the program you will see the issue.
Attachment
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
jornmo is in the usergroup ‘Regular’
Line 30?

Code (gambas)

  1. Public Sub BuildForm()                        'To add items to the Form

I do still not follow you friend  :)

Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Guru
cogier is in the usergroup ‘Guru’
Sorry. It's the last line in  

Code (gambas)

  1. Public Sub Form_Open()

Code (gambas)

  1. hTimer1.trigger
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
jornmo is in the usergroup ‘Regular’
Have you uploaded the same version? The code you gave me calls BuildForm, which in turn calls AddTimer which again calles hTimer.Start…

Anyway… I still do not know why you want to avoid this? Can you tell me like I am five years old, haha  :D

Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Guru
cogier is in the usergroup ‘Guru’
Opps! :o

Sorry I uploaded an earlier version :roll:

Please see attached..

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Regular
jornmo is in the usergroup ‘Regular’
I did not fully understand your code, but I tried to make a variant to what it seems you try to achieve:

Attachment

Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Guru
cogier is in the usergroup ‘Guru’
 I had a look at your code which works as I would expect. I just can't work out why mine needs a 'Trigger' to display.
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
jornmo is in the usergroup ‘Regular’
I added this code into the top of your RebuildForm sub:

Code (gambas)

  1. Debug "Rebuilding form", hPlayAreaPanel.W, hPlayAreaPanel.H

and it says you panel is 8x8. That's probably the problem. Now to find out why it does not fit the FMain's proportions :)

Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Regular
jornmo is in the usergroup ‘Regular’
The 'bug' is a big mystery, but this 'solves' the issue:

Remove the FMain's Arrangement from the BuildForm() sub, remove the trigger timer, and replace the BuildPlayArea() sub with this:

Code (gambas)

  1. Public Sub BuildPlayArea()                                      
  2.  
  3.   hPlayAreaPanel = New Panel(Me)                                
  4.   With hPlayAreaPanel
  5.     .Arrangement = Arrange.Row                      
  6.     .Expand = True                                    
  7.     .BackGround = Color.Blue
  8.     .W = Me.W - Me.Padding * 2
  9.     .H = Me.H - Me.Padding * 2
  10.   Me.Arrangement = Arrange.Vertical
  11.  
  12.  

… and voila… don't ask me why :)

Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Guru
cogier is in the usergroup ‘Guru’
 Thanks Jornmo. That seems to have done the trick. I needed to make a few more alterations but it does not require a trigger any more. I wonder if the Form Arrangement at that late point refreshes the Form?

Update

The display does not regenerate when rebuilt at the end of a game. Looking into it..
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Guru
cogier is in the usergroup ‘Guru’
I was playing with something else and I discovered that the following code will leave the Form_Open() routine without using a Timer.
You can also try Form_GotFocus() instead of Form_Show().

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3. Print "Hello"
  4.  
  5.  
  6. Public Sub Form_Show()
  7.  
  8. Print "I got here"
  9.  

Output: -
Hello
I got here
Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Regular
jornmo is in the usergroup ‘Regular’
 But, its still more of a hack than a proper understanding of the real problem.
I think it has to do with in what order Gambas arranges the controls on the form. It might be that for some reason that is not clear, your subs are called in a different order than expected. You can try using breakpoints to follow (use step/next buttons beside the run button) Gambas' way through the code. You can also enable profiling to see how many times each sub is called.

Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Guru
cogier is in the usergroup ‘Guru’
OK I have bumped into this again and my tricks don't work in this case. Have a look at the attached dice simulation. Can it be made to work without the Timer?

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#16
Avatar
Regular
jornmo is in the usergroup ‘Regular’
For example:

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim siCount As Short
  4.  
  5.   FMain.Show
  6.  
  7.   For sicount = 1 To 6
  8.     Button1.text = Str(siCount)
  9.     Wait 0.1
  10.   Next
  11.  
  12.   Button1.text = Rand(1, 6)
  13.  
  14.    
  15.  

But, why?

Online now: No Back to the top

Post

Posted
Rating:
#17
Avatar
Guru
cogier is in the usergroup ‘Guru’
That's it, you've cracked it! The FMain.Show is the answer. I didn't think of that. Thanks.
Online now: No Back to the top

Post

Posted
Rating:
#18
Avatar
Regular
jornmo is in the usergroup ‘Regular’
 Still, this hack was not necessary in the example I made for you, so either there's a bug somewhere, or there's something funny in the way you construct your form (that I cannot see).

Online now: No Back to the top

Post

Posted
Rating:
#19
Avatar
Guru
cogier is in the usergroup ‘Guru’
I thought you might have a point about the way I put the form together so I tried a new project with code only and it's still the same and wont work without the 'Me.Show' line.

Code (gambas)

  1. Public Sub Form_Open()
  2. Dim hButton As Button
  3. Dim siCount As Short
  4.  
  5.   .Arrangement = Arrange.Vertical
  6.   .padding = 5
  7.   .H = 200
  8.   .W = 200
  9.  
  10. hButton = New Button(Me)
  11. With hButton
  12.   .expand = True
  13.   .Font.bold = True
  14.   .Font.size = 100
  15.  
  16. Me.Show
  17.  
  18. For siCount = 10 DownTo 0
  19.   hButton.Text = Str(siCount)
  20.   Wait 0.2
  21.  
Online now: No Back to the top

Post

Posted
Rating:
#20
Avatar
Regular
jornmo is in the usergroup ‘Regular’
No, in this example it will not, and that is how it is supposed to be. But, the drawing of you puzzle game form is a bit different from this, and should to my understanding not need a timer, as I have shown with my own code.

Online now: No Back to the top
1 guest and 0 members have just viewed this.