locked
simplify if (Format = "N" Or Format = "C" Or Format = "F" Or Format = "P") then RRS feed

  • Question

  • hi

    a way to simplify if (Format = "N" Or Format = "C" Or Format = "F" Or Format = "P") then end if statement?

    Thanks!!!!!

    Wednesday, December 12, 2012 1:37 AM

Answers

  • If Format is a String variable, you could try this:

    If Format.Length = 1 And "NCFP".IndexOf(Format) >= 0 Then

    If Format is a Char Variable, this should work:

    If "NCFP".IndexOf(Format) >= 0 Then

    • Proposed as answer by Troy Garner Wednesday, December 12, 2012 4:15 AM
    • Marked as answer by fsze88ATmeDOTcom Wednesday, December 12, 2012 4:28 AM
    Wednesday, December 12, 2012 1:43 AM
  • Fsze88ATmeDOTcom : Too lenghty name to type..:)

    Does this help 

            Dim matchString As String() = {"N", "C", "F", "P"}
            Dim Format As String = "N"
            If matchString.Contains(Format) Then
    ' Your code
            End If

    Wednesday, December 12, 2012 1:45 AM
  • If Format is a String variable, you could try this:

    If Format.Length = 1 And "NCFP".IndexOf(Format) >= 0 Then

    If Format is a Char Variable, this should work:

    If "NCFP".IndexOf(Format) >= 0 Then

    This works, I would use AndAlso though instead, and by preference, why not > -1, instead of >=0? I'll mark yours as the answer though, as it's close to what I would do as well. :)

    Nice work


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum

    Wednesday, December 12, 2012 4:15 AM

All replies

  • If Format is a String variable, you could try this:

    If Format.Length = 1 And "NCFP".IndexOf(Format) >= 0 Then

    If Format is a Char Variable, this should work:

    If "NCFP".IndexOf(Format) >= 0 Then

    • Proposed as answer by Troy Garner Wednesday, December 12, 2012 4:15 AM
    • Marked as answer by fsze88ATmeDOTcom Wednesday, December 12, 2012 4:28 AM
    Wednesday, December 12, 2012 1:43 AM
  • Fsze88ATmeDOTcom : Too lenghty name to type..:)

    Does this help 

            Dim matchString As String() = {"N", "C", "F", "P"}
            Dim Format As String = "N"
            If matchString.Contains(Format) Then
    ' Your code
            End If

    Wednesday, December 12, 2012 1:45 AM
  • If Format is a String variable, you could try this:

    If Format.Length = 1 And "NCFP".IndexOf(Format) >= 0 Then

    If Format is a Char Variable, this should work:

    If "NCFP".IndexOf(Format) >= 0 Then

    This works, I would use AndAlso though instead, and by preference, why not > -1, instead of >=0? I'll mark yours as the answer though, as it's close to what I would do as well. :)

    Nice work


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum

    Wednesday, December 12, 2012 4:15 AM