Rob
Rob

Reputation: 2472

VB6 - calling subs

I am modifying a legacy project that must run in VB6, and I have OOP experience but not VB.

Anyway I thought this would be straightforward, I need to add data to a hashmap.

I can call the retreive data function but not the set data function.

Here is the set data function (or sub I guess).

Sub SetSetting(Name As String, Value)
    Member of MBCSettings.MBCSettings
    Store the named setting in the current settings map

So if I try to set something like this:

  gobjMBCSettings.SetSetting("UserName", "223")

I get: Compiler Error, Expected "="

Is my object broken or am I missing something obvious? Thanks.

Upvotes: 1

Views: 1033

Answers (1)

TyCobb
TyCobb

Reputation: 9089

Ah VB6... yes.

In order to invoke a method the standard way you do not use parentheses:

gobjMBCSettings.SetSetting "UserName", "223"

If you want to use parentheses, tack in the call command:

Call gobjMBCSettings.SetSetting("UserName", "223")

It should be noted that using parentheses around ByRef argument without the Call keyword, the argument will be sent in as ByVal.

Public Sub MySub(ByRef foo As String)
    foo = "some text"
End Sub

Dim bar As String
bar = "myText"
MySub(bar)
' bar is "myText"
Call MySub(bar)
' bar is "some text"

It only complained because you were passing in multiple parameters wrapped with a single set of parentheses. Using () to force ByVal also works in VB.NET.

Upvotes: 3

Related Questions