Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2007, 11:47 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default Simple Q

What does ...

Type Mismatch

Error Code '13'

...mean?

It gets thrown when this code is executed

Code:
If sTitle Or sArtist Or sAlbum Or sGenre Or sLength Or sKey = "" Then
This code is executed by a function called ValidateInput
Code:
Public Function ValidateInput(sTitle As String, sArtist As String, sAlbum As String, sGenre As String, sLength As String, sKey As String) As Boolean
Now i assume that this above means that you can set validateinput as true or false or return it as true or false when its executed some code within or called outide its function.

So on this assumption i tried writing this in a cmdAdd_Click

Code:
ValidateInput = False
Call ValidateInput(txtTitle.Text, txtArt.Text, txtAlb.Text, txtGen.Text, txtLen.Text, txtKey.Text)   
If ValidateInput = True Then
Call AddToGrid(txtTitle.Text, txtArt.Text, txtAlb.Text, txtGen.Text, txtLen.Text, txtKey.Text)
Else
Exit Sub 'this is because if ValidateInput returns false it already handled within the function
End If
But this throws a compile error

Function call on left-hand side of assignment must return Variant or Object

And this means...?

Two questions there, in simple terms
What does Type Mismatch, code '13' mean?
What does Function call on left-hand side of assignment must return Variant or Object mean?

Thanks for any help


------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
__________________
Apocolypse2005, I'm a programmer - of sorts.
 
Old August 7th, 2007, 12:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

step by step:
Code:
If sTitle Or sArtist Or sAlbum Or sGenre Or sLength Or sKey = "" Then
you are trying to compare every string with ""?? if that is the case, vb doesn't handle the if this way (in fact I think that any language do that this way)...
you have to compare every string with = "" something like this:
Code:
If sTitle = "" Or sArtist = "" Or sAlbum  = "" Or = "" sGenre = "" Or sLength = "" Or sKey = "" Then
the error is telling you that it can't convert the strings to boolean (because OR compares boolean values ;) )

your second problem is easily solved if you have option explicit set to on...
since ValidateInput is a function, you cannot assign a value to it (you are doing that when:
Code:
ValidateInput = False
)

you have two ways to do this:
1. Store the returned value of this function in a new variable (maybe ReturnedValue) and then do the if...
2. write the if with the function (ugly to see, but the same result)

Examples:

1.
Code:
dim ReturnedValue as boolean
returnedvalue = ValidateInput(txtTitle.Text, txtArt.Text, txtAlb.Text, txtGen.Text, txtLen.Text, txtKey.Text)   
If returnedValue Then
    AddToGrid(txtTitle.Text, txtArt.Text, txtAlb.Text, txtGen.Text, txtLen.Text, txtKey.Text)
Else
    Exit Sub 'this is because if ValidateInput returns false it already handled within the function
End If
2.
Code:
if ValidateInput(txtTitle.Text, txtArt.Text, txtAlb.Text, txtGen.Text, txtLen.Text, txtKey.Text) Then
    AddToGrid(txtTitle.Text, txtArt.Text, txtAlb.Text, txtGen.Text, txtLen.Text, txtKey.Text)
Else
    Exit Sub 'this is because if ValidateInput returns false it already handled within the function
End If

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 7th, 2007, 01:39 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Can i just ask, what is option expplicit?
 
Old August 7th, 2007, 01:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

by default, VB doesn't need to have the variables declared, which is a awfull way of work.. by adding option explicit to the top of every form, class, module you force declaration of every variable you use...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 7th, 2007, 03:08 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Oh is that why when you upgrade ur vb6 projects to vb2005 it shows a load of cautionsay variable not declared yet?!
 
Old August 8th, 2007, 08:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

probably... and sometimes you need to initialize them too...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Very Simple code Tal1481 Visual Basic 2005 Basics 1 January 25th, 2007 07:15 AM
Simple Program Help hobbit666 Visual Basic 2005 Basics 2 December 19th, 2006 11:51 AM
Simple or Complex richb XML 8 December 12th, 2006 01:40 PM
Simple problem rsa3des Classic ASP Basics 4 August 8th, 2005 06:14 PM
Simple Question MSK888 C# 4 August 1st, 2004 12:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.