Question:

OOo Basic question: Why does this code work?

by  |  earlier

0 LIKES UnLike

I don't understand why this code works, given that the variable 'i' hasn't been dimmed at any point. I know that variables will default to being a certain data type, at least when declared explicitly, but I can't figure out 'i' here given that it hasn't been:

Sub Test

Const d1 = 1

Const d2 = 1

Const d3 = 0

Dim a(d1, d2, d3)

For Each i In a()

Msgbox "Yes"

Next i

End Sub

Thanks

 Tags:

   Report

5 ANSWERS


  1. You defined " i " by your expression "for EACH " ! (It will start at 0 and increment through "next i")


  2. i generally stands for integer...

    it basically creates an array (a) and defines the values as 1, 1, and 0. Every time an integer appears in the array (integers do not include 0 in this case, i think) it will send a message saying "Yes"

    so in that case, you will get 2 messages saying "Yes"

  3. Explain properly

  4. Because you are using i in your FOR EACH statement, i inherits the properties of a() and does not need to be dimmed

  5. I think Option Explicit (or some other sort) is off here, so variables that aren't declared with any type are assumed as of type Object.

Question Stats

Latest activity: earlier.
This question has 5 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.