Predict The Output

What was your score?


  • Total voters
    12

Oorang

Well-known Member
Joined
Mar 4, 2005
Messages
2,071
Try to guess the final values of i, j, & k before you run the code.
Code:
Option Explicit
Sub PredictTheOutput()
    Dim i&, j&, k&
    i = 10: j = i: k = i
    MySub (i)
    MySub j
    MySub k + 20
    MsgBox Join(Array(i, j, k), vbNewLine), vbQuestion, "Did You Get It Right?"
End Sub
Public Sub MySub(ByRef foo As Long)
    foo = 5
End Sub

I got "i" wrong.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I didn't quite understand the question at first - but when I thought it through (several times) I realised what I was doing was right. Just that the answers I was getting were wrong. I only got i right.
 
Oorang,

Could not you think of something else, some fun like your other thread which was Question & Answer type ? It was good fun.

This one is again the same thing that we all do on Excel Questions board room.
 
Very interesting bit of code!

I've learned a few things I didn't know about how VB works, but still do not understand one piece. I won't ask directly about it just yet to give others an opportunity to look and guess, but am wondering if you are going to provide a step by step look at how the 'MySub' routine is working on the passed values.

Thanks for the challenge!

Owen
 
Owen

Why not set up some watchs on variables, sprinkle the code with a few breakpoints and stir with F8?:)

That should give you some insight on how the code is working.

PS I cheated and ran the code before guessing but I've not voted because I don't understand the poll.:eek:

Oorang

Do you work for some government organisation that creates polls just to confuse people?
 
I’ve been cautious :cool: as well as … wrong :eeek: at the assumption of 'i' estimation.

Amazed has thought :roll: about the difference on syntax and at last has understood that received result of code was absolutely correct from the point of VBA-parsing rules view :!:

Nice brick of VBA wall, thank you!
 
I technically only got 1 right (j=5) but my defence is that I wasn't wearing my glasses and thought the assignment lines were:

i=1;j=1;k=1
 

Forum statistics

Threads
1,222,647
Messages
6,167,331
Members
452,110
Latest member
eui

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top