This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

(VBS) Select Case - Case Range doesn't work

Former Member
Former Member
Hi there,

can you tell me why the following code doesn't work? Problem are the "Case x To y" Lines.. Is this not supported in M-Files?


Dim oRPZ
oRPZ = PropertyValues.SearchForProperty(1875).TypedValue
Dim oBezeichnung
oBezeichnung = PropertyValues.SearchForProperty(1063).TypedValue
Dim oRisiko

Select Case oRPZ
Case 1
oRisiko = "kein Risiko"
Case 2 To 50
oRisiko = "geringes Risiko"
Case 51 To 100
oRisiko = "mittleres Risiko"
Case 101 To 1000
oRisiko = "hohes Risiko"
End Select

Output = oBezeichnung & " (" & oRisiko & ")"


Problem is, I cannot even save the dialog!
Parents
  • Former Member
    Former Member
    Hi,
    First, 'Case 1' is interpreted as integer 1. If 'oRPZ = PropertyValues.SearchForProperty(1875).TypedValue' is a text field, you should read it as a string value: Case "1".
    Or, transform it to integer in the code before use: oRPZ = CInt(oRPZ).

    Then, the Select case is requires a little trick to use ranges.

    I think the next code will help you :).


    Dim oRPZ : oRPZ = PropertyValues.SearchForProperty(1875).TypedValue '(for example "25").
    Dim oBezeichnung : oBezeichnung = PropertyValues.SearchForProperty(1063).TypedValue
    Dim oRisiko

    oRPZ = CInt(oRPZ) 'convert string to integer value to be able to search ranges.

    Select Case True 'we only check for True and False now.
    Case (oRPZ = 1)
    oRisiko = "kein Risiko"
    Case (oRPZ >= 2 AND oRPZ
    oRisiko = "geringes Risiko"
    Case (oRPZ >= 51 AND oRPZ
    oRisiko = "mittleres Risiko"
    Case (oRPZ >= 101 AND oRPZ
    oRisiko = "hohes Risiko"
    Case Else
    oRisiko = "unbekanntes Risiko"
    End Select

    Output = oBezeichnung & " (" & oRisiko & ")"
Reply
  • Former Member
    Former Member
    Hi,
    First, 'Case 1' is interpreted as integer 1. If 'oRPZ = PropertyValues.SearchForProperty(1875).TypedValue' is a text field, you should read it as a string value: Case "1".
    Or, transform it to integer in the code before use: oRPZ = CInt(oRPZ).

    Then, the Select case is requires a little trick to use ranges.

    I think the next code will help you :).


    Dim oRPZ : oRPZ = PropertyValues.SearchForProperty(1875).TypedValue '(for example "25").
    Dim oBezeichnung : oBezeichnung = PropertyValues.SearchForProperty(1063).TypedValue
    Dim oRisiko

    oRPZ = CInt(oRPZ) 'convert string to integer value to be able to search ranges.

    Select Case True 'we only check for True and False now.
    Case (oRPZ = 1)
    oRisiko = "kein Risiko"
    Case (oRPZ >= 2 AND oRPZ
    oRisiko = "geringes Risiko"
    Case (oRPZ >= 51 AND oRPZ
    oRisiko = "mittleres Risiko"
    Case (oRPZ >= 101 AND oRPZ
    oRisiko = "hohes Risiko"
    Case Else
    oRisiko = "unbekanntes Risiko"
    End Select

    Output = oBezeichnung & " (" & oRisiko & ")"
Children
No Data