By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,967 Members | 2,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,967 IT Pros & Developers. It's quick & easy.

Help~how do I do nested if?

P: 5
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~ ;)
Expand|Select|Wrap|Line Numbers
  1.     If myChoice = "CREATION" Then
  2.     Dim c As Range
  3.     For Each c In Sheets("RMs").Range("F2:F500")
  4.         If c.Value = TextBox_SecCode.Value Then
  5.           MsgBox "SecCode already exists. Please input a different SecCode."
  6.           Exit Sub
  7.         Else
  8.           rsT.Fields("SecCode").Value = TextBox_SecCode.Value
  9.         End If
  10.     Next
Sep 11 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 5K+
P: 8,434
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.
Sep 11 '07 #2

P: 5
Thanks very much for your reply. So I suppose that that End If should be added after Next right?
Sep 11 '07 #3

Expert 5K+
P: 8,434
Thanks very much for your reply. So I suppose that that End If should be added after Next right?
Very likely, in my opinion.
Sep 11 '07 #4

sgrec7
P: 59
Very likely, in my opinion.
Is it not programming etiquette to use white space and correct indenting?

That's what I learnt!

Anyway:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. if 3 = 3 then
    if 3 < 6 then
    end
    End IF
    endif
  4.  
  5.  
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
Sep 11 '07 #5

Expert 5K+
P: 8,434
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.
Sep 12 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.