如何根据值更改结果 [英] How Do I Change Result Depending On A Value
问题描述
我正在尝试编写一个可以根据值更改结果的宏。这些数字是5位数,只能是1,2或3
如果数字全部为1则结果将通过。
如果数字包含2则结果将是动作。
如果数字包含3则结果将失败。
例如:
11111结果通过
11211结果为行动
32111或11223结果失败
这是我创建的代码(下面),但我不知道如何使用InStr控件,或者即使我应该使用它
私有 Sub result()
Dim points As Integer ,结果 As 字符串
我 .txtresult.Value = Val(cboImage.Value)& Val(cbofruit.Value)& Val(cboveg.Value)& Val(cboProcedure.Value)& Val(cboDescription.Value)
points = Val( Me .txtresult.Value)
选择 案例分
案例 InStr(points, 1 )
result = 传递
案例 InStr(points, 2 )
result = 操作
案例 InStr(points, 3 )
result = 失败
结束 选择
我 .txtresult.Value = result
End Sub
谢谢
< blockquote>感谢Sudhi http://stackoverflow.com/users/2550066/sudhi [ ^ ]他很有灵魂
instr所做的是找到一个数字的位置,如果它大于0则会触发我们需要的结果
私有 Sub result()
Dim points 作为 整数,结果作为 字符串
我 .txtresult.Value = Val(cboImage.Value)& Val(cbofruit.Value)& Val(cboveg.Value)& Val(cboProcedure.Value)& Val(cboDescription.Value)
points = Val( Me .txtresult.Value)
如果 InStr(points, 3)> 0 然后
result = 失败
否则
如果 InStr(points, 2)> 0 然后
result = 操作
否则
result = 传递
结束 如果
结束 如果
我 .txtresult.Value =结果
结束 Sub
Im trying to write a macro that would change result depending on a value. The numbers are 5 digits and can only be 1 , 2 or 3
if numbers are all 1 then the result would be pass.
if numbers contains 2 then the result would be action.
if numbers contains 3 then the result would be fail.
eg:
11111 result is pass
11211 result is action
32111 or 11223 result is fail
This is the code(below) which i have created but i am not sure how to use that InStr control or even if i should be using that
Private Sub result()
Dim points As Integer, result As String
Me.txtresult.Value = Val(cboImage.Value) & Val(cbofruit.Value) & Val(cboveg.Value) & Val(cboProcedure.Value) & Val(cboDescription.Value)
points = Val(Me.txtresult.Value)
Select Case points
Case InStr(points, 1)
result = "Pass"
Case InStr(points, 2)
result = "Action"
Case InStr(points, 3)
result = "Fail"
End Select
Me.txtresult.Value = result
End Sub
Thanks
Thanks to Sudhi http://stackoverflow.com/users/2550066/sudhi[^] from Stackoverflow he had great soultion
what instr does is find the location of a number and if it was greater than 0 it would triggered that result we needed
Private Sub result() Dim points As Integer, result As String Me.txtresult.Value = Val(cboImage.Value) & Val(cbofruit.Value) & Val(cboveg.Value) & Val(cboProcedure.Value) & Val(cboDescription.Value) points = Val(Me.txtresult.Value) If InStr(points, "3") > 0 Then result = "Fail" Else If InStr(points, "2") > 0 Then result = "Action" Else result = "Pass" End If End If Me.txtresult.Value = result End Sub
这篇关于如何根据值更改结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!