模数在VB 6.0中

时间:2015-11-09 22:01:39

标签: vb6

我想问一下模数对我来说不起作用。

例如:

 Option Explicit

 Private Function Modulus_Operator(Value1, Value2)

     Modulus_Operator = Value1 - (Int(Value1 / Value2) * Value2)

 End Function

 Private Sub Form_Activate()

     Dim A, B, BaseOut as double

     A = 67^89
     BaseOut = 35

     text1.text =  Modulus_Operator(A, BaseOut)

 End Sub

3 个答案:

答案 0 :(得分:1)

您的函数必须返回一个整数。你不能忘记类型:

Private Function Modulus_Operator(Value1 as integer, Value2 as integer) as integer

  Modulus_Operator = Value1 - (Int(Value1 / Value2) * Value2)

End Function

无论如何......你知道模数的mod吗?

答案 1 :(得分:0)

你尝试了一些不可能的事情'。你知道一个整数可以存储的值的范围吗?您的值67 ^ 89远远超出此值,因此您会溢出。

答案 2 :(得分:0)

您可以使用以下代码:

Private Sub Form_Activate()

 Dim A, B, BaseOut As Double

 A = 67 ^ 89
 BaseOut = 35

 Text1.Text = Modulus_Operator(Val(A), Val(BaseOut))

End Sub



Private Function Modulus_Operator(Value1 As Double, Value2 As Double) As Double

 Modulus_Operator = Value1 - (Int(Value1 / Value2) * Value2)

End Function