Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Trouble with IF...Then...ElseIf...

Trouble with IF...Then...ElseIf...

Scheduled Pinned Locked Moved Visual Basic
lounge
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    big_D
    wrote on last edited by
    #1

    Im trying to get this if then statement to work, but I'm new to VB and programming in general and I'mnot sure what's wrong, or even if this is the best way to do what i want to do. I see there is a select case method, but I'm not sure the best way to do this. Thanks in advance. When strOwnerCode = "M", my strTitle is not getting populated correctly. I'm not sure where my flaw is(probably my whole statement).

    strOwnerCode=sess0.screen.GetString(10, 78, 01)

    If strOwnerCode = “C” then
    sess0.screen.sendkeys("<PF2>") 'opens the officers library
    strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
    if strTitle = “S” then
    strTitle = “Secretary”
    elseif strTitle = “P” then
    strTitle = “President”
    elseif strTitle = “T” then
    strTitle = “Treasurer”
    elseif strTitle = “V” then
    strTitle = “Vice President”
    end if
    elseIf strOwnerCode = “D” then
    sess0.screen.sendkeys("<PF2>") 'opens the officers library
    strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
    if strTitle = “M” then
    strTitle = “Member”
    elseif strTitle = “G” then
    strTitle = “Manager”
    end if
    elseif strOwnerCode = “M” then
    sess0.screen.sendkeys("<PF2>") 'opens the officers library
    strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
    if strTitle = “M” then
    strTitle = “Owner Receiving Mail”
    elseif strTitle = “O” then
    strTitle = “Et Al”
    end if
    elseif strOwnerCode = “S” then
    strTitle = “Owner”
    end if

    B G 2 Replies Last reply
    0
    • B big_D

      Im trying to get this if then statement to work, but I'm new to VB and programming in general and I'mnot sure what's wrong, or even if this is the best way to do what i want to do. I see there is a select case method, but I'm not sure the best way to do this. Thanks in advance. When strOwnerCode = "M", my strTitle is not getting populated correctly. I'm not sure where my flaw is(probably my whole statement).

      strOwnerCode=sess0.screen.GetString(10, 78, 01)

      If strOwnerCode = “C” then
      sess0.screen.sendkeys("<PF2>") 'opens the officers library
      strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
      if strTitle = “S” then
      strTitle = “Secretary”
      elseif strTitle = “P” then
      strTitle = “President”
      elseif strTitle = “T” then
      strTitle = “Treasurer”
      elseif strTitle = “V” then
      strTitle = “Vice President”
      end if
      elseIf strOwnerCode = “D” then
      sess0.screen.sendkeys("<PF2>") 'opens the officers library
      strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
      if strTitle = “M” then
      strTitle = “Member”
      elseif strTitle = “G” then
      strTitle = “Manager”
      end if
      elseif strOwnerCode = “M” then
      sess0.screen.sendkeys("<PF2>") 'opens the officers library
      strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
      if strTitle = “M” then
      strTitle = “Owner Receiving Mail”
      elseif strTitle = “O” then
      strTitle = “Et Al”
      end if
      elseif strOwnerCode = “S” then
      strTitle = “Owner”
      end if

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      I'd suggest to remove the if-elseif-series and use a Select Case statement instead (see e.g. http://msdn.microsoft.com/en-us/library/cy37t14y.aspx[^]). Furthermore, you should consider the possibility that none of your cases was found - in the if-elseif world, that means another else clause (without an if); with select-case, it is the Case Else clause.

      B 1 Reply Last reply
      0
      • B big_D

        Im trying to get this if then statement to work, but I'm new to VB and programming in general and I'mnot sure what's wrong, or even if this is the best way to do what i want to do. I see there is a select case method, but I'm not sure the best way to do this. Thanks in advance. When strOwnerCode = "M", my strTitle is not getting populated correctly. I'm not sure where my flaw is(probably my whole statement).

        strOwnerCode=sess0.screen.GetString(10, 78, 01)

        If strOwnerCode = “C” then
        sess0.screen.sendkeys("<PF2>") 'opens the officers library
        strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
        if strTitle = “S” then
        strTitle = “Secretary”
        elseif strTitle = “P” then
        strTitle = “President”
        elseif strTitle = “T” then
        strTitle = “Treasurer”
        elseif strTitle = “V” then
        strTitle = “Vice President”
        end if
        elseIf strOwnerCode = “D” then
        sess0.screen.sendkeys("<PF2>") 'opens the officers library
        strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
        if strTitle = “M” then
        strTitle = “Member”
        elseif strTitle = “G” then
        strTitle = “Manager”
        end if
        elseif strOwnerCode = “M” then
        sess0.screen.sendkeys("<PF2>") 'opens the officers library
        strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
        if strTitle = “M” then
        strTitle = “Owner Receiving Mail”
        elseif strTitle = “O” then
        strTitle = “Et Al”
        end if
        elseif strOwnerCode = “S” then
        strTitle = “Owner”
        end if

        G Offline
        G Offline
        GuyThiebaut
        wrote on last edited by
        #3

        Bear in mind that string comparisons are by default case sensitive so always convert both side of the comparison to upper or lowercase(ToUpper or ToLower). If an "m" comes through your comparison will return a false with your current code. Clickety for how I messed up on this[^]

        “That which can be asserted without evidence, can be dismissed without evidence.”

        ― Christopher Hitchens

        B 1 Reply Last reply
        0
        • B Bernhard Hiller

          I'd suggest to remove the if-elseif-series and use a Select Case statement instead (see e.g. http://msdn.microsoft.com/en-us/library/cy37t14y.aspx[^]). Furthermore, you should consider the possibility that none of your cases was found - in the if-elseif world, that means another else clause (without an if); with select-case, it is the Case Else clause.

          B Offline
          B Offline
          big_D
          wrote on last edited by
          #4

          Ok, thanks for the suggestion, I'll go ahead and do that.

          1 Reply Last reply
          0
          • G GuyThiebaut

            Bear in mind that string comparisons are by default case sensitive so always convert both side of the comparison to upper or lowercase(ToUpper or ToLower). If an "m" comes through your comparison will return a false with your current code. Clickety for how I messed up on this[^]

            “That which can be asserted without evidence, can be dismissed without evidence.”

            ― Christopher Hitchens

            B Offline
            B Offline
            big_D
            wrote on last edited by
            #5

            I'm writing this for attachmate, and our interface only uses uppercase. But that is definetley a good suggestion to keep in mind.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups