我如何制作一个代码来告诉 VB6 告诉 VB6 你输入的不是整数?
How can I make a code that tells VB6 that tells VB6 that you're inputting something other than Whole numbers?
简介:大家好!我是 VB6 的新手!我怎样才能制作一个代码告诉 VB6 告诉 VB6 你输入的不是整数?
详情:我正在制作算术级数计算器(我认为不需要代码?但我会提供以防万一。)这是我的代码:
Option Explicit
Private Sub btCalc_Click()
Dim A As Long
Dim N As Long
Dim D As Long
Dim R As Long
Dim F As Long
A = Val(txtInitterm.Text)
N = Val(txtTermint.Text)
D = Val(txtFinterm.Text)
R = Val(txtTermint.Text)
F = N / 2 * (2 * A + (N - 1) * D)
lblOutput.Caption = F
End Sub
我想通知或告诉 VB6 我输入的是分数,而不是整数,并使用该分数进行运算。
注意: String Fraction to Value in VBA 这没有回答我的问题...:D
谢谢大家的帮助!非常感谢。
Vb6中没有VBA中的Application.Evaluate(...)
,所以你必须像“String Fraction to Value in VBA”中的“问题”那样做。将逻辑提取到函数中以供重复使用,并将 Val(...)
调用替换为函数以供使用。
尽管您可能希望在明显的数学错误情况下提供更好的错误处理,但类似下面的内容可能会奏效。我只是 return 归零并用评论标记它们。
Option Explicit
Private Sub btCalc_Click()
Dim A As Long, N As Long, D As Long, R As Long, F As Long
A = GetFrac(txtInitterm)
N = GetFrac(txtTermint)
D = GetFrac(txtFinterm)
R = GetFrac(txtTermint)
F = N / 2 * (2 * A + (N - 1) * D)
lblOutput.Caption = F
End Sub
Public Function GetFrac(ByVal S As String) As Double
GetFrac = 0 ' default return on error
If InStr(S, "/") = 0 Then GetFrac = Val(S): Exit Function
Dim P() As String, N As Double, D As Double
P = Split(S, "/")
If UBound(P) <> 1 Then Exit Function ' bad input -- multiple /'s
N = Val(P(0))
D = Val(P(1))
If D = 0 Then Exit Function ' div by 0
GetFrac = N / D
End Function
简介:大家好!我是 VB6 的新手!我怎样才能制作一个代码告诉 VB6 告诉 VB6 你输入的不是整数?
详情:我正在制作算术级数计算器(我认为不需要代码?但我会提供以防万一。)这是我的代码:
Option Explicit
Private Sub btCalc_Click()
Dim A As Long
Dim N As Long
Dim D As Long
Dim R As Long
Dim F As Long
A = Val(txtInitterm.Text)
N = Val(txtTermint.Text)
D = Val(txtFinterm.Text)
R = Val(txtTermint.Text)
F = N / 2 * (2 * A + (N - 1) * D)
lblOutput.Caption = F
End Sub
我想通知或告诉 VB6 我输入的是分数,而不是整数,并使用该分数进行运算。
注意: String Fraction to Value in VBA 这没有回答我的问题...:D
谢谢大家的帮助!非常感谢。
Vb6中没有VBA中的Application.Evaluate(...)
,所以你必须像“String Fraction to Value in VBA”中的“问题”那样做。将逻辑提取到函数中以供重复使用,并将 Val(...)
调用替换为函数以供使用。
尽管您可能希望在明显的数学错误情况下提供更好的错误处理,但类似下面的内容可能会奏效。我只是 return 归零并用评论标记它们。
Option Explicit
Private Sub btCalc_Click()
Dim A As Long, N As Long, D As Long, R As Long, F As Long
A = GetFrac(txtInitterm)
N = GetFrac(txtTermint)
D = GetFrac(txtFinterm)
R = GetFrac(txtTermint)
F = N / 2 * (2 * A + (N - 1) * D)
lblOutput.Caption = F
End Sub
Public Function GetFrac(ByVal S As String) As Double
GetFrac = 0 ' default return on error
If InStr(S, "/") = 0 Then GetFrac = Val(S): Exit Function
Dim P() As String, N As Double, D As Double
P = Split(S, "/")
If UBound(P) <> 1 Then Exit Function ' bad input -- multiple /'s
N = Val(P(0))
D = Val(P(1))
If D = 0 Then Exit Function ' div by 0
GetFrac = N / D
End Function