Computing.Net > Forums > Programming > VB sub paramters

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

VB sub paramters

Reply to Message Icon

Name: Eriedor
Date: February 16, 2006 at 08:55:36 Pacific
OS: win xp
CPU/Ram: 3000sempron 1024
Comment:

ok im close to blowing my brains out this is so frustrating!!

have a simple procedure defined as follows:

public sub proc(i as integer)

this works great however when i decided i wanted to pass 2 dates to it aswell as follows

public sub proc(i as integer,d1 as date,d2 as date)

it suddenly thinks its a function and demands i call it while assigning it. example

proc(int,date,date2) //gives compile error expected: =

x = proc(int,date,date2) //gives no compile errors but does give a runtime error as proc isnt a function!!!

omg what is going on??? pls help me sum1!

(also how do you turn off debugging during design time its very annoying!

thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: February 16, 2006 at 10:26:06 Pacific
Reply:

It is the x = proc(int,date,date2) that is causing the problem.

x = proc implies that proc is a function. You cannot return a value from a sub. If you want to return a value to x, then you will need to change the function definition to

public function proc(i as integer,d1 as date,d2 as date) as Integer

assuming that x is an integer.

If you don't want to return a value then remove the x=

One other thing. Do you really need to make the function/sub public. If proc is only called from within the module where it is defined, there is no need to make it public. If proc is defined in a bas module then it is public by default.

Making it public unnecessarily increase memory overheads and does slow down execution slightly, especially if there are lots of them.

Stuart


0

Response Number 2
Name: Eriedor
Date: February 19, 2006 at 14:16:43 Pacific
Reply:

thanks for the reply, however my poorly written first post has caused confusion.

calling

proc(int,date,date2)

gives me a compile error stating "expected :=". in other words it beleives this should be assigned like x=proc(int,date,date2) which doesnt give a compile error.

However ofc this is incorrect as it is a sub not a function. This is driving me insane!! how can vb confuse a sub with a function purely because i added 2 dates for parameters!!


0

Response Number 3
Name: StuartS
Date: February 19, 2006 at 14:26:01 Pacific
Reply:

Remove the parentheses. The are only used when something preceded the procedure name.

proc int,date,date2

or

Call proc(int,date,date2)

Stuart


0

Response Number 4
Name: Eriedor
Date: February 20, 2006 at 04:05:36 Pacific
Reply:

thanks for reply, a fellow student pointed tht out just before i read this lol.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Logoff script erase folde... Javascript help...name ge...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB sub paramters

echo vbs code but errors, help www.computing.net/answers/programming/echo-vbs-code-but-errors-help/18948.html

using shell through VB www.computing.net/answers/programming/using-shell-through-vb/9065.html

newb vb 6 user www.computing.net/answers/programming/newb-vb-6-user/7741.html