Solved

VB 2008  - Convert contents of TextBox to an Integer

Posted on 2009-07-12
3
298 Views
Last Modified: 2012-05-07
ActiveAns is a textbox.  It may contain Nothing or an integer.  If it contains a number I need to convert that to (n) as below.  I can't seem to do this without runtime errors that say it cannot convert it.  

How do I test ActiveAns and then convert the contents of ActiveAns to n ?


If IsNumeric(ActiveAns.Text) And ActiveAns.Text > 0 Then

    Dim n As Integer = Int(ActiveAns.Text)

    blah blah blah

End If

Open in new window

0
Comment
Question by:ljcor
3 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 24833637
Use the Integer.TryParse method....

        Dim n As Integer
        If Integer.TryParse(ActiveAns.Text, n) Then
            MsgBox(n.ToString & " is an integer")
        Else
            MsgBox("is not an integer")
        End If

Wayne
0
 
LVL 2

Expert Comment

by:Moed
ID: 24834070
If IsNumeric(ActiveAns.Text) And ActiveAns.Text > 0 Then
try
    Dim n As Integer = Int(ActiveAns.Text)
    blah blah blah
catch ex as exception
Msgbox("Entry must be a number")
end try
End If

0
 

Author Closing Comment

by:ljcor
ID: 31602542
Thanks to each of you for your advice.  I didn't use the second solution because I thought I had used it earlier without a result.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now