Click here to Skip to main content
14,551,234 members
Rate this:
Please Sign up or sign in to vote.
See more:
Guys I have made a convertor that converts a decimal number to a octal number in VB.NET,but it converts only upto 7 digits of decimal number to Octal.If it exceeds 7 digits "Memory Overflow" message is displayed.How To solve this problem guys?


Here Is The Code:
Dim s1,s2 As Atring
Dim i1,i2 As Integer

s1=textbox1.Text
i1=Convert.ToInt64(s1, 10)
s2=Convert.ToString(i1, 8)
i2=Convert.ToInt64(s2, 8)
MsgBox(s2)

but this code is limited only up to 7 characters of input.
Posted
Updated 21-Sep-13 22:56pm
v4
Comments
phil.o 22-Sep-13 1:49am
   
You may begin with showing us the code you wrote :)
Sergey Alexandrovich Kryukov 22-Sep-13 12:11pm
   
Do not use "Convert" is such cases. Use Integer.Parse and System.Object.ToString (with parameters is required). Even if it works the same, it tells you explicitly what you are doing, which is not really "conversion".
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 2

Without seeing your code, we can't be that helpful.
phil.o has given you instruction in how to start debugging your application, but...did you realise that .NET can do this for you?
Dim inp As Integer = 1234567890
Dim oct As String = Convert.ToString(inp, 8)
Console.WriteLine("The Octal value of {1} is {2}", inp, oct)
   
Comments
phil.o 22-Sep-13 3:25am
   
Fair enough ; but solving (and learning to solve) the actual problem could be more useful for the OP than using a predefined method :)
OriginalGriff 22-Sep-13 3:29am
   
Oh, I totally agree - that's why I referred to your post - but it's worth knowing when you are reinventing the wheel as well! :laugh:
phil.o 22-Sep-13 3:33am
   
Unless someone feels a elliptical chaotic random-shaped wheel could be useful to humanity ;)
OriginalGriff 22-Sep-13 4:30am
   
Well, now you mention it... :laugh:
http://www.velobase.com/CompImages/CrankRing/B7C758B9-C6D9-4D86-B3BD-9E82CB4ED9CC.jpeg
A keen cyclist friend of mine used to swear by these in the 80s - effectively it changed the gearing to match the angle of your leg to the pedal and evened out the power of the stroke.
phil.o 22-Sep-13 4:48am
   
Wow! Did you friend survive? :D
OriginalGriff 22-Sep-13 4:55am
   
Regrettably not: the Big C got him in the 90s... :sigh:
Rate this:
Please Sign up or sign in to vote.

Solution 1

Without any code provided, the only solution left for you is to:
- put a beakpoint at the beginning of the method handling the conversion.
- lauch your project in debug mode (F5 in Visual Studio).
- go on from line to line and watch carefully for the values of your variables ; you have to wonder what it is you expect for them, and what you actually get; the difference will point the problem.

[edit]

Seeing your code, then Solution 2 by Original Griff is the one that does exactly what you want to do the way you want to do it, but without limitations.

I would just change the way you get your Int32 value from your textBox:
If (Int32.TryParse(s1, i1))
   s2 = Convert.ToString(i1, 8)
End If


[/edit]
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100