All forms load, but only one form.Show executes
Greetings,
My project view looks like this:
.Project
....Forms
........frmAbout
........frmTest
........frmWindow
....Modules
........Test
And the Test module is:
Public frmTest As New frmTest
Public frmAbout As New frmAbout
Public frmWindow As New frmWindow
Public Sub main(ByJava args() As String)
Dim myArgs() As String
myArgs = args
frmTest.SetDefaultClose()
frmTest.Show()
End Sub
I have written many VB6 programs, but not familiar with Public ... New syntax, or Class Modules. I saw Public ... New in Jabaco samples and copied it.
Only the frmTest.Show executes, but all three forms load together. The other two forms have .Show on command buttons in frmTest. How do I fix this? How to get control of form loads?
If I comment out the Public ... New for frmAbout and frmWindow, then I get the compiler message "Expected: Static Method" for the frmAbout.Show statement.
I appreciate a helping hand. Thank you.
My project view looks like this:
.Project
....Forms
........frmAbout
........frmTest
........frmWindow
....Modules
........Test
And the Test module is:
Public frmTest As New frmTest
Public frmAbout As New frmAbout
Public frmWindow As New frmWindow
Public Sub main(ByJava args() As String)
Dim myArgs() As String
myArgs = args
frmTest.SetDefaultClose()
frmTest.Show()
End Sub
I have written many VB6 programs, but not familiar with Public ... New syntax, or Class Modules. I saw Public ... New in Jabaco samples and copied it.
Only the frmTest.Show executes, but all three forms load together. The other two forms have .Show on command buttons in frmTest. How do I fix this? How to get control of form loads?
If I comment out the Public ... New for frmAbout and frmWindow, then I get the compiler message "Expected: Static Method" for the frmAbout.Show statement.
I appreciate a helping hand. Thank you.
Hi,
I've entered the following:
In Form1, I have the following code:
When I click button Command1 on Form1, I get Form2. No problem.
It is a bit misleading to name variables exactly like their respective class names.
The line "Public frmWindow As New frmWindow" means that you have a variable "frmWindow" of class "frmWindow".
The "New" calls the constructor of class frmWindow and returns the instantiated class as object.
The variable is visible for all source modules due to the "Public" scope.
If you comment out the line, you don't have any instantiation of your form. So there is no way to show it.
A "static method" is a method which does not depend on a specific object but is executed for the whole class.
Static methods must not access any dynamic member variables (i.e. object properties) of the class.
I am not sure, by the way, if Jabaco supports static methods.
Does this help you?
My suggestion is to name your form variables different from your form classes,
Example: "Public myWindow as New frmWindow"
If this is clearer to you, write it in two lines:
Public myWindow as frmWindow
myWindow = New frmWindow
Note that Jabaco has dropped the "set" which used to be mandatory for assignments to objects in VB6.
To launch this form, you would code "myWindow.Show".
How is that?
A1880
I've entered the following:
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 |
Public Form1 As New Form1 Public Form2 As New Form2 Public Form3 As New Form3 Public Sub main(ByJava args() As String) Dim myArgs() As String myArgs = args Form1.SetDefaultClose() Form1.show() End Sub |
In Form1, I have the following code:
|
|
Source code |
1 2 3 |
Public Sub Command1_Click() Form2.Show End Sub |
When I click button Command1 on Form1, I get Form2. No problem.
It is a bit misleading to name variables exactly like their respective class names.
The line "Public frmWindow As New frmWindow" means that you have a variable "frmWindow" of class "frmWindow".
The "New" calls the constructor of class frmWindow and returns the instantiated class as object.
The variable is visible for all source modules due to the "Public" scope.
If you comment out the line, you don't have any instantiation of your form. So there is no way to show it.
A "static method" is a method which does not depend on a specific object but is executed for the whole class.
Static methods must not access any dynamic member variables (i.e. object properties) of the class.
I am not sure, by the way, if Jabaco supports static methods.
Does this help you?
My suggestion is to name your form variables different from your form classes,
Example: "Public myWindow as New frmWindow"
If this is clearer to you, write it in two lines:
Public myWindow as frmWindow
myWindow = New frmWindow
Note that Jabaco has dropped the "set" which used to be mandatory for assignments to objects in VB6.
To launch this form, you would code "myWindow.Show".
How is that?
A1880
Thank you again for the prompt response to my problem. I have converted the class statements to use different names, as follows:
Public MyTest As New frmTest
Public MyAbout As New frmAbout
Public MyWindow As New frmWindow
Public Sub main(ByJava args() As String)
Dim myArgs() As String
myArgs = args
MyTest.SetDefaultClose()
MyTest.Show()
End Sub
and frmTest says:
Public Sub cmdAbout_Click()
MyAbout.Show
End Sub
Public Sub cmdWindow_Click()
MyWindow.Show
End Sub
--------------------------------------------------------------------------------------------------
However, the problem still occurs. All three forms display at once.
So, I set breakpoints and learned that the run sequence is:
--------------------------------------------------------------------------------------------------
1. frmTest
Public Sub Form_Load()
...
End Sub
2. frmAbout
Public Sub Form_Load()
...
End Sub
3. frmWindow
Public Sub Form_Load()
...
End Sub
and finally
4. main
Public Sub main(ByJava args() As String)
Dim myArgs() As String
myArgs = args
MyTest.SetDefaultClose()
MyTest.Show()
End Sub
I am still doing something wrong to cause all forms to load at the beginning, even before Sub main executes.
Thank you
Public MyTest As New frmTest
Public MyAbout As New frmAbout
Public MyWindow As New frmWindow
Public Sub main(ByJava args() As String)
Dim myArgs() As String
myArgs = args
MyTest.SetDefaultClose()
MyTest.Show()
End Sub
and frmTest says:
Public Sub cmdAbout_Click()
MyAbout.Show
End Sub
Public Sub cmdWindow_Click()
MyWindow.Show
End Sub
--------------------------------------------------------------------------------------------------
However, the problem still occurs. All three forms display at once.
So, I set breakpoints and learned that the run sequence is:
--------------------------------------------------------------------------------------------------
1. frmTest
Public Sub Form_Load()
...
End Sub
2. frmAbout
Public Sub Form_Load()
...
End Sub
3. frmWindow
Public Sub Form_Load()
...
End Sub
and finally
4. main
Public Sub main(ByJava args() As String)
Dim myArgs() As String
myArgs = args
MyTest.SetDefaultClose()
MyTest.Show()
End Sub
I am still doing something wrong to cause all forms to load at the beginning, even before Sub main executes.
Thank you
Hi,
you are right! The "New" of a Form initiates a "Form_Load" of this form
I figure, "Show" is just the opposite of "Hide". So, a form is loaded in the first place to initialize it.
To avoid loading all three forms, I'd suggest the following:
The "MyForm2 = New Form2" should be executed right before the first "MyForm2.Show".
OK?
A1880
you are right! The "New" of a Form initiates a "Form_Load" of this form
I figure, "Show" is just the opposite of "Hide". So, a form is loaded in the first place to initialize it.
To avoid loading all three forms, I'd suggest the following:
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 |
Public MyForm1 As New Form1 Public MyForm2 As Form2 Public MyForm3 As Form3 Public Sub main(ByJava args() As String) Dim myArgs() As String myArgs = args MyForm1.SetDefaultClose() MyForm1.show() End Sub |
The "MyForm2 = New Form2" should be executed right before the first "MyForm2.Show".
OK?
A1880
Yes, A1880, I placed MyWindow = New frmWindow on the test form's Click() event as follows:
Public Sub cmdAbout_Click()
MyWindow = New frmWindow
MyWindow.Show
End Sub
And this idea does load the forms "only" when clicked. Thank you!
1. In VB6, all this is possible without creating new class objects, etc. It is possible to work with original forms only. Perhaps, this isn't possible with Jabaco? I was thinking of these extra conversion steps to migrate from VB6 to Jabaco.
2. In this example, the forms are not "modal". What is the syntax to load these forms "modal" (process one copy at a time)?
3. I wish to make certain that I added these existing forms correctly to the test project. I clicked "Add File" in the Project window. Then I clicked "Add File" in the dropdown window, and finally I browsed and selected the forms I needed. I hope this is correct.
4. One final question. If I would wish to remove a form or a module from the project, I right click the member and click "Delete". What is the difference between answering "Yes" asnd answering "Permanent"?
Thank you, so much, A1880.
Public Sub cmdAbout_Click()
MyWindow = New frmWindow
MyWindow.Show
End Sub
And this idea does load the forms "only" when clicked. Thank you!
1. In VB6, all this is possible without creating new class objects, etc. It is possible to work with original forms only. Perhaps, this isn't possible with Jabaco? I was thinking of these extra conversion steps to migrate from VB6 to Jabaco.
2. In this example, the forms are not "modal". What is the syntax to load these forms "modal" (process one copy at a time)?
3. I wish to make certain that I added these existing forms correctly to the test project. I clicked "Add File" in the Project window. Then I clicked "Add File" in the dropdown window, and finally I browsed and selected the forms I needed. I hope this is correct.
4. One final question. If I would wish to remove a form or a module from the project, I right click the member and click "Delete". What is the difference between answering "Yes" asnd answering "Permanent"?
Thank you, so much, A1880.
Modal Forms again
Please have a look here.
You may find the "search" function of this board worth trying.
It helps you to spot existing solutions and hints.
Happy digging!
A1880
You may find the "search" function of this board worth trying.
It helps you to spot existing solutions and hints.
Happy digging!
A1880
Beginner
Hello all!
So far (about 30 minutes) I have enjoy the similarity with VB6 in the environment.
But also, the first problem also encounter. I Placed two command buttons in the
form, it does compile without errors, but one the first one show. I tested a text
box for the second one, and also it did not show.
What is the problem?
Regards
Santiago
So far (about 30 minutes) I have enjoy the similarity with VB6 in the environment.
But also, the first problem also encounter. I Placed two command buttons in the
form, it does compile without errors, but one the first one show. I tested a text
box for the second one, and also it did not show.
What is the problem?
Regards
Santiago
Please explain your problem in a bit more detail.
You have placed two buttons on one common form.
What should happen if you press the first button?
What should happen when pressing the second button?
What role does the textbox play?
Normally your code should look similar to this:
Happy experimenting!
A1880
You have placed two buttons on one common form.
What should happen if you press the first button?
What should happen when pressing the second button?
What role does the textbox play?
Normally your code should look similar to this:
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Option Explicit
Public Sub Command1_Click()
MsgBox "pressed button 1"
End Sub
Public Sub Command2_Click()
MsgBox "pressed button 2"
End Sub
Public Sub Text1_Click()
MsgBox "clicked in textbox Text1"
End Sub
Public Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
MsgBox "ended Text1 entry with enter key"
End If
End Sub
Public Sub Form_Load()
Text1.Text = "some text"
End Sub
|
Happy experimenting!
A1880
Beginner
HELLO A1880... Thank you for you fast response.
Yes, that is exactly the case. And even further... I just re-open the proyecto, place a new command button and it did work. In fact, I placed (yesterday) a second text box and a second list and it did not show neither, but now the they all show.
I have kept programming in order to confirm if my main requirements work for me, and the are find.
I have another question, in regard to serial ports, but I will place them in the proper thread.
Regards
Santiago
Yes, that is exactly the case. And even further... I just re-open the proyecto, place a new command button and it did work. In fact, I placed (yesterday) a second text box and a second list and it did not show neither, but now the they all show.
I have kept programming in order to confirm if my main requirements work for me, and the are find.
I have another question, in regard to serial ports, but I will place them in the proper thread.
Regards
Santiago
Similar threads
-
General topics, questions and discussions »-
Quick question: Form Load()
(Aug 17th 2009, 2:06am)
-
General topics, questions and discussions »-
Icons
(Jul 10th 2009, 4:58pm)
-
General topics, questions and discussions »-
File operations don't work for me
(Dec 14th 2008, 7:32pm)
-
Allgemeine Themen, Fragen und Diskussionen »-
Allgemeine Fragen zu Forms (Open und Close)
(Nov 25th 2008, 11:07am)
