We help IT Professionals succeed at work.

control forms from vb module

309 Views
Last Modified: 2012-06-27
Using visual Studio 2005 programming in visual basic.
I have one module and two forms. The program launches the setupform, which
sets global variables in the mainmodule. After completion it hands control to mainmod.
The second form (monitor) now needs to be shown and is updated every minute.
The program runs 24/7, but there has to be a way to stop it, which is done by a checkbox on the monitor form.

The problem is I cannot control the forms from the module.
Following is some code from the module:

Imports System
Imports System.Collections
Imports Microsoft.Office.interop.excel

Module MainMod

'       global variables
    Dim FMXL As Excel.Application
    Dim FMWbook As Workbook
    Dim FMWSheet As Worksheet
    Dim FMMon1 As New System.Windows.Forms.Form
    Dim FMSet1 As New System.Windows.Forms.Form
                           etc

    Sub Main()

        FMSet1.Name = "SetupForm"
        FMMon1.Name = "MonitorForm"

        FMSet1.Close()
        FMMon1.Show()
         etc

The problem is, it is not complaining about the syntax, but FMMon1.show show a completely blank form, not the monitor form I have created.
Also there is a public subroutine in MonitorForm, but is does not show up in FMMon1.
In addition I cannot close or unload the setupform

So we are obviously not connected.
Can you tell me what is wrong or missing.

Another thing I have a problem with is to set the location of the monitor form. There are 5 radio buttons on the form sending the form top left, centre etc
However to set location pointer with X & Y coordinates escapes me.

I do a lot of programming in VBA and I find this visual studio very tedious & frustrating.
For example I cannot use Range(Cells(1,1),Cells(5,2000)).Select
Nor can it understand EntireColumn etc etc
and I have not tried ActiveCell.offset, but probably not. (I have not seen it in intellisence)
Can anybody "open a door here"?

Can somebody help?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Try instantiating forms like

Dim fmon As New FMMon1
fmon.Show()
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
Right...the form is blank because you are creating an instance of the default blank form:

    Dim FMMon1 As New System.Windows.Forms.Form

As CodeCruiser suggests, replace that with the name of your actual created form.  I think it's "MonitorForm"?

    Dim FMMon1 As New MonitorForm

Author

Commented:
Yes guys that works. However when I close the setupform it still hangs around in the status bar. I would prefer to unload it, but FMSet1.unload does not work. Must need some other syntax.

Also could I have some suggestions about the location X,Y pointer.

Thanks
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
Does your app actually start with sub Main()?  If so, how are you keeping it alive?

Author

Commented:
No it starts with setupform, which then loads sub main on mainmod.vb . From your comment I gather that the application will close if I unload the calling form. Is that correct?
I may have to minimize the form instead. However the application stays alive after I close the setupform.

regards.
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.