One problem that a lot of people don't understand is that an if statement has 2 different syntax. The only time you have to "end if" an if statement, is when the if statement is on more than 1 line (or if it does more than one thing). So for example, if I want to make this program change the value of a variable, display a msgbox and leave the sub, I would do this:
somevariable = 1
if x = 5 then
somevariable = 10
msgbox "changed somevariable to 10"
exit sub
end if
However, let's say all I want to do is change the variable, and that's it.... just change the variable and move on, if x = 5:
somevariable = 1
if x = 5 then somevariable = 10
And that will work just fine..... in fact, it will give an error if you put a end if..... without have a "block" of code.
Another thing to keep in mind, is that it really isn't a good practice to put code that should be on 1 line, in more than 1 line. For example, the underscores used in your first if block. While VB allows you to do this (and it's supposed to be for readability) you shouldn't. Each line should represent a different purpose..... it keeps things in order. If you are comfortable programmang with the _, then keep doing it, but be aware on team projects and larger scale apps, you will kick yourself in the rump for it.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Dell XPS
Junior Poster in Training
85 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0