Click to See Complete Forum and Search --> : A little problem using MDI form


yuenchichi
October 21st, 2001, 01:49 AM
Dear all,
I have developed a MDI form and one child form. And also, I placed a text box and one timer control in the child form. I have created the object variable and created the new object instance to show the child form. The question is if I called several instances of the form, how does it increment by 1 and place it to the text box independently based on the duration of the timer.
For example:

'Somewhere in module and calling from the timer
'event
public i as Integer
Public sub SetText()
i = i+1
form1.text1.text = i
End Sub

I know that this sub has an error here, please help me to find out. Thanks

JHamilton
October 21st, 2001, 04:56 PM
First off, why are you using a timer in the child form? That timer event will fire on all of them. You'll start getting exponential amounts of child forms. Unless, of course, that is what you want. I would put the timer on the parent.

Secondly, your variable "i" will always reset to its default value unless you make it static. I would do something along the lines of:

public static Sub SetText()
Dim i as Integer
i = i + 1
Form1.Text1 = i
End Sub




Try to avoid using global variables.

I wouldn't use the timer to randomize the position of the text box as it may go outside the height/width parameters of the form. Instead, I would use something like this in your child form's load event:

private Sub Form_Load()
Randomize
Text1.Top = Int((me.Height - Text1.Height - 50) * Rnd)
Text1.Left = Int((me.Width - Text1.Width - 50) * Rnd)
End Sub




Software is like sex, it's better when it's free - Linus Torvalds
Software is like sex, it's better when I get paid for it. - me