Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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!!

Remove the parentheses. The are only used when something preceded the procedure name.
proc int,date,date2
or
Call proc(int,date,date2)
Stuart

![]() |
Logoff script erase folde...
|
Javascript help...name ge...
|

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