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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

type mismatch

Status
Not open for further replies.

domt

Programmer
Mar 13, 2001
115
0
0
US
I have a series of 6 boolean values to test with an If statement (If Nt1 = True and Nt2 = True and Nt3 = True etc.) Then ....
However, I get a Type Mismatch error message at that If statement. Can anyone tell me why?
domt
 
How can we tell you what's wrong with your code if you don't show it to us? Include the code where you define the variables.


 
Thanksfor your prompt responce guys.

Here is the portion of the code in question:

Call TestNu(Ct5)
If NuTestS1 = False Or NuTestS2 = False Or NuTestS3 = False Or NuTestV = False Or NuTestH = False Then
Label12(Ct5).Caption = " "
End If
NuTestS1, NuTestS2, etc are all defined as Boolean. Each individual ones check out properly in the returned statement as True or False as determined by the TestNu(Ct5) testing procedure, but the If statement itself gives the Type Mismatch error mssage.
Domt
 
Can you show the actual Dim statement

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Also what is Ct5 defined as?

because if it isn't an integer or long, you'll have trouble!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
NuTestS1, NuTestS2, etc are all defined as Boolean and Ct5 as Integer in the Option Explicit heading.
 
Still looks like it could be a Variant problem - hence my request for the ACTUAL Dim statement

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
I completely agree with johnwm. Try adding this code.

Code:
    [!]MsgBox "Ct5: " & TypeName(ct5)
    MsgBox "NuTestS1: " & TypeName(NuTestS1)
    MsgBox "NuTestS2: " & TypeName(NuTestS2)
    MsgBox "NuTestS3: " & TypeName(NuTestS3)
    MsgBox "NuTestV: " & TypeName(NuTestV)
    MsgBox "NuTestH: " & TypeName(NuTestH)[/!]
    
    Call TestNu(ct5)
    If NuTestS1 = False Or NuTestS2 = False Or NuTestS3 = False Or NuTestV = False Or NuTestH = False Then
        Label12(ct5).Caption = " "
    End If

Of course, once you solve this problem, you'll want to remove the code I just suggested, but this will likely help you to figure out the problem. If the problem isn't obvious after running this, the post the contents of the message boxes and someone here will help you more.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
What johnwm is suspecting would be:
Code:
Dim NuTestS1, NuTestS2, NuTestS3, NuTestV, NuTestH As Boolean
which I've seen many times before.

In a statement like this only NuTestH is a Boolean, all other variables are of type of Variant.

In the case like this, change it to:
Code:
Dim NuTestS1 As Boolean
Dim NuTestS2 As Boolean
Dim NuTestS3 As Boolean
Dim NuTestV As Boolean
Dim NuTestH As Boolean


Have fun.

---- Andy
 
Here is a copy of the actual Option Explicit statements:
Option Explicit
Dim Ct1 As Integer, Ct2 As Integer, Ct5 As Integer
Dim NuTestV As Boolean, NuTestH As Boolean
Dim NuTestS1 As Boolean, NuTestS2 As Boolean, NuTestS3 As Boolean

gmmastros' MsgBoxcode also assures us that every thing is dimmensioned properly.
 
I suspect an operator precedence problem. Doesn't OR evaluate before =?

Try this code, which is the equivalent of what you want:
Code:
    If Not(NuTestS1 And NuTestS2 And NuTestS3 And NuTestV And NuTestH) Then
        Label12(ct5).Caption = " "
    End If
 
I suspect your problem is with "Call TestNu(Ct5)"
it seems that if you are making a call to TestNu then this is where you are changing the values of NuTestS1 and so on.

 
Guys, thank you all for your interest and help.
The problem was with another part of the program where the test was called twice by mistake. The program is behaving now.
Its great to have people like you to call on.
Dom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top