Parsing

i want to parse string value into integer how can i do
LVL 2
ahmadfuwadAsked:
Who is Participating?
 
drichardsConnect With a Mentor Commented:
Depends on the string.  The simplest approach is to use Integer.Parse:

    val = Integer.Parse(str)

where val is the integer variable and str is the string variable.
0
 
RacinRanCommented:
Or you could use the old school VB 6 approach of:

val = CInt(str)

but either way ... I would do this in a Try Catch block and add a catch:

 Catch ex as InvalidCastException

This way you'll know an error occurred trying to parse the string in case it's not a valid integer and you can provide specific feedback to the user, if this is where it's coming from.

0
 
jerrycsakanyjrCommented:
Try this

on error goto badstring

dim myInt as integer
dim myStr as string
myStr= "you string"
myint = asc(myStr)

msgbox(myint)

badstring:
msgbox("Invalid Characters")
exit sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.