+ Reply to Thread
Results 1 to 6 of 6

better way

  1. #1

    better way

    Hi, is ther a better way of writing this.
    If r = "K" And i = 2 Or r = "Q" And i = 2 Or r = "J" And i = 2 Then
    r1 = 10 + i
    y = i
    x = 112
    end if.

    As you can see i always = 2 but r can be a k,q, or j. This way works
    perfect, just thinking that there may be a better way. I was thinking
    something like if r = k/q/j.
    regards Robert


  2. #2
    NickHK
    Guest

    Re: better way

    If i=2 And InStr("KQJ",r)>0 Then
    r1=....
    etc
    End If

    NickHK

    <[email protected]> wrote in message
    news:[email protected]...
    > Hi, is ther a better way of writing this.
    > If r = "K" And i = 2 Or r = "Q" And i = 2 Or r = "J" And i = 2 Then
    > r1 = 10 + i
    > y = i
    > x = 112
    > end if.
    >
    > As you can see i always = 2 but r can be a k,q, or j. This way works
    > perfect, just thinking that there may be a better way. I was thinking
    > something like if r = k/q/j.
    > regards Robert
    >




  3. #3

    Re: better way

    Hello,

    NickHK wrote:
    > If i=2 And InStr("KQJ",r)>0 Then


    Sorry, that's more than the OP wants. This is TRUE for r="K", "Q", "J",
    "KQ", "QJ" and "KQJ" (and i=2, of course)

    Regards,
    Bernd


  4. #4
    NickHK
    Guest

    Re: better way

    Depends what are possible values for r.
    If i=2 And InStr("KQJ",Left(r,1))>0 Then

    Better.

    NickHK

    <[email protected]> wrote in message
    news:[email protected]...
    > Hello,
    >
    > NickHK wrote:
    > > If i=2 And InStr("KQJ",r)>0 Then

    >
    > Sorry, that's more than the OP wants. This is TRUE for r="K", "Q", "J",
    > "KQ", "QJ" and "KQJ" (and i=2, of course)
    >
    > Regards,
    > Bernd
    >




  5. #5

    Re: better way

    Hello,

    Sorry, no. This would accept any r starting with "K", "Q" or "J" (i
    being 2).

    Maybe
    If i = 2 And Application.WorksheetFunction.Match(r, _
    Array("K", "Q", "J", r), False) < 4 Then
    ...
    End If

    or just

    If i=2 and (r="K" or r="Q" or r="J") then
    ...
    end if


    Regards,
    Bernd


  6. #6
    RobcPettit
    Guest

    Re: better way

    Thankyou for your replys. I trying both ideas.
    Regards Robert


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1