Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello, I've been spending most of the day trying to figure out how to properly convert from an integer to a string; so I can add a loop where if you input a letter instead of a number you have to re-enter.the number instead of just crashing. If anyone can point me in the right direction it would be much appreciated.

What I have tried:

Ive tried things along this line:
VB
Score = Console.ReadLine() Or Score = CStr(Score)
Posted
Updated 28-Feb-16 20:07pm
Comments
Kenneth Haugland 28-Feb-16 20:01pm    
Dim MyNumber as integer
MyNumber = 5
MyNumber.ToString
koolprasad2003 28-Feb-16 23:38pm    
Haven't you tried toString() method of int class ? it is bit simple
int a = 10;
string sz = a.toString();
Member 12312671 29-Feb-16 19:33pm    
sorry I've been busy with assignments all day I've been playing with it for a couple hours I'll try out all these methods tonight but right now I have meet a friend (paying me back)

1 solution

Read it as a string, then use Integer.TryParse to convert it:
VB.NET
Dim x As Integer
If Not Integer.TryParse(stringFromUser, x) Then
	' report problem to user.
        Return
End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900