Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

By Ref Argument Type Mismatch Error

Status
Not open for further replies.

DugzDMan

Programmer
Oct 19, 2000
157
US
Where am I going wrong here? I just don't see it.

do stuff...
Call CreateSQL("CPU", "", dtUsageDate, strLPAR, dUsage)
do more stuff...

Public Sub CreateSQL(DataType As String, FileType As String, UsageDate As Date, LPAR as String, UsageAmount As Double)

strSQL = "INSERT INTO MyDB.MyTable ('" & DataType & "','" & FileType & "','" & Format(UsageDate, "mm/dd/yyyy") & "','" & strLPAR & "'," & UsageAmount & ");"

End Sub

It's giving me an error on strLPAR when I try to call the sub. When I remove that, it gives me one on dUsage.

Any ideas where I messed up?

Thanks!
 
You could try using
ByVar LPAR as String
Which may work if a Null isn't being passed.
Or you could converty the types: Cstr(strLPAR).

But first I would check what types you are declaring the variables as. Maybe you could post these here.
 
The variables are declared as the same types as the sub is expecting, I did check that first :)

Then I put in the ByVal and DOH! That did the trick!

Thanks!!
 
Which means the variables probably are not of the same type...

How are they declared? And, is Option Explicit at the top of the module/class?
 
I do have Option Explicit.

Here are the declarations (there are many more, but these are the ones used with the Sub):
Code:
Dim strData, strFileType, strLPAR as String
Dim dtUsageDate as Date
Dim dCurrentMonth as Double
Here is the call:
Code:
Call CreateSQL(strData, strFileType, dtUsageDate, strLPAR, dCurrentMonth)
Here is the Sub:
Code:
Public Sub CreateSQL(ByVal DataType As String, ByVal FileType As String, ByVal UsageDate As Date, ByVal LPAR As String, ByVal UsageAmount As Double)

strSQL = "INSERT INTO SPECIAL_TABLES.CABS_CPU_DASD_USAGE_DATA ('" & DataType & "','" & FileType & "','" & Format(UsageDate, "mm/dd/yyyy") & "','" & strLPAR & "'," & UsageAmount & ");"
intLoadCount = intLoadCount + 1
Print #2, strSQL
    
End Sub
 
Yuo have cunningly, abd probably without realising it, managed to declare strData and strFileType as Variants...
 

>But first I would check what types you are declaring the variables as. Maybe you could post these here.

>...Or you could convert the types: Cstr(strLPAR).

>Which means the variables probably are not of the same type...

>>How are they declared

> managed to declare strData and strFileType as Variants...

Exactly!

DugzDMan, you stated:

>The variables are declared as the same types as the sub is expecting, I did check that first

You see, that was the problem all along...as we have assumed.

Dim strData as String, strFileType as String, strLPAR as String
Dim dtUsageDate as Date
Dim dCurrentMonth as Double

You cannot declare variables to be the same type all on one line as you have.
Each need to be declared individually in VB6.
(Changed in VB.NET to work as you might expect though)

 
Ah, in my VB class (years ago), that's the way we did it. I didn't realize you couldn't string them along like that. Which basically means I have hundreds of illegitimate variants running around work :)

Thanks for the help all!!
 

Yep.
But I'm happy to see you are still smiling...
 
Unplanned job security!

That and I learned something new. Guess I can go home now, my day is complete (somehow I don't think they'll go for that).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top