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

Using CInt() on textbox value causes "type mismatch"

Status
Not open for further replies.

slicendice

Programmer
Joined
Jun 28, 2002
Messages
164
Location
GB
Hi
I have a very simple bit of code that is trying to do a CInt conversion on the numerical content of a textbox (i.e. make it an Int if a decimal has been specified). The line of code in question is:

txtMWMins(Index).Text = CStr(CInt(txtMWMins(Index).Text))

However I get a "type mismatch" error occurring and I'm not too sure why! I've tried just a simple type conversion using:

Dim x as Integer
x = CInt(txtMWMins(Index).Text)

but get exactly the same problem!

Thanks
 
Is variable Index in scope when you run the line? In other words did you try with a fixed value in place of Index


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Sorry, I should have mentioned that! The code is for a control that is part of a control array - "Index" is just the index of the control in question
 
DOH DOH DOH!!!!

Apologies! Just found out the prob.....the event was getting fired before txtMWMins(Index).Text had a value in it, so it was tryring to do a CInt() on a null string!

Strangely enough, it all seems to work fine now I've put a check for vbNullString before doing the conversion!

Sorry about that - was just me being a numb-nuts!

Thanks johnwm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top