Sub main??

jorge

Junior Contributor
Joined
Jul 13, 2003
Messages
239
Location
Belgium
Sub main + Howto Execute code when app is closed

Ok,
How do i use sub main to do:
Check to see if a valeu in the reg is 1 or 0
If it is 0, show a form, if it is 1 then show a notifyicon.
btw: the notify icon is on the form :s
I have a temp fix, but it us irritating that the form flashesa few times befor it disapears :confused: :eek:
btw: you can look at the latest stabel code here:
http://users.skynet.be/jorge/apachemon/apachemon-src.zip
Thanx in advance
 
Last edited:
http://msdn.microsoft.com/library/d...kreadingwritingtoregistryusingvisualbasic.asp

That may help you. Its the msdn library article on reading and writing the Windows Registry. I also have some sample code I derived from that.

Visual Basic:
Dim regConfig As RegistryKey

regConfig = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Merck\\MRL LADI\\WPPDR", True)

If regConfig Is Nothing Then
            Registry.LocalMachine.CreateSubKey("SOFTWARE\\Merck\\MRL LADI\\WPPDR")
            regConfig.CreateSubKey("Config")
            GoTo nofile
        End If

        strConfigFile = regConfig.GetValue("Config")

NoFile:
Visual Basic:
With OpenFileDialog1
                .InitialDirectory = "..\Config"
                .Filter = "PD Rating Configuration (*.ini)|*.ini"
                .ShowDialog()
                strConfigFile = .FileName()
            End With
            regConfig.SetValue("Config", strConfigFile)
 
thax, but i can read, but don't know how to load the form from sub main or the notifyicon :s
thanx anywhay
 
Okay I was misunderstanding what you wanted.

Visual Basic:
If someRegValue = 0 Then
          Dim you as new frmSomeForm
          you.show()
ElseIf someRegValue = 1 Then
          someicon.visible = True
End If

This is all I can think of. If its a taskbar icon I never used those, and don't know how to show/hide it. but the form part works.
 
ok,
I can see the form for a few sec, when sub main end so does my programm :s
And it says, trayicon.shoc() gives a error, maby becouse it on the form :s
 
try something like

Visual Basic:
 Dim you As New frmSomeForm
If someRegValue = 0 Then
         you.show()
ElseIf someRegValue = 1 Then
          someicon.visible = True
End If

 application.run(you)

not near a compiler so I haven't tested it though...
 
After some playing i found application.run(fomr) works :D
But still can't get the tray to work :(
btw anyid on howto execute code when a form is closed?
 
Last edited:
Just had a quick look (with a compiler handy yipee!!!)
Application.Run(you) does indeed display the form.
the following may be of some help though...
Visual Basic:
Dim you As New frmSomeForm
If someRegValue = 0 Then
         you.show()
ElseIf someRegValue = 1 Then
          you.someicon.visible = True        'with someicon being a notifyicon component of form1 declared public
End If

application.run()

the only problem is that the app doesn't exit when you close the form - either add a handler for the Form close event or deal with it in you're exit routine.
 
Last edited:
you.someicon.visible = True

Will show the form too!
btw: How kan i work around it?
it only seems to stay in memery when clsoe via the [X] not when usding END in the code, that bring me back, how can i detect that [X] is pushed?
 
Last edited:
Found it :p

Visual Basic:
    Sub main()
        Dim frmMain As New main()
        If sAM_tray_start = 0 Then
            frmMain.Show()
        ElseIf sAM_tray_start = 1 Then
            frmMain.systray.Visible = True
        End If
        Application.Run()
    End Sub
Thanx a lot :p
And for the closing problem:
Visual Basic:
Private Sub main_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        End
    End Sub
 
Back
Top