|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Is my VB6 app form open?On a remote pc that is...
I have a VB6 data collection app running on a remote PC, and need to determine if the main form is open when a client app is opened. Somewhat like this: Dim FormVisible as boolean If form1.visible = true then FormVisible = true Else FormVisible = false End ifBut not sure how to do remote. Any Ideas? William wrote:
Show quoteHide quote > On a remote pc that is... If by "opened" you mean loaded and visible, then something like this may > > I have a VB6 data collection app running on a remote PC, and need to > determine if the main form is open when a client app is opened. > > Somewhat like this: > Dim FormVisible as boolean > If form1.visible = true then > FormVisible = true > Else > FormVisible = false > End ifBut not sure how to do remote. > Any Ideas? > > do the job. If FormIsLoaded(Form1.Name) And Form1.Visible Then 'do whatever End If Public Function FormIsLoaded(ByVal sFormName As String) As Boolean Dim bLoaded As Boolean Dim f As Form bLoaded = False For Each f In Forms If f.Name = sFormName Then bLoaded = True Exit For End If Next f Set f = Nothing FormIsLoaded = bLoaded End Function I'll leave to you the problem of how your client app is going to talk to your remote app which will have to run the above code and return the answer. Checking if a form is open by accessing it's Visibiliy properly will load
the form if it is not already loaded, which I don't think is what this guy wants to do. The IsFormLoaded code suggested will to the trick. Here is mine, where the case of the form does not matter.: Public Function IsFormLoaded(ByVal sFormName As String) As Boolean Dim i As Long For i = 0 To Forms.Count - 1 If (LCase$(Forms(i).Name) = lcase$(sFormName)) Then IsFormLoaded = True Exit For End If Next End Function -- Show quoteHide quote2025 If you do not believe in time travel, your beliefs are about to be tempered. http://www.facebook.com/group.php?gid=43606237254 "Jason Keats" <jke***@melbpcDeleteThis.org.au> wrote in message news:uem5ghE$JHA.1380@TK2MSFTNGP02.phx.gbl... | William wrote: | > On a remote pc that is... | > | > I have a VB6 data collection app running on a remote PC, and need to | > determine if the main form is open when a client app is opened. | > | > Somewhat like this: | > Dim FormVisible as boolean | > If form1.visible = true then | > FormVisible = true | > Else | > FormVisible = false | > End ifBut not sure how to do remote. | > Any Ideas? | > | > | | If by "opened" you mean loaded and visible, then something like this may | do the job. | | If FormIsLoaded(Form1.Name) And Form1.Visible Then | 'do whatever | End If | | Public Function FormIsLoaded(ByVal sFormName As String) As Boolean | Dim bLoaded As Boolean | Dim f As Form | | bLoaded = False | | For Each f In Forms | If f.Name = sFormName Then | bLoaded = True | Exit For | End If | Next f | | Set f = Nothing | | FormIsLoaded = bLoaded | End Function | | I'll leave to you the problem of how your client app is going to talk to | your remote app which will have to run the above code and return the answer. Kevin Provance wrote:
> Checking if a form is open by accessing it's Visibiliy properly will load That's a good point. That bit was air code (ie, untested).> the form if it is not already loaded, which I don't think is what this guy > wants to do. Maybe it should have been: If FormIsLoaded(Form1.Name) Then If Form1.Visible Then 'do something Else Form1.Visible = True 'do something End If Else Form1.Show 'do something End If Your code assumes the form is already loaded and you are checking for
visibility. If your form is not loaded, then If Form1.Visible = False will load it if it's not already loaded, which makes the check a moot point, it will always return loaded even if it wasn't. The code I offered checks the Forms collection (which is a collection of Forms that have already been loaded) and compares the form you want to check against that collection, which will tell you if it's loaded or not. - Kev -- Show quoteHide quote2025 If you do not believe in time travel, your beliefs are about to be tempered. http://www.facebook.com/group.php?gid=43606237254 "Jason Keats" <jke***@melbpcDeleteThis.org.au> wrote in message news:O6ghDsG$JHA.2824@TK2MSFTNGP03.phx.gbl... | Kevin Provance wrote: | > Checking if a form is open by accessing it's Visibiliy properly will load | > the form if it is not already loaded, which I don't think is what this guy | > wants to do. | | That's a good point. That bit was air code (ie, untested). | | Maybe it should have been: | | If FormIsLoaded(Form1.Name) Then | If Form1.Visible Then | 'do something | Else | Form1.Visible = True | 'do something | End If | Else | Form1.Show | 'do something | End If Kevin Provance wrote:
> Your code assumes the form is already loaded and you are checking for I guess you're saying> visibility. > > If your form is not loaded, then If Form1.Visible = False will load it if > it's not already loaded, which makes the check a moot point, it will always > return loaded even if it wasn't. > > The code I offered checks the Forms collection (which is a collection of > Forms that have already been loaded) and compares the form you want to check > against that collection, which will tell you if it's loaded or not. > > - Kev > If FormIsLoaded(Form1.Name) Then should be If FormIsLoaded("Form1") Then for my code to work. I must admit I normally pass a string to that function. I forgot that Form1.Name will load the form if it's not already loaded! Thanks for pointing out my mistake. You could do something simple like open a file (exclusive)when you load the
form and close it when you exit the form. Then all the client form needs to do is to check to see if it can write to the file. If you get an error then the form is open... It probaly the simliest method. Of course if your app terminates abruptly you might leave the file open and will need to forcibly close it on the next run. -- Show quoteHide quoteRandem Systems Your Installation Specialist The Top Inno Setup Script Generator http://www.randem.com/innoscript.html Disk Read Error Press Ctl+Alt+Del to Restart http://www.randem.com/discus/messages/9402/9406.html?1236319938 "William" <no_spam@mail.com> wrote in message news:UJd3m.4699$Kn1.2477@newsfe09.iad... > On a remote pc that is... > > I have a VB6 data collection app running on a remote PC, and need to > determine if the main form is open when a client app is opened. > > Somewhat like this: > Dim FormVisible as boolean > If form1.visible = true then > FormVisible = true > Else > FormVisible = false > End ifBut not sure how to do remote. > Any Ideas? >
Show quote
Hide quote
"Randem" <newsgro***@randem.com> wrote in message Sorry, but that is rather sloppy and unreliable. It makes more check work news:ee484WF$JHA.5780@TK2MSFTNGP03.phx.gbl... | You could do something simple like open a file (exclusive)when you load the | form and close it when you exit the form. Then all the client form needs to | do is to check to see if it can write to the file. If you get an error then | the form is open... | | It probaly the simliest method. Of course if your app terminates abruptly | you might leave the file open and will need to forcibly close it on the next | run. than really needed. And sure does explain a lot. <g> Yes, it sure does. He is creating a client/server type app and you have no
clue... -- Show quoteHide quoteRandem Systems Your Installation Specialist The Top Inno Setup Script Generator http://www.randem.com/innoscript.html Disk Read Error Press Ctl+Alt+Del to Restart http://www.randem.com/discus/messages/9402/9406.html?1236319938 "Kevin Provance" <Bill.McCarthy.Is.Stalking.TPASoft.com***@nowhere.edu> wrote in message news:eEuJowF$JHA.3544@TK2MSFTNGP04.phx.gbl... > "Randem" <newsgro***@randem.com> wrote in message > news:ee484WF$JHA.5780@TK2MSFTNGP03.phx.gbl... > | You could do something simple like open a file (exclusive)when you load > the > | form and close it when you exit the form. Then all the client form needs > to > | do is to check to see if it can write to the file. If you get an error > then > | the form is open... > | > | It probaly the simliest method. Of course if your app terminates > abruptly > | you might leave the file open and will need to forcibly close it on the > next > | run. > > Sorry, but that is rather sloppy and unreliable. It makes more check work > than really needed. > > And sure does explain a lot. <g> > > I would use Winsock for this. The main or server app listens to incoming
connections, and the clients connect to it using TCP. Below is a sample code. To try it, add 1 command button with name "btnSend", and 2 Winsock controls to Form1. Set the name for the first one to "wsckServer", and Index property to 0, and "wsckClient" for the second one while leave Index property blank, then add the following code: Option Explicit Private Sub Form_Load() ' Server wsckServer(0).LocalPort = 5555 wsckServer(0).Listen ' Client wsckClient.RemotePort = 5555 wsckClient.RemoteHost = "127.0.0.1" ' Local host End Sub ' Server side ======================================= Private Sub wsckServer_ConnectionRequest(Index As Integer, _ ByVal requestID As Long) wsckServer(GetNextAvailableSocket()).Accept requestID End Sub Private Sub wsckServer_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim s As String wsckServer(Index).GetData s, vbString Debug.Print "wsckServer_DataArrival: s = '" & s & "'" Select Case Left(s, 3) Case "001": ' Send response wsckServer(Index).SendData "Ack" End Select End Sub ' Get the next available socket, or load a new one if all are used Private Function GetNextAvailableSocket() As Long Dim iNext As Long Dim iWinsockControlsCount As Long Dim ctl As Control iNext = 0 ' Assume no unused socket found For Each ctl In Me.Controls If TypeOf ctl Is Winsock Then If ctl.Name = "wsckServer" Then If ctl.Index > 0 Then ' Avoid the first socket If ctl.State = sckClosed Then ' Found unused socket iNext = ctl.Index Exit For End If ' Keep track of the maximum Index number If iWinsockControlsCount < ctl.Index Then iWinsockControlsCount = ctl.Index End If End If End If End If Next If iNext = 0 Then iNext = iWinsockControlsCount + 1 Load wsckServer(iNext) End If Debug.Print "GetNextAvailableSocket: returning " & iNext GetNextAvailableSocket = iNext End Function ' Client side ======================================= Private Sub btnSend_Click() Dim t As Single wsckClient.LocalPort = 0 ' Use dynamic port wsckClient.Connect ' Wait for up to 5 seconds to connect, or use the Connect event t = Timer Do While Timer - t < 5 And wsckClient.State <> sckConnected DoEvents Loop If wsckClient.State = sckConnected Then wsckClient.SendData "001" Else Debug.Print "Timeout waiting to connect" End If End Sub Private Sub wsckClient_DataArrival(ByVal bytesTotal As Long) Dim s As String wsckClient.GetData s, vbString Debug.Print "wsckClient_DataArrival: s = '" & s & "'" Select Case Left(s, 3) Case "Ack": ' Add code here End Select End Sub
Other interesting topics
Removing too many hyphens
Printing contents of a picture box Remote-Desktop "client/ server" Vista 64 and Visual Studio 6 Re: ADO: Deleting a table after it is loaded into Recordset Date and regional settings problem Type comparison Problem with DIR function..... Need help retrieving a udp response after sending a udp command Exporting a function from VB.net DLL |
|||||||||||||||||||||||