• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Visual Basic Type Mismatch

Joined
Jul 29, 2007
Messages
392 (0.06/day)
Location
Portugal
System Name Lil'Lighty
Processor Intel Core i3 530 @ Stock
Motherboard Asus P7P55D
Cooling Artic Cooling Freezer Pro Rev.2
Memory Gskill Ripjaw 1600MHz 9-9-9-24 8GB
Video Card(s) MSI GeForce GTX650 OC 1GB
Storage WD Blue 500GB AAKS
Display(s) ASUS 20'
Case Aerocool Aeroengine II // Two 120mm Blue Fans
Audio Device(s) Creative SoundBlaster LE // Logitech X-230
Power Supply Corsair VX450W
Software Windows 8.1 Pro x64
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.

Code:
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.
 
Last edited:
Joined
Jul 29, 2007
Messages
392 (0.06/day)
Location
Portugal
System Name Lil'Lighty
Processor Intel Core i3 530 @ Stock
Motherboard Asus P7P55D
Cooling Artic Cooling Freezer Pro Rev.2
Memory Gskill Ripjaw 1600MHz 9-9-9-24 8GB
Video Card(s) MSI GeForce GTX650 OC 1GB
Storage WD Blue 500GB AAKS
Display(s) ASUS 20'
Case Aerocool Aeroengine II // Two 120mm Blue Fans
Audio Device(s) Creative SoundBlaster LE // Logitech X-230
Power Supply Corsair VX450W
Software Windows 8.1 Pro x64
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.
 
Joined
Jul 29, 2007
Messages
392 (0.06/day)
Location
Portugal
System Name Lil'Lighty
Processor Intel Core i3 530 @ Stock
Motherboard Asus P7P55D
Cooling Artic Cooling Freezer Pro Rev.2
Memory Gskill Ripjaw 1600MHz 9-9-9-24 8GB
Video Card(s) MSI GeForce GTX650 OC 1GB
Storage WD Blue 500GB AAKS
Display(s) ASUS 20'
Case Aerocool Aeroengine II // Two 120mm Blue Fans
Audio Device(s) Creative SoundBlaster LE // Logitech X-230
Power Supply Corsair VX450W
Software Windows 8.1 Pro x64
Yes, it starts to output the numbers that i write into the textbox into a messagebox.
 
Joined
May 20, 2004
Messages
10,487 (1.44/day)
Private Sub PIN_Change()
If PIN = 5454 Then Command1.Visible = True _
Else: Command1.Visible = False
Label1 = Nil
Label2 = Nil
Label3 = Nil
Label4 = Nil
Label5 = Nil
Label6 = Nil
Label7 = Nil
End Sub

Turn it into

Private Sub PIN_Change()
If PIN.text = 5454 Then
Command1.Visible = True
Else
Command1.Visible = False
Label1.text = ""
Label2.text = ""
Label3.text = ""
Label4.text = ""
Label5.text = ""
Label6.text = ""
Label7.text = ""
End Sub
 
Joined
Jul 29, 2007
Messages
392 (0.06/day)
Location
Portugal
System Name Lil'Lighty
Processor Intel Core i3 530 @ Stock
Motherboard Asus P7P55D
Cooling Artic Cooling Freezer Pro Rev.2
Memory Gskill Ripjaw 1600MHz 9-9-9-24 8GB
Video Card(s) MSI GeForce GTX650 OC 1GB
Storage WD Blue 500GB AAKS
Display(s) ASUS 20'
Case Aerocool Aeroengine II // Two 120mm Blue Fans
Audio Device(s) Creative SoundBlaster LE // Logitech X-230
Power Supply Corsair VX450W
Software Windows 8.1 Pro x64
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.
 
Joined
May 20, 2004
Messages
10,487 (1.44/day)
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
Else
Command1.Visible = False
Label1.text = ""
Label2.text = ""
Label3.text = ""
Label4.text = ""
Label5.text = ""
Label6.text = ""
Label7.text = ""
catch e as exception
msgbox("OMFG THE PRGRAMZ CRASHED!")
end try
End Sub

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.
 
Joined
Jul 29, 2007
Messages
392 (0.06/day)
Location
Portugal
System Name Lil'Lighty
Processor Intel Core i3 530 @ Stock
Motherboard Asus P7P55D
Cooling Artic Cooling Freezer Pro Rev.2
Memory Gskill Ripjaw 1600MHz 9-9-9-24 8GB
Video Card(s) MSI GeForce GTX650 OC 1GB
Storage WD Blue 500GB AAKS
Display(s) ASUS 20'
Case Aerocool Aeroengine II // Two 120mm Blue Fans
Audio Device(s) Creative SoundBlaster LE // Logitech X-230
Power Supply Corsair VX450W
Software Windows 8.1 Pro x64
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)
 
Joined
Jul 29, 2007
Messages
392 (0.06/day)
Location
Portugal
System Name Lil'Lighty
Processor Intel Core i3 530 @ Stock
Motherboard Asus P7P55D
Cooling Artic Cooling Freezer Pro Rev.2
Memory Gskill Ripjaw 1600MHz 9-9-9-24 8GB
Video Card(s) MSI GeForce GTX650 OC 1GB
Storage WD Blue 500GB AAKS
Display(s) ASUS 20'
Case Aerocool Aeroengine II // Two 120mm Blue Fans
Audio Device(s) Creative SoundBlaster LE // Logitech X-230
Power Supply Corsair VX450W
Software Windows 8.1 Pro x64
I'm developing this in VB6, because I thought that this one would be the best for start programming in VB.
 
Joined
May 20, 2004
Messages
10,487 (1.44/day)
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 :)
 
Joined
Jul 29, 2007
Messages
392 (0.06/day)
Location
Portugal
System Name Lil'Lighty
Processor Intel Core i3 530 @ Stock
Motherboard Asus P7P55D
Cooling Artic Cooling Freezer Pro Rev.2
Memory Gskill Ripjaw 1600MHz 9-9-9-24 8GB
Video Card(s) MSI GeForce GTX650 OC 1GB
Storage WD Blue 500GB AAKS
Display(s) ASUS 20'
Case Aerocool Aeroengine II // Two 120mm Blue Fans
Audio Device(s) Creative SoundBlaster LE // Logitech X-230
Power Supply Corsair VX450W
Software Windows 8.1 Pro x64
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?
 
Joined
May 20, 2004
Messages
10,487 (1.44/day)
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

New Member
Joined
Oct 15, 2006
Messages
544 (0.08/day)
Processor Intel q9400 @ stock
Motherboard Lanparty P45-T2RS
Cooling Zalman CNPS-9500
Memory 8GB OCZ PC2-6400
Video Card(s) BFG Nvidia GTX285 OC
Storage 1TB, 500GB, 500GB
Display(s) 20" Samsung T200HD
Case Antec Mini P180
Audio Device(s) Sound Blaster X-Fi Elite Pro
Power Supply 700w Hiper
Software Ubuntu x64 virtualising Vista
Code:
If PIN.text = [B]"[/B]5454[B]"[/B] Then

;)

You can't compare a String with a number :cool:
 
Joined
Dec 1, 2007
Messages
528 (0.09/day)
Location
Karachi, Pakistan
System Name mAkS
Processor Intel Core 2 Duo E0 E8400 @3.0Ghz (Acheived 4.4Ghz On Stock Cooling)
Motherboard Asus P5K-V (Dead :[ )
Cooling CPU + Front + Rear + Side
Memory XMS2 DHX TWIN2X2048-6400C5DHX/800 BUS
Video Card(s) Inno3D 9600 GT Overclocked
Storage Seagate Sata II 250 GB ++ 500 GB
Display(s) Hp 2009f 20-inch Wide-screen
Case Legend
Audio Device(s) Build-In 8 CHannel (Dell 5.1")
Power Supply CoolerMaster 460W eXtreme Power Plus
Software Many
Benchmark Scores E8400 hardware rank 94th on hwbot in wPrime :D
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"
 

Oliver_FF

New Member
Joined
Oct 15, 2006
Messages
544 (0.08/day)
Processor Intel q9400 @ stock
Motherboard Lanparty P45-T2RS
Cooling Zalman CNPS-9500
Memory 8GB OCZ PC2-6400
Video Card(s) BFG Nvidia GTX285 OC
Storage 1TB, 500GB, 500GB
Display(s) 20" Samsung T200HD
Case Antec Mini P180
Audio Device(s) Sound Blaster X-Fi Elite Pro
Power Supply 700w Hiper
Software Ubuntu x64 virtualising Vista
Label's have Caption, TextBox's have Text :toast:

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 :laugh:
 
Top