Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB4 16-bit AppActivate error

Posted on 1998-01-30
1
Medium Priority
?
289 Views
Last Modified: 2008-02-01
I've place the following code in the Sub Main() of my program

    If App.PrevInstance Then
        sTitle = App.Title
        App.Title = "armgarmgar"
        AppActivate sTitle
        End
    End If

After running a second instance of my program it gives me a runtime error  'Invalid procedure call' '5'

I'm  also running the program under Win95.  What am I doing wrong?
0
Comment
Question by:armg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
anthonyc earned 800 total points
ID: 1454497
The problem is you are confusing your app, since the title is the same as your current app.  Use this code to do what yu want.  In sub main put this

Please find the declare for the API functions in the api viewer
(findwindow, getwindowplacement, setfocusapi, setforegorund window)  The #if are precompiler conditions


sub main
  if app.previnstance then
      restorepreviousinstance
      end
  end if
end sub

Public Sub RestorePreviousInstance()
    Dim lngPrevWin       As Long
    Dim strPreviousTitle As String
   
    'VB3 & VB4 use class name "ThunderRTForm"
    'VB5 uses class name "ThunderRT5Form"
    'Including the class name for the compiled exe class
    'prevents the routine from finding and attempting
    'to activate the project form of the same name.
    'Set the current App.Title = "....Duplicate Instance" to avoid it being found
    strPreviousTitle = App.Title
    App.Title = "....Duplicate Instance"
   
#If Win32 Then
    lngPrevWin = FindWindow("ThunderRT5Form", strPreviousTitle)
#Else
    lngPrevWin = FindWindow("ThunderRTForm", strPreviousTitle)
#End If
   
    DoEvents
   
    'Check to see if the previous instance is open
    If lngPrevWin > 0 Then
        Dim intReturn As Long
        Dim udtCurWin As WINDOWPLACEMENT
       
        'get the current window state of the previous instance
        udtCurWin.Length = Len(udtCurWin)
        intReturn = GetWindowPlacement(lngPrevWin, udtCurWin)
               
        'if the udtCurWin.showCmd member indicates that
        'the window is currently minimized, it needs
        'to be restored, so ...
        If udtCurWin.showCmd = SW_SHOWMINIMIZED Then
            udtCurWin.Length = Len(udtCurWin)
            udtCurWin.Flags = 0&
            udtCurWin.showCmd = SW_SHOWNORMAL
            intReturn = SetWindowPlacement(lngPrevWin, udtCurWin)
        End If
       
        'bring the window to the front and make
        'the active window.  Without this, it
        'may remain behind other windows.
        'This command only works in Win32
#If Win32 Then
        intReturn = SetForegroundWindow(lngPrevWin)
#Else
        intReturn = SetFocusAPI(lngPrevWin)
#End If
       
        DoEvents
   End If
End Sub



0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question