Link to home
Start Free TrialLog in
Avatar of mellenf
mellenfFlag for Australia

asked on

control forms from vb module

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?
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Try instantiating forms like

Dim fmon As New FMMon1
fmon.Show()
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
Avatar of mellenf

ASKER

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
Does your app actually start with sub Main()?  If so, how are you keeping it alive?
Avatar of mellenf

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial