Solved

VB 2008  - Convert contents of TextBox to an Integer

Posted on 2009-07-12
3
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Ctime to date time in textfile? 7 81
Find date of 2nd Thursday of each month 3 44
Web page design problem 3 39
Intermittent OleDbConnection Error 20 46
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 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