You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Blue Blazes

Beginner

  • "Blue Blazes" started this thread

Posts: 15

Date of registration: Aug 14th 2009

  • Send private message

1

Wednesday, August 19th 2009, 9:38pm

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.

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Wednesday, August 19th 2009, 10:39pm

Hi,
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

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

3

Thursday, August 20th 2009, 12:40am

Quoted

I am not sure, by the way, if Jabaco supports static methods.
Supported in two ways: Modules and the "static"-attribute within a class-module.

Blue Blazes

Beginner

  • "Blue Blazes" started this thread

Posts: 15

Date of registration: Aug 14th 2009

  • Send private message

4

Thursday, August 20th 2009, 1:50am

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 ?(

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

5

Thursday, August 20th 2009, 12:54pm

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:

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

Blue Blazes

Beginner

  • "Blue Blazes" started this thread

Posts: 15

Date of registration: Aug 14th 2009

  • Send private message

6

Thursday, August 20th 2009, 1:46pm

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.

Blue Blazes

Beginner

  • "Blue Blazes" started this thread

Posts: 15

Date of registration: Aug 14th 2009

  • Send private message

7

Thursday, August 20th 2009, 1:48pm

Sorry, example is:

Public Sub cmdWindow_Click()
MyWindow = New frmWindow
MyWindow.Show
End Sub

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

8

Thursday, August 20th 2009, 2:38pm

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

  • "santiago.barreiro" is male

Posts: 14

Date of registration: Jan 29th 2010

Location: Guayaquil, Ecuador

Occupation: Manager of a software company

Hobbies: Music player

  • Send private message

9

Friday, January 29th 2010, 7:25pm

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

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

10

Friday, January 29th 2010, 9:33pm

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:

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

  • "santiago.barreiro" is male

Posts: 14

Date of registration: Jan 29th 2010

Location: Guayaquil, Ecuador

Occupation: Manager of a software company

Hobbies: Music player

  • Send private message

11

Saturday, January 30th 2010, 3:15am

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

Rate this thread
WoltLab Burning Board