Help~how do I do nested if?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • removefromp
    New Member
    • Sep 2007
    • 5

    #1

    Help~how do I do nested if?

    Hi... would like to start off a little useless info. about myself... first time using VB... totally confused and lost... treat me as a retarded and thanks for your help in advance.

    I get the "Block if without end if" error on the codes below. I don't see where I am missing an End If... please help~ ;)
    [CODE=vb]
    If myChoice = "CREATION" Then
    Dim c As Range
    For Each c In Sheets("RMs").R ange("F2:F500")
    If c.Value = TextBox_SecCode .Value Then
    MsgBox "SecCode already exists. Please input a different SecCode."
    Exit Sub
    Else
    rsT.Fields("Sec Code").Value = TextBox_SecCode .Value
    End If
    Next[/CODE]
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Well, going only by the code you posted, you are missing an End If to close the If block opened on the very first line.

    Comment

    • removefromp
      New Member
      • Sep 2007
      • 5

      #3
      Thanks very much for your reply. So I suppose that that End If should be added after Next right?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by removefromp
        Thanks very much for your reply. So I suppose that that End If should be added after Next right?
        Very likely, in my opinion.

        Comment

        • sgrec7
          New Member
          • Aug 2007
          • 58

          #5
          Originally posted by Killer42
          Very likely, in my opinion.
          Is it not programming etiquette to use white space and correct indenting?

          That's what I learnt!

          Anyway:

          Code:
           
          
          if 3 = 3 then[INDENT]if 3 < 6 then[/INDENT][INDENT][INDENT]end[/INDENT][/INDENT][INDENT]End IF[/INDENT]
          endif
          I learnt that last year in YR 9 !

          Hey everybody guess what ?

          Tomorrow is A Merry Can's 9/11

          So take a minute's silence.

          sgrec7

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by sgrec7
            Is it not programming etiquette to use white space and correct indenting?
            Sigh... there goes my nice round 5555 message count. :(

            Anyway...

            I agree that indenting is extremely important in producing understandable code. As for the "white space" I would say that's more of a personal preference and tends to vary a lot. But then I never "learned" programming, just picked it up as I went along.

            In fact, I think it makes code look a lot worse if you have gaps between all the lines. I think gaps should be used to separate code into logical blocks. In the case of this nested IF situation, I'd probably consider that all to be a single block. Unless there was some fairly complex stuff in there, which might need to be broken up for readability.

            Comment

            Working...