• 0

[VB6] Keeping a class alive +Sub Main


Question

Hey gang,

We just got some code from a partner and since the app has a UI and we need to run it as a Windows Service I need to quickly update the code to A) Call "Sub Main" instead of directly loading the form, B) transfer all the form's code to a class, and C) keep the class alive until we want to kill it (Task Mgr, etc)

I know this is possible, and I'm sure I did it a few times (years ago) but I cannot remember how. When Sub Main completes the class terminates. How do I avoid this?

Thanks

Option Explicit
Private objRDSService As New clsRDSService

Sub Main()
	Dim sSerialNumber   As String
	Dim sPassword	   As String
	Dim sMenuFolder	 As String
	Dim sOrderFolder	As String

	With objRDSService
		.SerialNumber = sSerialNumber
		.Password = sPassword
		.OrderFolder = sOrderFolder
		.SerialNumber = sSerialNumber
		.MenuFolder = sMenuFolder
		.LoginName = "Portal_" & Right("0000" & .SerialNumber, 3)
		If .HasUI = True Then
			frmMain.Show
			'the following lines are commented out because I
			'have not added the controls.
			'frmMain.txtSerialNumber.text = .SerialNumber
			'frmMain.txtMenuFolder.text = .MenuFolder
			'frmMain.txtOrderFolder.text = .OrderFolder
			'frmMain.txtStarted.text = .Started
		End If
	End With
End Sub

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Thanks SOOPRcow,

But thats just a hack and will use memory and CPU cycles. Yes, I could sleep for a minute or five in the loop but still not elegant.

I also just noticed that the partner's code uses two OCX controls, which means I may not be able to do this anyway. <sigh> I could have done this litterally six months ago in .NET and... never mind me, I'm just venting at bad design decisions.

Thanks again.

Link to comment
Share on other sites

  • 0

Thanks again. Yea I know of that one, and it works ok. The problem is our partner has to allow the app to run as an app for other partners. So I am attempting to change a little bit of the code to take in a command line switch to avoid loading the UI.

But again, thanks. My next question will be about Cobal (re: old software) Have a great day.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.