Sub main??

jorge

Well-known member
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 by a moderator:
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.

Code:
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:
Code:
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 dont know how to load the form from sub main or the notifyicon :s
thanx anywhay
 
Okay I was misunderstanding what you wanted.

Code:
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 dont 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

Code:
 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 havent tested it though...
 
After some playing i found application.run(fomr) works :D
But still cant get the tray to work :(
btw anyid on howto execute code when a form is closed?
 
Last edited by a moderator:
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...
Code:
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 doesnt exit when you close the form - either add a handler for the Form close event or deal with it in youre exit routine.
 
Last edited by a moderator:
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 by a moderator:
Found it :p

[VB]
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
[/VB]
Thanx a lot :p
And for the closing problem:
[VB]
Private Sub main_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
End
End Sub
[/VB]
 
Back
Top