在10年的时间里,我一直在使用VB6,每一次,我都会得到一个“ByRef参数类型不匹配”错误,我根本无法找到不匹配.经过一段时间的努力,我一直以强迫的方式来打扰,但这次我以为我会问.我正在包括我认为可以与此有关的所有代码;但是现在可以跳过它,并在我演示问题后参考它:
Public Type PBufferType Location(9) As Integer ' code location ValueHi(9) As Integer ' Vhi code ValueLo(9) As Integer ' Vlo code Locked(9) As Integer ' State of pair Gamma(9) As Single ' Gamma between this segment and next End Type Public GammaBuffer(1) As PBufferType ' The main data type Public SelectedBank as Integer Function MeasureLuxAtCode(code As Integer) As Single Call TestPatternForm.DrawTestWindow(3,code) MeasureLuxAtCode = MeasureLux(1) End Function
问题发生在下面. “LuxMinTarget = MeasureLuxAtCode(FirstLevel)”行会生成“ByRef参数类型不匹配”错误,表示FirstLevel不是整数.
Sub DetermineIdealLuxCurve() Dim FirstLevel,FirstDACtoMeasure As Integer FirstDACtoMeasure = 0 FirstLevel = GammaBuffer(SelectedBank).Location(FirstDACtoMeasure) LuxMinTarget = MeasureLuxAtCode(FirstLevel) End Sub
但是,当然,FirstLevel是一个整数,不是吗?它是一个int int,它的值由UDT设置,返回一个int,所以我错了什么?如果我强制它这样一个int:
LuxMinTarget = MeasureLuxAtCode(Int(FirstLevel))
编译/解释器的快乐.但我不是.
这是编译器中的错误还是只是我密集?
问题在这里:
原文链接:https://www.f2er.com/vb/255696.htmlDim FirstLevel,FirstDACtoMeasure As Integer
这实际上将FirstLevel声明为Variant,而不是您可能期望的整数.
这是一个经典的VB6 getcha! (你不是第一个被它咬死).
每行声明一个变量可以避免这个问题:
Dim FirstLevel As Integer Dim FirstDACtoMeasure As Integer