Runtime error 438

Status
Niet open voor verdere reacties.

ColdDeath

Gebruiker
Lid geworden
7 nov 2013
Berichten
63
Dag,

Ik heb de volgende code van internet afgeplukt en geconverteerd naar 64-bit. Echter krijg ik een Run-time Error 438 bij het oproepen van de eerste function. Het frustrerende hiervan is dat er geen code wordt gehighlight. Heb ik ergens een vertalingsfout gemaakt? Ben ik code aan het gebruiken wat verouderd is?

Input vanuit Module1:
Code:
Option Explicit

Public Userform1 as Object

sub main()
    With Userform1
        Module2.Display_Center (ivForm)
        .Show vbModeless
   End With
end sub

Code vanuit module 2.
Code:
Private Declare PtrSafe Function GetSystemMetrics Lib "USER32" (ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hDC As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDC Lib "USER32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "USER32" (ByVal hWnd As LongPtr, ByVal hDC As LongPtr) As Long

Private Const LOGPIXELSX As Long = 88
Private Const LOGPIXELSY As Long = 90
Private Const PointsPerInch = 72

Private Const sm_cxscreen As Long = 0
Private Const sm_cyscreen As Long = 1

Public Enum SystemMetricsConstants

    smScreenWidth = sm_cxscreen
    smScreenHeight = sm_cyscreen
    
End Enum

Public Function SystemMetrics(ByVal uindex As SystemMetricsConstants) As Long

    SystemMetrics = GetSystemMetrics(uindex)

End Function

Public Function PointsPerPixelX() As Double

    Dim hDC As LongPtr
    Dim lDotsPerInch As Long
    
    hDC = GetDC(0)
    lDotsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)
    PointsPerPixelX = PointsPerInch / lDotsPerInch
    ReleaseDC 0, hDC

End Function

Public Function PointsPerPixely() As Double

    Dim hDC As LongPtr
    Dim lDotsPerInch As Long
    
    hDC = GetDC(0)
    lDotsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)
    PointsPerPixely = PointsPerInch / lDotsPerInch
    ReleaseDC 0, hDC

End Function

Sub Display_Center(ivForm As Object)

    xheight = SystemMetrics(smScreenHeight)
    xwidth = SystemMetrics(smScreenWidth)
    
    With ivForm
        If xwidth / xheight > 1.5 Then
            .Left = xwidth * PointsPerPixelX / 4 - .Width / 2
        Else
            .Left = xwidth * PointsPerPixelX / 2 - .Width / 2
        End If
        .Top = xheight * PointsPerPixely / 2 - .Height / 2
    End With
    
End Sub

Het centeren van de userfrom wil ik afhankelijk maken van het scherm, niet de applicatie.

Alvast bedankt.
 
Niks van te zeggen zonder je document.
Ik zou in ieder geval dit niet gebruiken:
Public Userform1 as Object

Dat zal een probleem geven als een userform ook die naam heeft.
 
Ik krijg de error bij de End Function van Function PointsPerPixelX() As Double in Module2.

Hierbij wat meer context aan wat er vooraf gebeurt. De drie punten zijn stukken weggelaten code dat niet relevant is aan het probleem.

Code:
Option Explicit

Public ivApp As Inventor.Application
Public ivDoc As Inventor.Document
.
.
.
Public editType

Sub iPropertiesMacro()

.
.
.
    Call StartMacro
.
.
.
    
End Sub

Function StartForm(ivForm As Object) As Boolean

    Module2.Display_Center (ivForm)
    With ivForm
        .Show vbModeless
        If Not Cancel = Empty And Cancel = False Then StartForm = False Else StartForm = True
    End With
                
End Function

Private Sub StartMacro()

.
.
.
typeBom:
        If typeDeel = "" Then
        
            'Object can't be identified, go back to bomForm.
            GoTo bomForm
        ElseIf typeDeel = "Manufactured" Then
            If ivDoc.DocumentType = kPartDocumentObject Then
            
                'Object is a manufactured part document.
MD:
                
                If StartForm(frmMaakdeel) = False Then GoTo KD
            ElseIf ivDoc.DocumentType = kAssemblyDocumentObject Then
            
                'Object is manufactured assembly document.
MS:

                If StartForm(frmMaakdeel) = False Then GoTo MS
            End If
        ElseIf typeDeel = "Purchased" Then
        
            'Object is manufactured part/assembly document.
KD:
            If StartForm(frmKoopdeel) = False Then GoTo KD
        ElseIf typeDeel = "P&ID" Then
            If ivDoc.DocumentType = kAssemblyDocumentObject Then
            
            'Object is P&ID assembly document.
PD:
                If StartForm(frmPID) = False Then GoTo PD
            End If
        End If
.
.
.

End Sub
 
Laatst bewerkt:
Het centeren van de userfrom wil ik afhankelijk maken van het scherm, niet de applicatie.


Daaroor heb je slechts 2 regels code nodig
 
Daaroor heb je slechts 2 regels code nodig

Ik heb veel codes uitgeprobeerd. Bij mijn computer gaat het meestal goed, maar bij andere computers niet. De reden waarom ik voor deze code ben gegaan is omdat de schermen eerst worden uitgelezen. Daardoor wordt de resolutie bepaald en het midden van iedere scherm.

De code waarmee ik het wil vervangen is de volgende:

Code:
    With ivForm
        .StartUpPosition = 0
        If ivApp.Left + 8 < 2560 Then
            .Left = ivApp.Left + (0.4 * ivApp.Width) - (0.5 * .Width)
            .Top = ivApp.Top + (0.4 * ivApp.Height) - (0.5 * .Height)
        Else
            .Left = ivApp.Left + (0.15 * ivApp.Width) - (0.5 * .Width)
            .Top = ivApp.Top + (0.35 * ivApp.Height) - (0.5 * .Height)
        End If
        .Show vbModeless
        If Not Cancel = Empty And Cancel = False Then StartForm = False Else StartForm = True
    End With

Als je een betere code weet laat het me weten!
 
Laatst bewerkt:
Waarom niet in de ontwerpmodus: startupposition: 2
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan