excel vba中的debug.print语句在我的代码中无法正常工作

时间:2018-07-07 09:48:21

标签: vba excel-vba excel

我的项目是由用户输入气体调节器规格(最小入口压力,最大入口压力,数量等),以便稍后计算该类中每个调节器的项目数量。

该类称为RegulatorGas,如下所示:

' variable names

Private pQuantity As Integer

Private pMinInletP As Double
Private pMaxInletP As Double
Private pOutletP As Integer

Private pInletDiamPipe As Double
Private pOutletDiamPipe As Double

Private pInletDiamReg As Double
Private pOutletDiamReg As Double

Private pInletReducer As String
Private pOutletRrducer As String

Private px As Double
Private py As Double
Private pz As Double

Property Let Quantity(value As Integer)

    pQuantity = value

End Property

Property Get Quantity() As Integer

    Quantity = pQuantity

End Property

Property Let MinInletPressure(value As Double)

    pMinInletP = value

End Property

Property Get MinInletPressure() As Double

    MinInletPressure = pMinInletP

End Property

Property Let MaxInletPressure(value As Double)

    pMaxInletP = value

End Property

Property Get MaxInletPressure() As Double

    MaxInletPressure = pMaxInletP

End Property

Property Let OutletPressure(value As Integer)

    pOutletP = value

End Property

Property Get OutletPressure() As Integer

    OutletPressure = pOutletP

End Property

Property Get Description() As String

    Description = "Reg." & "( " & CStr(pMinInletP) & " - " & CStr(pMaxInletP) & " Bar /" _
    & CStr(pOutletP) & " mbar)" & ",Q = " & CStr(pQuantity) & " m3/hr " _
    & vbNewLine & "inlet diameter: " & CStr(pInletDiamPipe) & """" & vbNewLine _
    & "outlet diameter: " & CStr(pOutletDiamPipe) & """"

End Property


Public Property Let xCoordinate(value As Double)

    px = value

End Property

Public Property Let yCoordinate(value As Double)

    py = value

End Property

Public Property Let zCoordinate(value As Double)

    pz = value

End Property

Public Property Get xCoordinate() As Double

    xCoordinate = px

End Property

Public Property Get yCoordinate() As Double

    yCoordinate = py

End Property

Public Property Get zCoordinate() As Double

    zCoordinate = pz

End Property

Public Property Let Coordinates(value As Variant)

    px = value(0)
    py = value(1)
    pz = value(2)

End Property

Private Function transformDMmToInch(diam As Double) As Double

    If diam = 25 Then

        transformDMmToInch = 0.75

    ElseIf diam = 32 Then

        transformDMmToInch = 1

    ElseIf diam = 63 Then

        transformDMmToInch = 2

    ElseIf diam = 90 Then

        transformDMmToInch = 3

    ElseIf diam = 125 Then

        transformDMmToInch = 4

    ElseIf diam = 180 Then

        transformDMmToInch = 6

    ElseIf diam = 250 Then

        transformDMmToInch = 8

    End If

End Function

Property Get RegOutletDiam() As Double

    If pQuantity <= 24.5 Then

        RegOutletDiam = 0.75

    ElseIf pQuantity <= 42.5 Then

        RegOutletDiam = 1

    ElseIf pQuantity <= 250 Then

        RegOutletDiam = 2

    ElseIf pQuantity <= 500 Then

        RegOutletDiam = 3

    ElseIf pQuantity <= 1000 Then

        RegOutletDiam = 4

    ElseIf pQuantity <= 2000 Then

        RegOutletDiam = 6

    Else

        RegOutletDiam = 8

    End If

    pOutletDiamReg = RegOutletDiam

    Call outletReducer

End Property

Property Get RegInletDiam() As Double

    If pMinInletP <= 2.5 Then

        If pQuantity <= 42.5 Then

            RegInletDiam = 1

        ElseIf pQuantity <= 250 Then

            RegInletDiam = 2

        ElseIf pQuantity <= 500 Then

            RegInletDiam = 3

        ElseIf pQuantity <= 1000 Then

            RegInletDiam = 4

        ElseIf pQuantity <= 2000 Then

            RegInletDiam = 6

        Else

            RegInletDiam = 8

        End If

    ElseIf pMinInletP <= 4.5 Then

        If pQuantity <= 42.5 Then

            RegInletDiam = 0.75

        ElseIf pQuantity <= 250 Then

            RegInletDiam = 2

        ElseIf pQuantity <= 500 Then

            RegInletDiam = 2

        ElseIf pQuantity <= 1000 Then

            RegInletDiam = 3

        ElseIf pQuantity <= 2000 Then

            RegInletDiam = 4

        Else

            RegInletDiam = 6

        End If


    End If

    pInletDiamReg = RegInletDiam

    Call inletReducer

End Property

Property Let PipeInletDiam(value As Double)

    Dim inchDiam As Double

    inchDiam = transformDMmToInch(value)

    pInletDiamPipe = inchDiam

    Call inletReducer

End Property

Property Get PipeInletDiam() As Double

    PipeInletDiam = pInletDiamPipe

End Property

Property Let PipeOutletDiam(value As Double)

    Dim inchDiam As Double

    inchDiam = transformDMmToInch(value)

    pOutletDiamPipe = inchDiam

    Call outletReducer

End Property

Property Get PipeOutletDiam() As Double

    PipeOutletDiam = pOutletDiamPipe

End Property


Sub inletReducer()

    If pInletDiamPipe > pInletDiamReg Then

        pInletReducer = "R" & CStr(pInletDiamPipe) & "x" & CStr(pInletDiamReg)

    ElseIf pInletDiamPipe < pInletDiamReg Then

        pInletReducer = "R" & CStr(pInletDiamReg) & "x" & CStr(pInletDiamPipe)

    Else

        pInletReducer = "No inlet reducer"

    End If

End Sub

Sub outletReducer()


    If pOutletDiamPipe > pOutletDiamReg Then

        pOutletRrducer = "R" & CStr(pOutletDiamPipe) & "x" & CStr(pOutletDiamReg)

    ElseIf pInletDiamPipe < pInletDiamReg Then

        pOutletRrducer = "R" & CStr(pOutletDiamReg) & "x" & CStr(pOutletDiamPipe)

    Else

        pOutletRrducer = "No outlet reducer"

    End If

End Sub

Property Get getInletReducer() As String

    getInletReducer = pInletReducer

End Property

Property Get getOutletReducer() As String

    getOutletReducer = pOutletRrducer

End Property

Sub refresh()

    Call inletReducer
    Call outletReducer

End Sub

但是当我在下面显示的另一个模块中测试该类时

Sub testClass()

    'On Error Resume Next

    Dim reg1 As New RegulatorGas

    reg1.PipeInletDiam = 90
    reg1.PipeOutletDiam = 180

    reg1.MinInletPressure = 2.5
    reg1.MaxInletPressure = 7
    reg1.Quantity = 1000
    reg1.OutletPressure = 100



    Debug.Print reg1.getInletReducer
    Debug.Print reg1.getOutletReducer
    reg1.refresh


End Sub

答案是错误的,应该分别打印“ R4x3”和“ R6x4”,但是代码分别打印“ R3x0”和“ R6x0”。

我的代码中的错误在哪里?

0 个答案:

没有答案