Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2008

Tip: Looking for answers? Try searching our database.

Int conversion

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SK - 03 Mar 2008 15:07 GMT
Hi All,

       Dim str As String
       Dim myParsedInt As Integer

       str = "3,3,4"

       myParsedInt = CInt(str)
       MessageBox.Show(myParsedInt)

I get 334 as result but I need it to be 3,3,4 as an integer.

Any help!

Thanks,
Sonu
Jon Skeet [C# MVP] - 03 Mar 2008 15:17 GMT
>         Dim str As String
>         Dim myParsedInt As Integer
[quoted text clipped - 5 lines]
>
> I get 334 as result but I need it to be 3,3,4 as an integer.

3,3,4 isn't an integer though - it's three integers.

What single integer do you want to get back, and why?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

SK - 03 Mar 2008 16:13 GMT
Well this is what I am trying to do

Select Case ID
Case 1,3,5
   do....
End Select

Now works with it but I need to read 1,3,5 programmatically from a file and
it doesn't work 'coz it treat 1,3,5 as 135 if I use CInt(str).
Where str is a string = "1,3,5"

So I need to read whatever data is there in a file for these values like
4,5,7,8 into a case statement

Select Case ID
Case 4,5,7,8
   do....
End Select

I'm stuck :(

Thanks,
Sonu

>>         Dim str As String
>>         Dim myParsedInt As Integer
[quoted text clipped - 9 lines]
>
> What single integer do you want to get back, and why?
Jon Skeet [C# MVP] - 03 Mar 2008 16:32 GMT
> Well this is what I am trying to do
>
[quoted text clipped - 16 lines]
>
> I'm stuck :(

Right - your problem is that you're trying to parse it as a single
number. 1, 3, 5 represent three different options. You need to:

1) Split the string by commas
2) Parse each of them as an integer
3) Check if the test ID is equal to *any* of the integers

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

SK - 03 Mar 2008 16:57 GMT
Could you please give an example..?
Thanks

>> Well this is what I am trying to do
>>
[quoted text clipped - 24 lines]
> 2) Parse each of them as an integer
> 3) Check if the test ID is equal to *any* of the integers
Peter Duniho - 03 Mar 2008 18:58 GMT
> Well this is what I am trying to do
>
[quoted text clipped - 6 lines]
> and it doesn't work 'coz it treat 1,3,5 as 135 if I use CInt(str).
> Where str is a string = "1,3,5"

If the string is "1,3,5" and you want to read the string as individual  
integers separated by commas, then you may want to use the String.Split()  
method to get three different strings, each of which you can parse.

But it's not clear that's actually going to address your question.

In the VB code you posted, the code in the "Case" will be executed if the  
integer is _any_ of the three listed.  If your file actually specifies a  
string reading "1,3,5", does that mean you only want to execute the code  
if that string matches _all_ of the options?  Does it mean that you want  
to execute the code _once_ if the string matches _any_ of the options?  Or  
does it meant that for each integer in the string, you want to execute the  
code in that "Case"?  Or perhaps some other possibility I haven't even  
mentioned?

As you've asked it, your question is ambiguous and until you state your  
question more clearly, no one will be able to provide you with the details  
you want.

Pete
SK - 05 Mar 2008 04:04 GMT
It is working Sir.

Thanks

> Hi All,
>
[quoted text clipped - 12 lines]
> Thanks,
> Sonu

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.