Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

emergency!!! i need help!!!

red3warlordred3warlord Member Posts: 77
i am now suffering from severe migrain and the only reason is that i can't get the idea of how to program a calculator.... my instructor asked me to find out how to make a calculator....

i can't figure it out....

here's my problem...:

there is only one textbox for ten command buttons, ranging from 0 upto 9, respectively. let's say, i click on the command buttn (1). the output will be shown on the textbox. then i will click another button. but when i click any button, the previous output of command button (1) will disappear.


here is my question...:


how can i make the output of the previous one to the next one? i mean, how can these both output will merge?


from red3warlord with gratitude...

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    I'm thinking the following:

    Save whether a calculation was started in a boolean.
    Then, when a user click a button, check if the calculation started.
    If not: set calculation started to true, save the contents of the textbox to a variable (a member of the Form, just like the boolean). Also save which operation this button represents to a variable.
    If calculation had started: take the previous input, take the current input and apply the previous operation to it (the one saved in the member variable). Then save the result of this along with the current operation to the member variables.

    This way, it'll work like a standard calculator.
    To reset it (clear) just set calculation started to false.

    Is this making sense to you?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • Max_AliMax_Ali Member Posts: 7
    : i am now suffering from severe migrain and the only reason is that i
    : can't get the idea of how to program a calculator.... my instructor
    : asked me to find out how to make a calculator....
    :
    : i can't figure it out....
    :
    : here's my problem...:
    :
    : there is only one textbox for ten command buttons, ranging from 0
    : upto 9, respectively. let's say, i click on the command buttn (1).
    : the output will be shown on the textbox. then i will click another
    : button. but when i click any button, the previous output of command
    : button (1) will disappear.
    :
    :
    : here is my question...:
    :
    :
    : how can i make the output of the previous one to the next one? i
    : mean, how can these both output will merge?
    :
    :
    : from red3warlord with gratitude...

    It's Piece of cake:
    ** first of all remember to use the button as an index button. that mean the Index value (0..9).
    follow these step
    1. make the textbox default value 0
    2. in the Command_click event insert Case Statment to identify the pressed button, in the every statment type these code:
    txtresult = txtresult + cmdvalue 'cmdvalue is the value of the pressed button
    3. and so on for each statment in the Case.

    i hope this will be useful
    Max_VB

  • red3warlordred3warlord Member Posts: 77
    : : i am now suffering from severe migrain and the only reason is that i
    : : can't get the idea of how to program a calculator.... my instructor
    : : asked me to find out how to make a calculator....
    : :
    : : i can't figure it out....
    : :
    : : here's my problem...:
    : :
    : : there is only one textbox for ten command buttons, ranging from 0
    : : upto 9, respectively. let's say, i click on the command buttn (1).
    : : the output will be shown on the textbox. then i will click another
    : : button. but when i click any button, the previous output of command
    : : button (1) will disappear.
    : :
    : :
    : : here is my question...:
    : :
    : :
    : : how can i make the output of the previous one to the next one? i
    : : mean, how can these both output will merge?
    : :
    : :
    : : from red3warlord with gratitude...
    :
    : It's Piece of cake:
    : ** first of all remember to use the button as an index button. that
    : mean the Index value (0..9).
    : follow these step
    : 1. make the textbox default value 0
    : 2. in the Command_click event insert Case Statment to identify
    : the pressed button, in the every statment type these code:
    : txtresult = txtresult + cmdvalue 'cmdvalue is the value of the
    : pressed button
    : 3. and so on for each statment in the Case.
    :
    : i hope this will be useful
    : Max_VB
    :
    :
    thanks for the information you had givnen me. this helps me a lot....

    as of now, i have a new problem with regards to visual basic, but i must aplly it to database using Microsoft Office Access. how can i make a calculator? i do now have the codes of the command buttons '+' and '='. but i don't have the other 3, namely, '/', '-', '*', respectively.

    at the same time, i will also apply the convertion into my calculator, from decimal to binary, hexadecimal, and octal.

    how can i convert the value which i had input to the calculator, if the value is unknown? the value will only exist when a user will input it. how's that one?




    from red3warlord with gratitude
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : thanks for the information you had givnen me. this helps me a lot....
    :
    : as of now, i have a new problem with regards to visual basic, but i
    : must aplly it to database using Microsoft Office Access. how can i
    : make a calculator? i do now have the codes of the command buttons
    : '+' and '='. but i don't have the other 3, namely, '/', '-', '*',
    : respectively.
    :

    The difference between + and the rest, is only in the line:
    [code]
    lNewNumber = lOldNumber [color=Blue]-> + <-[/color] lCurrentNumber
    [/code]

    : at the same time, i will also apply the convertion into my
    : calculator, from decimal to binary, hexadecimal, and octal.
    :
    : how can i convert the value which i had input to the calculator, if
    : the value is unknown? the value will only exist when a user will
    : input it. how's that one?
    :
    The algorithm is as follows:
    [code]
    Get the number
    Get the base (like 10 based - decimal, or 16 - hexadecimal, etc)

    Repeat the following:
    Divide number by base.
    The remainder after division is the index into the CharString (see below)
    Repeat the loop with number being the result after division
    (eg:
    Loop
    current digit = number Mod base
    number = Int(number / base)
    Do While (number <> 0)
    )

    Use this string for CharString. It'll work with up to 36-base conversions:
    "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    (36 = 10 normal numbers, plus 26 letters of the alfabet)
    [/code]
    Ofcourse, for a number to Hex string you can use the Hex() function.
    If you have a hex word and want it to a number, use CLng("&H" & HexNumber).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.