Home
Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
VB.NET
Windows Forms
Calculator App w/ VB.Net
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="lmo10" data-source="post: 6330" data-attributes="member: 2494"><p>I am very new to VB.Net and as a first project I am trying to build a calculator similar to the windows scientific calculator. I have a specific problem when I try to convert a binary Qword to decimal. I am using this loop:</p><p></p><p><span style="font-size: 10px"><span style="color: #0000ff">Public</span></span><span style="font-size: 10px"><span style="color: #0000ff">Function</span></span><span style="font-size: 10px"> BTD(</span><span style="font-size: 10px"><span style="color: #0000ff">ByVal</span></span><span style="font-size: 10px"> Bin </span><span style="font-size: 10px"><span style="color: #0000ff">As</span></span><span style="font-size: 10px"><span style="color: #0000ff">String</span></span><span style="font-size: 10px">) </span><span style="font-size: 10px"><span style="color: #0000ff">As </span></span><span style="font-size: 10px"><span style="color: #0000ff">String</span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span><span style="font-size: 10px"><span style="color: #0000ff">Dim</span></span><span style="font-size: 10px"> i </span><span style="font-size: 10px"><span style="color: #0000ff">As</span></span><span style="font-size: 10px"><span style="color: #0000ff">Integer</span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span><span style="font-size: 10px"><span style="color: #0000ff">Dim</span></span><span style="font-size: 10px"> Dec </span><span style="font-size: 10px"><span style="color: #0000ff">As </span></span><span style="font-size: 10px"><span style="color: #0000ff">Long</span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span><span style="font-size: 10px"><span style="color: #0000ff">For</span></span><span style="font-size: 10px"> i = Bin.Length </span><span style="font-size: 10px"><span style="color: #0000ff">To</span></span><span style="font-size: 10px"> 1 </span><span style="font-size: 10px"><span style="color: #0000ff">Step</span></span><span style="font-size: 10px"> -1</span></p><p><span style="font-size: 10px"></span></p><p><span style="font-size: 10px"></span><span style="font-size: 10px"><span style="color: #0000ff">If</span></span><span style="font-size: 10px"> Mid(Bin, i, 1) </span><span style="font-size: 10px"><span style="color: #0000ff">And</span></span><span style="font-size: 10px"> 1 </span><span style="font-size: 10px"><span style="color: #0000ff">Then</span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span><span style="font-size: 10px">Dec = Dec + 2 ^ (Bin.Length - i)</span></p><p><span style="font-size: 10px"></span></p><p><span style="font-size: 10px"></span><span style="font-size: 10px"><span style="color: #0000ff">End</span></span><span style="font-size: 10px"><span style="color: #0000ff">If</span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span><span style="font-size: 10px"><span style="color: #0000ff">Next</span></span><span style="font-size: 10px"> i</span></p><p><span style="font-size: 10px"></span></p><p><span style="font-size: 10px">keyData = Dec</span></p><p><span style="font-size: 10px"></span></p><p><span style="font-size: 10px"></span><span style="font-size: 10px"><span style="color: #0000ff">End</span></span><span style="font-size: 10px"><span style="color: #0000ff">Function</span></span></p><p></p><p><span style="font-size: 10px"><span style="color: #0000ff">Using the Long Data Type I get an Arithmetic Overflow Exception and if I use the String Data Type the result for DEC is in scientific notation (xx+Exx) with this as a value I dont know how to translate it back to a numeral that can be used in converting to another base (say the user wants to convert the value to hex after converting from binary to decimal). So my question is how do I handle large numbers like this? </span></span></p><p></p><p><span style="font-size: 10px"><span style="color: #0000ff">i.e:</span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff">If the original Binary Qword value is equivalent to 2^64 the decimal number would be "18446744073709551616" which is too large for the Long Data Type.</span></span></p><p></p><p><span style="font-size: 10px"><span style="color: #0000ff">Is the loop I am using correct for this situation(It works for Dword values) or should I rethink the approach as a whole?</span></span></p><p></p><p><span style="font-size: 10px"><span style="color: #0000ff">Note The windows calculator handles these correctly If someone knows how its done in the windows calc please let me know. I am just starting out with VB.Net so any guidenece will be appreciated.</span></span></p><p><span style="font-size: 10px"><span style="color: #0000ff"></span></span></p></blockquote><p></p>
[QUOTE="lmo10, post: 6330, member: 2494"] I am very new to VB.Net and as a first project I am trying to build a calculator similar to the windows scientific calculator. I have a specific problem when I try to convert a binary Qword to decimal. I am using this loop: [size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] BTD([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] Bin [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2]) [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]String [/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] i [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer [/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] Dec [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Long [/color][/size][size=2][color=#0000ff]For[/color][/size][size=2] i = Bin.Length [/size][size=2][color=#0000ff]To[/color][/size][size=2] 1 [/size][size=2][color=#0000ff]Step[/color][/size][size=2] -1 [/size][size=2][color=#0000ff]If[/color][/size][size=2] Mid(Bin, i, 1) [/size][size=2][color=#0000ff]And[/color][/size][size=2] 1 [/size][size=2][color=#0000ff]Then [/color][/size][size=2]Dec = Dec + 2 ^ (Bin.Length - i) [/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If [/color][/size][size=2][color=#0000ff]Next[/color][/size][size=2] i keyData = Dec [/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Function[/color][/size] [size=2][color=#0000ff]Using the Long Data Type I get an Arithmetic Overflow Exception and if I use the String Data Type the result for DEC is in scientific notation (xx+Exx) with this as a value I dont know how to translate it back to a numeral that can be used in converting to another base (say the user wants to convert the value to hex after converting from binary to decimal). So my question is how do I handle large numbers like this? [/color][/size] [size=2][color=#0000ff]i.e:[/color][/size] [size=2][color=#0000ff]If the original Binary Qword value is equivalent to 2^64 the decimal number would be "18446744073709551616" which is too large for the Long Data Type.[/color][/size] [size=2][color=#0000ff]Is the loop I am using correct for this situation(It works for Dword values) or should I rethink the approach as a whole?[/color][/size] [size=2][color=#0000ff]Note The windows calculator handles these correctly If someone knows how its done in the windows calc please let me know. I am just starting out with VB.Net so any guidenece will be appreciated. [/color][/size] [/QUOTE]
Insert quotes…
Verification
Post reply
Home
Forums
VB.NET
Windows Forms
Calculator App w/ VB.Net
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom