# Visual Basic Type Mismatch



## Dark_Webster (Jul 20, 2008)

Hey guys, could you help me with a problem?

I'm trying to make a VB program that generates lottery numbers. The thing is, it has a PIN textbox for when the right PIN is introduced, the button for randomize numbers becomes active.

But when I delete the PIN, the program gives me Error 13 Type Mismatch:
I think that if you delete the PIN, the program can't compare because the textbox has Nil value.


```
Private Sub PIN_Change()
[COLOR="Lime"]If PIN = 5454 Then [/COLOR]Command1.Visible = True _
Else: Command1.Visible = False
Label1 = Nil
Label2 = Nil
Label3 = Nil
Label4 = Nil
Label5 = Nil
Label6 = Nil
Label7 = Nil
End Sub
```

The green text is where VB says where is the error. By the way, the DataFormat of the textbox is in Number.

Someone can help me out?? I started to learn VB by my own iniciative.


----------



## Deleted member 3 (Jul 20, 2008)

If PIN is a textbox you need to use PIN.text.


----------



## Dark_Webster (Jul 20, 2008)

DanTheBanjoman said:


> If PIN is a textbox you need to use PIN.text.



Thanks anyway, but it sill gives me the same error using PIN.Text. The only way that I'm capable of changing the PIN is to select the other already written and write the new one.


----------



## Deleted member 3 (Jul 20, 2008)

if you do msgbox(pin.text) and run the sub, does it output anything?


----------



## Dark_Webster (Jul 20, 2008)

Yes, it starts to output the numbers that i write into the textbox into a messagebox.


----------



## Deleted member 3 (Jul 20, 2008)

> Private Sub PIN_Change()
> If PIN = 5454 Then Command1.Visible = True _
> Else: Command1.Visible = False
> Label1 = Nil
> ...



Turn it into 



> Private Sub PIN_Change()
> If PIN.text = 5454 Then
> Command1.Visible = True
> Else
> ...


----------



## Dark_Webster (Jul 20, 2008)

Sorry to say this, but that didn't worked as well. What I think is that if Pin.Text reaches Nil value, it will cause this error.


----------



## Deleted member 3 (Jul 20, 2008)

Dark_Webster said:


> Sorry to say this, but that didn't worked as well. What I think is that if Pin.Text reaches Nil value, it will cause this error.



Actually, that could be the issue

change it to



> Private Sub PIN_Change()
> try
> If PIN.text = 5454 Then
> Command1.Visible = True
> ...



Of course if you leave the msgbox out it'll just go on not saying a thing. Personally I like to make a big multiline textbox and name it errorbox or something similar and output errors to it. So I can always look back at things that went wrong.


----------



## Dark_Webster (Jul 20, 2008)

It now gives me an error refering to "Private Sub PIN_Change()" : Sub or function not defined

Also i'm using VB6 (yes i know its a bit old)


----------



## Deleted member 3 (Jul 20, 2008)

What are you developing in? If it's VS send me your program.


----------



## Dark_Webster (Jul 20, 2008)

I'm developing this in VB6, because I thought that this one would be the best for start programming in VB.


----------



## Deleted member 3 (Jul 20, 2008)

Dark_Webster said:


> I'm developing this in VB6, because I thought that this one would be the best for start programming in VB.



I'd recommend VS, offers everything all other .NET languages do and keeps the simplicity of VB. It's a shame that when you understand VB you have to adapt to another platform to do more with it.

If I'd open your application it would just try to convert it, hence not helping you in any way


----------



## Dark_Webster (Jul 20, 2008)

DanTheBanjoman said:


> I'd recommend VS, offers everything all other .NET languages do and keeps the simplicity of VB. It's a shame that when you understand VB you have to adapt to another platform to do more with it.
> 
> If I'd open your application it would just try to convert it, hence not helping you in any way



Ok, thanks a lot anyway. I'm going to see if I can do something this error anyway, and what VS do you recommend: 2005 or 2008?


----------



## Deleted member 3 (Jul 20, 2008)

Dark_Webster said:


> Ok, thanks a lot anyway. I'm going to see if I can do something this error anyway, and what VS do you recommend: 2005 or 2008?



I use 2005, not sure what 2008 offers though. 

Type mismatch means that you're trying to convert some variable in an impossible way, ie string with text to number and the likes. Nil might cause this, and apparently VB6 doesn't understand try/catch that well. Does it have a function like notnull() to catch the error?


----------



## Oliver_FF (Jul 20, 2008)

```
If PIN.text = [B]"[/B]5454[B]"[/B] Then
```



You can't compare a String with a number


----------



## smartali89 (Jul 20, 2008)

Private Sub PIN_Change()

	If PIN.Text = "5454" Then 
		Command1.Visible = True
	Else
		Command1.Visible = False
		Label1.Caption = ""
		Label2.Caption = ""
		Label3.Caption = ""
		Label4.Caption = ""
		Label5.Caption = ""
		Label6.Caption = ""
		Label7.Caption = ""
	End If
End Sub

Label in VB6 doesn't has the property "Text"


----------



## Deleted member 3 (Jul 20, 2008)

smartali89 said:


> Label in VB6 doesn't has the property "Text"



Another reason to use vb.net


----------



## Oliver_FF (Jul 20, 2008)

Label's have Caption, TextBox's have Text 



> it has a PIN textbox for when...



It's terrible I remember all this, haven't written any VB for years and years - it was my first language


----------

