DevPinoy.org
A Filipino Developers Community

>>> First two to make 3 wins! <<<

Weird function calls in VB6

Note that i started my programming career as a .NET Developer so i never got hold of VB6.0 even in school (I have a Physics degree)

I was experimenting with some vba codes when i stumbled upon this weird function call constructs for vb6/vba.  i was calling a msgbox function with custom parameters

MsgBox(Prompt:="test", Title:="jokiz", Buttons:=vbOKOnly)

and it's complaining about "Expected: =", expected where (talk about those helpful messages)?  I found out later that it needs a variable to assign the results to.  Turned out that if you call functions with parenthesis, you're obliged to assign the results to a variable.  I later found this blog post of eric lippert, which explains the interiors of these weird parentheses rules.  This line made me laugh: "These rules are confusing and silly, as the designers of Visual Basic .NET realized". 

The moment we ported our project to VS2005 the past week, I was excited to generics and all the new stuff.  Here i am learning VBA/VB6 for the Excel programming requirement of the project.


Posted 12-14-2006 3:43 PM by jokiz
Filed under:

Comments

cruizer wrote re: Weird function calls in VB6
on 12-14-2006 12:25 AM

well dude...somebody's gotta do the dirty work! :P

dehran ph wrote re: Weird function calls in VB6
on 12-14-2006 12:28 AM

the real world in consulting. never been there so far ;).

jokiz wrote re: Weird function calls in VB6
on 12-14-2006 12:30 AM

yeah, the handyman...

darwin25 wrote re: Weird function calls in VB6
on 12-14-2006 5:39 PM

ay yeah. I remember the time when I had to ask dehran_ph why I cant what is wrong with my ADO statement here:

cmd.CommandType = adCmdStoredProc        

cmd.Execute("InsertQueryName",Array & _(Parameters))

for freaking out loud Im using an insert query in MS Access and the ADO statement is showing the error "Expected: =". So I would have to modify my statement in to this

cmd.CommandType = adCmdStoredProc        

Set rs = cmd.Execute("InsertQueryName",Array & _(Parameters))

Its sking for a recordset when MS Access dont return recordsets. It turn out that this is the correct syntax

cmd.CommandType = adCmdStoredProc        

cmd.Execute "InsertQueryName",Array(Parameters)

It turned out its those freaking parantheses that's causing the problem

jokiz wrote re: Weird function calls in VB6
on 12-14-2006 6:36 PM

wow, rodel the consultant

LaTtEX wrote re: Weird function calls in VB6
on 12-17-2006 11:01 PM

Physics grad ka pala. Ako din eh. :p

But I did tinker with VB6.

jokiz wrote re: Weird function calls in VB6
on 12-17-2006 11:21 PM

wow pareho pala tayo

cruizer wrote re: Weird function calls in VB6
on 12-18-2006 12:33 PM

sana ako hindi ma-assign sa VB6, he he

Richard wrote re: Weird function calls in VB6
on 02-04-2007 2:59 PM

Aren't you just missing "Call" before "MsgBox", as it's a procedure?

jokiz wrote re: Weird function calls in VB6
on 02-04-2007 6:25 PM

i've seen the docs and it says it's optional

xypho wrote re: Weird function calls in VB6
on 03-27-2007 9:48 PM

bah, if you want to call a function or sub with parenthesis and not have to get a return value write:

Call MyFunction(bla, bloum)

it is the same as

MyFunction bla, bloum

but at least you have the parenthesis... I just hate the "Call" word... it puts blue everywhere and makes the code quite confusing sometimes, but I prefer it to calling functions or subs without parentesis.

As someone mentioned, this "call" is not needed anymore in .NET... what a relief...

(like the "Set" for the objects... given that everything is an object, even the in-built types, I found that illogical too...)

Have fun!


Copyright DevPinoy 2005-2008