Hi I need a math expert

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



Answer this question

Hi I need a math expert

  • John999

    Hi,

    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.

  • daxwhit

    Thanx Justdave important to enable the keypreview

  • veugelenw

    thanx holy fire for the help...

  • NozTheGK

    hi
    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

  • Alan Brewer

    Yes - you need to use both.  Key preview for your numeric keys, but you also need to set focus off the command buttons so that you can trap an enter keypress.

    Hope this helps,
    Adam

  • me_someone

    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.Big Smile


  • TkNeo

    System.Math.Asin

    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



  • Roger Rombooth

    Thanx Adam

    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

  • Arvind Agarwal - Skelta

    Hey Holy-Fire
    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

  • RMan54

    look for agorithms for sine and ln and so forth...
    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


  • vbrada

    Keypreview does not work for the Enter keypress when focus is on a command button - in this case only the Click event for the button control that has focus gets fired.

    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

  • Tebby

    Major,
    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

  • ChrisThomas

    Hi.
    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...

  • Hi I need a math expert