Click here to Skip to main content
15,886,774 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
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

VB
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
Posted

1 solution

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

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900