I always thought that (x&) is passable as an argument to a Sub expecting (x As Long)!
I was wrong (I think!).
I got the dreaded "byref argument type mismatch" from this code:
Private Sub Form_Load()
Dim txt$
txt$ = "12345"
dim i as long
i = 100
Call ci(txt$, 1, i)
End Sub
Sub ci(txt$, Optional x&, Optional y&)
' do something
End Sub
The error seems to occur before i assumes any value.
I solved it by either this:
Dim i&
OR this:
Sub ci(txt$, Optional x AS LONG, Optional y AS LONG)
In other word, (&) and (AS LONG) do NOT seem to be equal!
I always thought that (x&) is passable as an argument to a Sub expecting (x As Long)!
I was wrong (I think!).
I got the dreaded "byref argument type mismatch" from this code:
Private Sub Form_Load()
Dim txt$
Dim i, x, y As Long
txt$ = "12345"
x = 5: y = 2
i = ci(txt$, x, y)
End Sub
Function ci(txt$, Optional x&, Optional y&)
MsgBox (Str$(x&) & Str$(y&))
End Function
The error seems to occur before i assumes any value.
I solved it by either this:
Dim i&
OR this:
Sub ci(txt$, Optional x AS LONG, Optional y AS LONG)
In other word, (&) and (AS LONG) do NOT seem to be equal!
Please explain! (I use VB6)
Hi,
I think the problem with your variable declaratin.
in vb6, if multiple variables are declared in a single statement then the last varialbel is declared with the specified type and rest will become a variant (an untyped variable)
Dim i, x, y As Long
Here only y is declared as long whereas i and x are declared as a variant
take note of this and try changing your code accordingly.
Also for maintainability it's better to code the long hand way, that way when you come back to your code in a year's time you know exactly what you where passing and dont have to revert to the online help to remind you what the shorthand syntax means.
If you find my answers helpful, dont forget to rate me
Bookmarks