Click here to Skip to main content
16,016,501 members
Please Sign up or sign in to vote.
1.00/5 (1 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:
VB
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

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?
C#
Dim inp As Integer = 1234567890
Dim oct As String = Convert.ToString(inp, 8)
Console.WriteLine("The Octal value of {1} is {2}", inp, oct)
 
Share this answer
 
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
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:
VB
If (Int32.TryParse(s1, i1))
   s2 = Convert.ToString(i1, 8)
End If


[/edit]
 
Share this answer
 
v2

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