English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have asked this question before and no one got it right. See if you can answer this fun little quiz.

This is Visual Basic 6.0. (No cheating now)
Can anyone tell me the results that will be displayed in the Immediate window when the procedure Test is called?

Public Sub Test()
Dim sTemp As String
Dim bRetVal As Boolean



sTemp = "Original"
TestFunction (sTemp)
Debug.Print "Result 1 = " & sTemp

sTemp = "Original"
bRetVal = TestFunction(sTemp)
Debug.Print "Result 2 = " & sTemp

sTemp = "Original"
bRetVal = TestFunction((sTemp))
Debug.Print "Result 3 = " & sTemp

End Sub


Private Function TestFunction(sTest As String) As Boolean
sTest = "Changed"

TestFunction = True 'Set a return value
End Function

2007-03-28 16:02:02 · 5 answers · asked by Jeff R 2 in Computers & Internet Programming & Design

5 answers

Result 1 = Original
Result 2 = Changed
Result 3 = Original

I thought (in my previous answer) that there was a distinction between subs and functions and the effect of ()'s on the arguments.

#2 is a normal function call, and arguments are passed by reference by default.

#3 overrides the implicit byref with the extra set of ()'s.

#1 is equivalent to call((sTemp)) which would also override the implicit byref in the function

2007-03-29 04:49:00 · answer #1 · answered by Vegan 7 · 0 0

First, the Variable sTemp contains "Changed" every time Debug.print is called. Remember, passing a value ByRef is the default in VB 6.

Second, you will get a Syntax error for the double perands '()' in line 15.

2007-03-29 00:51:51 · answer #2 · answered by Brooklyn_SS 2 · 0 2

sTest is passed by reference (although ByRef omitted).
Maybe that was confusing you.

2007-03-29 03:30:54 · answer #3 · answered by BataV 3 · 1 1

it should give compilation error

2007-03-29 08:20:01 · answer #4 · answered by Anonymous · 0 0

is it "false"?

ohh i dont know!!~...

2007-03-29 00:30:48 · answer #5 · answered by farina m 4 · 0 1

fedest.com, questions and answers