The most basic question ever - what does "i" mean

J

jknapp1005

Bill Jelen wrote a book for VBA in Excel 2007. I guess he thinks I know
everything. He is writing things and not explaining what they are. All the
sudden he's writing section of macros that say things like:

FinalRow = Cells(Rows.Count, 1). End(xlUp).Row
For i = 1 to FinalRow
Range ("A" & i & ":E" & i).Font.Bold = True
Next i

without explaining what the heck "i" means. Try searching for the meaning of
"i" in any database.
 
D

Dave Peterson

i is a variable. The name was Bill's choice--almost arbitrary. He wouldn't use
a variable named Long, Integer, Row, Font, Bold or any thing built into excel's
VBA--or any illegal name (VBA's help will explain more).

In this case, I bet Bill has a line like:
Dim i As Long
(or "Dim i as integer")
in his code

In this case, it's a place holder that he can use for looping between the number
1 and the number that's stored in that FinalRow (another variable).

So for the first time through (when i = 1):
Range ("A" & 1 & ":E" & 1).Font.Bold = True
which is:
Range ("A1":E1").Font.Bold = True

The 2nd time through, i = 2:
Range ("A" & 2 & ":E" & 2).Font.Bold = True
which is:
Range ("A2":E2").Font.Bold = True

If he had 1000 rows to bold, it would be very ugly to use 1000 lines like:

Range ("A1":E1").Font.Bold = True
Range ("A2":E2").Font.Bold = True
Range ("A3":E3").Font.Bold = True
Range ("A4":E4").Font.Bold = True
...
Range ("A1000":E1000").Font.Bold = True
 
W

witek

jknapp1005 said:
Bill Jelen wrote a book for VBA in Excel 2007. I guess he thinks I know
everything. He is writing things and not explaining what they are. All the
sudden he's writing section of macros that say things like:

FinalRow = Cells(Rows.Count, 1). End(xlUp).Row
For i = 1 to FinalRow
Range ("A" & i & ":E" & i).Font.Bold = True
Next i

without explaining what the heck "i" means. Try searching for the meaning of
"i" in any database.


iterator - a variable which changes its value (usually by 1) in every
iteration of the loop.
"i" was the simplest what could be chosen to name iterator


check also Hungarian notation.
It has something to do with International Space Station :)
 
S

smartin

jknapp1005 said:
Bill Jelen wrote a book for VBA in Excel 2007. I guess he thinks I know
everything. He is writing things and not explaining what they are. All the
sudden he's writing section of macros that say things like:

FinalRow = Cells(Rows.Count, 1). End(xlUp).Row
For i = 1 to FinalRow
Range ("A" & i & ":E" & i).Font.Bold = True
Next i

without explaining what the heck "i" means. Try searching for the meaning of
"i" in any database.

I found one: http://mathworld.wolfram.com/i.html

The code is complex.
 
S

smartin

witek said:
O yes, it is really about complex numbers.


:)

Actually, the code is imaginary. There can be no "FinalRow" because
there is always one more row. This concept has been demonstrated many
times. For a perfect example you can read this:
http://mathschallenge.net/index.php?section=faq&ref=number/infinite_primes
but this is a much more succinct proof:

If we write
For i = 1 to FinalRow
...
Next i

It is the same as
i = 1
While i <= FinalRow ' Note 1
...
i = i + 1 ' Note 2
Wend

Note 1: Aha! i is the duck that eats i + 1, so i always gets bigger
[especially when cheeseburgers are nearby], so FinalRow must be a
nondecreasing function of i. Therefore as i go, you go.

Note 2: Now, how can i = i + 1, really ??? There are only two
possibilities: either FinalRow is unbound, so either i = infinity, or
1=2. I think the latter can be proved, but I've lost my notes on that
one. So the former must be true. However if you have so many rows that
Excel craps out, you have a cheeseburger, and then the next row is
imagined: QED.
 
S

smartin

measekite's psychiatrist said:
Are you NUTS? I is a variable to hold an integer value. Why make something
complex out of it?

You're the psychiatrist (^:

I eat almonds.

You are what you eat.

Therefore...
 
S

smartin

jknapp1005 said:
Bill Jelen wrote a book for VBA in Excel 2007. I guess he thinks I know
everything. He is writing things and not explaining what they are. All the
sudden he's writing section of macros that say things like:

FinalRow = Cells(Rows.Count, 1). End(xlUp).Row
For i = 1 to FinalRow
Range ("A" & i & ":E" & i).Font.Bold = True
Next i

without explaining what the heck "i" means. Try searching for the meaning of
"i" in any database.

Ok I've had my fun with your missive and departed from my usual habit of
not baiting rhetorical (trollish) posts. Others have given some very
sane and reasonable explanations for the meaning of "i" in the context
of your post (even though you didn't ask for that). I hope they made sense.

jknapp1005, If you spent any time at all looking at code--in any
language--you will encounter "i" as it is commonly used, as the saner
posters described, as a generic looping variable.

To the point: I suggest you engage in a couple minutes of independent
study to make sure you are not overlooking the obvious before attacking
anyone. If the concept still doesn't make sense, ask a reasonable
question, not a rhetorical (trollish) one.
 
J

jknapp1005

Sorry, smartin, not meaning to be trollish. Actually, I DID spend a good hour
trying to find some definition of "i". It may seem obvious to you folks, but
as someone who is fairly new, it is isn't really obvious to me. I do realize
to those who are experienced, it would seem like a basic question. But I
looked in the index, online, in the VBA editor window, and couldn't find
anything that described it. I even referenced other's books, and didn't see
it being used.

Yeah, sometimes the most basic things do escape me. Thanks for posting.
 
J

jknapp1005

That's a very good answer. Thank you very much.

smartin said:
witek said:
O yes, it is really about complex numbers.


:)

Actually, the code is imaginary. There can be no "FinalRow" because
there is always one more row. This concept has been demonstrated many
times. For a perfect example you can read this:
http://mathschallenge.net/index.php?section=faq&ref=number/infinite_primes
but this is a much more succinct proof:

If we write
For i = 1 to FinalRow
...
Next i

It is the same as
i = 1
While i <= FinalRow ' Note 1
...
i = i + 1 ' Note 2
Wend

Note 1: Aha! i is the duck that eats i + 1, so i always gets bigger
[especially when cheeseburgers are nearby], so FinalRow must be a
nondecreasing function of i. Therefore as i go, you go.

Note 2: Now, how can i = i + 1, really ??? There are only two
possibilities: either FinalRow is unbound, so either i = infinity, or
1=2. I think the latter can be proved, but I've lost my notes on that
one. So the former must be true. However if you have so many rows that
Excel craps out, you have a cheeseburger, and then the next row is
imagined: QED.
 
J

jknapp1005

That's really great, actually. I couldn't find anything like that. Although
you guys are having fun takin' shots (which I'm sure I deserve), I actually
learned something from that. Thanks.
 
J

jknapp1005

Thanks. Very helpful.

witek said:
iterator - a variable which changes its value (usually by 1) in every
iteration of the loop.
"i" was the simplest what could be chosen to name iterator


check also Hungarian notation.
It has something to do with International Space Station :)
 
J

jknapp1005

Thanks, Dave. You were much gentler on me than I probably deserved. Sometimes
the simplest things are the most frustrating (for me anyway). Thanks very
much!
 
S

smartin

jknapp1005 said:
Sorry, smartin, not meaning to be trollish. Actually, I DID spend a good hour
trying to find some definition of "i". It may seem obvious to you folks, but
as someone who is fairly new, it is isn't really obvious to me. I do realize
to those who are experienced, it would seem like a basic question. But I
looked in the index, online, in the VBA editor window, and couldn't find
anything that described it. I even referenced other's books, and didn't see
it being used.

Yeah, sometimes the most basic things do escape me. Thanks for posting.

Ok, I am glad to know you were not just trolling. Hope there are no hard
feelings.

Was your question answered?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top