Hi i need some help building an advanced calculator using vb .net
1st i want to calculate the logarithm and the ln; i used math.log(x) but it returned a number different than the one i get using the windows calculator.
Also i need to calculate sin^-1(x) but i cannotmake it
2nd i need a help with keypresses. i made my codes in the form_keypress but when i click on any button it focuses and then the keypress doesn't work and when i press enter the button focused is clicked, i wrote Me.Focus () in each button sub but it didnt work. but when i wrote it under form_lostfocus it worked but i had another problem which is i cant select any item in the list box in this form coz it focus the base form once i click any other control.
So plz i need an accurate solution in VB .NET
Thankss alot

Hi I need a math expert
David Parslow
Cool_DBA
You can also use the Keypreview property of the form. If set to TRUE, the keypress event of the form fires before that of the control....

Setting focus back to a textbox will also work, if you like.
jini shans
i want to handle some events with the form keypress for ex. when the user presses 0 - 9 keys it types the numers and when the user presses the enter key the program runs the codes under the equal button :- (btnEqual_click) .
Handling the keypresses is not the problem but the problem is when the user click on any on the form it focuses then when the user press enter it types the button focused instead of handling equal. i hope it is clear now
now i need help with keypresses and focusing.
p.s. : plz take a look at the microsoft windows calculator.
p.p.s the math.log10(x) worked thanx but still math.asin(x) doesn't give me the value i get in my own calcilator
thanx a lot
abc_acb
Thanx a lot with your example it worked
now i know my problem i wrote sin-1 (x) = Math.Asin(y *180 / Math.PI) and that returned a false number
but with sin-1 (x) = Math.Asin(y) * 180 / Math.PI it wroked
lol i dont know why we converted the input degree to radian at the sin and we didnt convert the input degree to radian and we converted the output
Thanks a lot u r very helpful
RavenSensei1
I'm not exactly sure what you are attempting to do, but it sounds like you do not want the focus to remain on the button controls because you want an "enter" keypress to invoke a specific button.
For this to happen, I think you need to set "TabStop=False" for all your button controls, and in their click events, you need to set focus to some other non-button control, like a text box that displays your numbers, ie: "TextBox1.Focus()". This way focus will appear to remain in the textbox. Then to get the enter key to invoke a specific button, you can set the form's AcceptButton property to your Enter button, ie: "Form1.AcceptButton=btnEnter"
This is how I'd first approach it. There might be a better way to tackle this part of your problem, if you get stuck again, you should post this type of question in the Windows Forms forum.
Thanks,
Adam Braden
Visual Basic Team
maypo
I really want not only the enter key but also some other keys like 0-9 as it is a calculator. so if i disabled the keypreview i cannot use the keyboard keys when i set the focus on a lable or a textbox. just i am searching for the easist and best method to do so (like the windows calculator)
Thanx
JuanK_solocodigo
There should be some online...
Then I am guessing that you could to the agorithm in your program so...
Well, forgive me if I am wrong because I am just a newbie...
Thank You
Lauriemoore
I believe that was your original question. If you can live with that behavior, then yes using Keypreview is your easiest solution. However if you only want the enter key to fire the "=" button's click event, then you'll need to do something about the focus as I mention above.
Adam
Thomas GG
As for asin, it would be best if you give a specific example, but here are a few suggestions:
1) You have probably set your calculator to give results in Degrees rather than Radians. A radian is (180 / PI) degrees, or roughly 57.3o, and is the standard angular unit in mathematics. The functions math.sin and math.asin work in radians. To work with degrees, you need to make a suitable conversion, using the built-in constant math.PI:
Sin (xo) = math.sin (x * math.PI / 180)
Sin-1 (x) = yo where y = math.asin (x) * 180 / math.PI
2) If that is not the problem, you should remember that Arcsine is a multi-valued function, meaning, for example, that one place can define asin (0) = 0 and another place can define asin (0) = PI (Since Sin(PI)=0). Both definitions are fine as long as they are used consistently. The function math.asin uses the popular standard of giving a result in the range [-PI/2,+PI/2], but other calculators may give other results. Using the value given by math.asin in your application is fine.
I hope this solves your problem, and if not, please give a specific example.
Zheng Lu
cnuk
Hope this helps,
Adam
FrankLin1981
For you other question, I'm not exactly sure what you want to accomplish. What should (or should not) happen when you get a keypress event
Best regards,
Johan Stenberg
Mojmir
I don't think writing your own mathematical algorithms would be particularly clever, as they will inevitably be MUCH slower than what could be done with built-in functions.
And such functions are easy to find. The function math.log returns the Natural logarithm (base e, ln). math.log10 returns the decimal logarithm. And if you want the logarithm of x to an arbitary base b, calculate ln x / ln b which is math.log (x) / math.log (b).
The function math.asin returns the arcsine, or inverse sine. Acos and Atan also exist.
If you want more advanced functions, you may have to resort to writing an explicit taylor series, but it seems that all elementary functions are built-in.
As for the keypresses question, I hope the vb.net experts can help you...