PDA

View Full Version : CInt in Visual Basic



CrazyLemurs
17-01-2013, 05:41 PM
Hey everyone
I'm doing 1/3 of 30% of my Computing CA and it's come up in it that I've got to program an ISBN book number calculator
I take in a 10digit number and have to make it to 11digits using some special formula etc etc.
But I take in the number as a string (so if they like type 123456789Q it doesnt crash the program) and have applied an if statement so IF userenter = 1 then DO CONVERSION TO 11DIGITS
But if they type in like ASBHFHKFLJHBS then I have an error as I cant subject a string to operators like = and +.
My teacher said to use CInt command to do this, but how does it work?
And is there any other way I can go about it if CInt isn't ideal?
Thanks in advance for your assistance xxxxxx

Zak
18-01-2013, 12:51 AM
You can convert a string into an integer value by using CInt, or probably better CLng. (CLng accepts a larger amount than CInt).

If you're doing it via database design it's simple. It'll be CInt([TABLENAME].[FEILDNAME]). Though sometimes I use Val().

I have no idea what it would be in VB but I'm guessing it's very similar (google it :D). In short, CInt or CLng just converts a String value to an integer value. SIMPLES!

scottish
18-01-2013, 01:45 AM
http://msdn.microsoft.com/en-us/library/xh29swte(v=vs.80).aspx

CrazyLemurs
18-01-2013, 06:54 AM
Thanks you two
My computing teacher isn't allowed to tell me how to use it because that's cheating and telling me how to solve the program, but I'm within full ability to google an answer xD


I'm currently on my iPhone if you are seeing this message! I cannot participate in spam wars xx

Zak
18-01-2013, 01:50 PM
Thanks you two
My computing teacher isn't allowed to tell me how to use it because that's cheating and telling me how to solve the program, but I'm within full ability to google an answer xD


I'm currently on my iPhone if you are seeing this message! I cannot participate in spam wars xx

No problem, it's very easy to implement. You should have no problem :)

CrazyLemurs
18-01-2013, 05:16 PM
Will it work if the string I enter is like FDKSUGFJKHSTB?

scottish
18-01-2013, 05:34 PM
use IsNumeric(varName) to check

Want to hide these adverts? Register an account for free!