PDA

Click to See Complete Forum and Search --> : Form Control


san_excalibur
Sep 2nd, 2011, 09:42 AM
Hello,

I have a question. I have a couple of forms in my VB6 project. I have also been able to compile the project to generate an executable. However, i'm not sure how i can control which form i want to have displayed first when the executable is launched.

Say for example, i have two forms, frmOne and frmTwo. By default, when i run the executable, frmOne is the first one that gets displayed. But what i wish to know is if it is possible to have frmTwo come up first when the program is launched.

Any help is appreciated.

Thanks!

si_the_geek
Sep 2nd, 2011, 09:48 AM
On the Project menu select Properties, then change the "Startup Object".

san_excalibur
Sep 2nd, 2011, 10:07 AM
Thanks for the reply si_the_geek. I have looked at the Properties under Project Menu. I found that for the Startup Object property, i have only two options in the drop down. One is 'None' and the other is 'Sub Main'. 'Sub Main' is a method right? I have looked at the forms and i can't seem to find where it is. Any advice?

si_the_geek
Sep 2nd, 2011, 10:20 AM
That is rather strange, the list normally contains "Sub Main" (which is a sub you create in a module) plus each of the forms in the project.

A quick check shows that you have probably created the 'wrong' kind of project. A normal project ("Standard Exe") shows them all, but others (such as "ActiveX Exe") show the list you are seeing.

I presume your project is an "ActiveX Exe", and unless you have a particular reason for choosing that I recommend you convert to a "Standard Exe" (you can select it next to the Startup Object).

san_excalibur
Sep 2nd, 2011, 10:22 AM
Yes, the project is an ActiveX Exe. I probably will change that. Thanks again!

san_excalibur
Sep 2nd, 2011, 10:31 AM
I'm afraid it has to be an ActiveX Exe.

san_excalibur
Sep 2nd, 2011, 10:55 AM
Question again.

I have a form, called say 'frmOne'. This 'frmOne' has a menu bar on the top, with options saying 'One', 'Two', 'Three'. When any of these menu options are clicked upon, other menu lists pop up with more options. I would like to get rid of some of the menu options and keep some intact. I am not sure how to control the menu items. Any help please?

Hack
Sep 2nd, 2011, 10:58 AM
Toggle their visible property perhaps?

san_excalibur
Sep 2nd, 2011, 10:58 AM
I think i might have figured it out.

Nightwalker83
Sep 4th, 2011, 01:49 AM
I think i might have figured it out.

If you have solved the problem please mark the thread "Resolved".

san_excalibur
Sep 6th, 2011, 11:27 AM
Actually, i'm not sure that i have resolved the issue. I can't seem to figure a way to control which form i want to display first when the application is run.

Another question: How can i delete a form from a VB6 project completely?

si_the_geek
Sep 6th, 2011, 12:25 PM
Actually, i'm not sure that i have resolved the issue. I can't seem to figure a way to control which form i want to display first when the application is run. Based on the options you've got, create a 'Sub Main' (and set it as the startup object), and in there have code to show the form you want.
Another question: How can i delete a form from a VB6 project completely?Go to the Project explorer window and right-click on the form, then select "Remove".

The file will still exist wherever it was (so you may want to find + delete it), but it will not be part of the project.

san_excalibur
Sep 6th, 2011, 01:14 PM
I'm sorry! I can't believe i'm this ignorant. I did right click on the form in the project explorer view, but i was looking for 'Delete', and i didn't pay attention to the 'Remove' option. Thanks si_the_geek!

I'm sorry i keep asking so many questions, but i have another one. I have a form, a very simple one with two command buttons that say 'Yes' and 'No'. What i want to do is when i click on 'Yes', i want to display another form.

I have tried 'frmName.Show', 'frmName.Show vbModal' and 'frmName.Show , Me' in the click event for that button, but it doesn't open up that form. Any help please?

Nightwalker83
Sep 7th, 2011, 02:31 AM
Check the form name of the second form and make sure it is spelt correctly.

Either of those should work.


Private Sub Command1_Click()
frmName.Show
End Sub


or


Private Sub Command1_Click()
frmName.Show vbModal, Me
End Sub

san_excalibur
Sep 7th, 2011, 10:16 AM
Thanks for the suggestion Nightwalker83. I have tried that. It doesn't seem to work though. Just to test, i tried to do that to other forms and it worked (the forms did show up), but it just doesn't work on the one form that i WANT to have show up on click of the button. Do you think there might be something stopping from that form from displaying?

Nightwalker83
Sep 7th, 2011, 08:16 PM
Would you mind uploading the project so I can have a look at it? There is probably a problem with the event registering.

san_excalibur
Sep 9th, 2011, 10:43 AM
Nightwalker83, i'm not sure if i can upload the project as of now. But i will probably do that at a later time necessary. I still haven't been able to make the 'frmName.Show' to work.

However, i have a function in frmName with the code below:
<code>
Public Sub ShowFrmName()
On Error GoTo ErrPtnr_OnError
'Exit Sub
50010 With Me
50020 .ZOrder
50030 .WindowState = vbNormal
50040 .Show
50050 End With
Exit Sub
ErrPtnr_OnError:
Select Case ErrPtnr.OnError("frmName", "ShowFrmName")
Case 0: Resume
Case 1: Resume Next
Case 2: Exit Sub
Case 3: End
End Select
End Sub
</code>

Notice that i commented out the 'Exit Sub' code on line 3 so the program flow doesn't really exit the function. So now when i go to another form (say frmTwo) with a command button, in the click event for this button i wrote this code:
frmName.ShowFrmName

So when i click on the button in frmTwo, it does reveal the form frmName. However, frmName is displayed for about two seconds before it disappears again. I'm not sure what is causing this, but if i can get any help, i'd appreciate it. Also note that if, in the click event of the command button of frmTwo, i have frmName.Show (or frmName.Show vbModal or frmName.Show vbModal , Me), it does not display frmName at all.

Nightwalker83
Sep 10th, 2011, 01:17 AM
Well, your code achieves opening the form like my code in post #14. Maybe the install of Visual Basic 6.0 is corrupt. Try reinstalling it and see if the problem persists.

san_excalibur
Sep 12th, 2011, 10:34 AM
I just tried that Nightwalker83. I re-installed VB6, but it didn't help. And now that same code which actually displayed the form for a few seconds doesn't do that anymore. So the form doesn't show up at all now when i click on the button. :/

I'm really sorry that something this simple is taking me so long to figure out, and that i keep asking questions about it. But i feel completely at sea here, and i need help with this.

san_excalibur
Sep 12th, 2011, 10:42 AM
Actually, please disregard the part about the 'form not showing up at all' in my last post. I was looking at the wrong set up file. The form does show up, but it is only for a few seconds like before.

san_excalibur
Sep 12th, 2011, 11:08 AM
Okay, so i'm not sure about what's going on with that form, but i am able to display OTHER forms on a button click.

So let's say i have three forms, FormOne, FormTwo and FormThree.
I have a button on FormOne, which upon clicking, i would like to display FormTwo. But like i explained, it only shows FormTwo for a few seconds before FormTwo vanishes. However, i am able to display FormThree upon clicking the button on FormOne.

Now i tried to check if i could get to FormTwo from a button in FormThree. But when i click on the button, i get an error message saying 'can't display non-modal form when modal form is displayed'.

Can anyone explain what modal forms and non-modal forms are, and what i can do to fix the above error?

Thanks!

san_excalibur
Sep 12th, 2011, 11:59 AM
As per my previous post (post #21), i have fixed the error 'can't display non-modal form when modal form is displayed'. However, when i try to display FormTwo when a button on FormThree is clicked, the same thing happens. That is, FormTwo is displayed for a few seconds before it disappears. So i think there's something up with FormTwo.

san_excalibur
Sep 12th, 2011, 12:00 PM
Hey! I think i might have fixed it! There was a timer set on another function in the same form. I got rid of the timer and that fixed it. Let me test some more and let you guys know.

san_excalibur
Sep 12th, 2011, 02:01 PM
Yup, it works. I am now able to display FormTwo (as per post #21). Now i have a new question.

I have a list view on FormTwo. And i can add items to this list. Now, what i would like to do is this. When i click on a button in FormOne, i want to be able to view FormTwo with all the items in the list being displayed.

However, here is what is happening. When i click on the button in FormOne to display FormTwo, the list view displays nothing (even though there are items added to it). But when i close FormTwo, and click on the same button in FormOne again, it displays FormTwo again, but this time, with all of the items in the list view being displayed.

Does anybody know why this is happening? I would like to be able to see the items in the list view when i click on the button the first time, instead of displaying the form, closing it, and then reopening it.

Any help please?

san_excalibur
Sep 12th, 2011, 05:21 PM
One more question. How can i define an event that occurs upon clicking the 'Enter' button and 'Delete' button from the keyboard?