Results 1 to 12 of 12

Thread: numeric calculator

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Greensboro,NC USA
    Posts
    9

    Post

    I am new to VB and I am attemping to create a numeric calculator with basic math functions(+-*/)

    I have created the form using a text box for the display and command buttons for each number 0-9 and each function.

    Does anyone know how I should go about attaching the code and how it should read?

    Thanks in advance for any help!


  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    It depends on exactly what you mean. Code to simply take teh number they clicked and add it to the display?

    txtDisplay.text = txtDisplay & Value from button.


    I did something like that years ago and I found it easiest to make the number buttons an array with the index being the number. Then on hte _Click event(index as integer) I would know what number was clicked and could simply use that:

    cmdNumbers(0) = 0
    cmdNumbers(1) = 1

    That made it easy to know what number to place in the display. Then just a matter of storing the display value into either a hidden field or private string when they click on an operator (add, subtract etc).

    Hope this helps. If you want more info email me and I'll send it to you.


    I like your reference to the Wolfman... unless I'm wrong in whcih case ignore this part of the message :-)

    [This message has been edited by netSurfer (edited 02-04-2000).]

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Greensboro,NC USA
    Posts
    9

    Post

    Thank you!

    That is very helpful. I plan to work with this program over the weekend and will e-mail you if I run into problems.

    And yes, Lon Chaney is a reference to the actor who played the wolfman. I am an N C State fan, thus the nickname.

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Greensboro,NC USA
    Posts
    9

    Post

    How do you go about making the buttons an array?

    Told you I was new....

  5. #5
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    OK name each command button the same thing and it will ask you if you want to create an array. Then if byaccident you do it out of order and the o has an array of 9 you have to fix that in the porperties called index but you must remeber nothing can have the same index so if you want the zero button to have an array of 0 you must first go to the one that actually does say 0 and change it to another number and then go to your zero button and make the array 0. I hope this helps

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    just have fun out there and live life to the fullest while it is still here
    Email [email protected]


  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Greensboro,NC USA
    Posts
    9

    Post

    Thanks PB.

    Now I have the 0-9 command keys in an array in which I named them all "integer". And I also set the index to match each number on the keyboard.

    What code do I use to display the numbers when they are clicked? txtDisplay=? for each number?



    [This message has been edited by Lon Chaney (edited 02-06-2000).]

  7. #7
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    Here is your code:

    Private Sub INTEGER_Click(Index As Integer)
    TextDISPLAY.Text = TextDISPLAY.Text & Index
    End Sub


    there that should do it

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    just have fun out there and live life to the fullest while it is still here
    Email [email protected]


  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Greensboro,NC USA
    Posts
    9

    Post

    I tried that code, but I'm getting an error message:

    Run-time error 424
    object required

    When I debug, I get this line highlighted:

    TextDisplay.Text=TextDisplay.Text & Index


    Any ideas?

    Thanks!

  9. #9
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    hmm it seemed to work fine when i tried it let me check again

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    just have fun out there and live life to the fullest while it is still here
    Email [email protected]


  10. #10
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    Hmm i tried the code i gave you again and it worked fine so here is a few ideas dim you make index as anything anywhere if so change the name to something else or did you put that code under
    Private Sub INTEGER_Click(Index As Integer)
    if you put it under
    Private Sub INTEGER_Click
    it won't work.
    hope this helps

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    just have fun out there and live life to the fullest while it is still here
    Email [email protected]


  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Greensboro,NC USA
    Posts
    9

    Post

    OK

    I now have a calculator that will display numbers and clear. Now I just need to discover how to set up the addition, subtraction, multiplication, and division functions.

    Again, thanks for all the help. What a challange!

    Lon

  12. #12
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    If you need anymore help just email me [email protected] . I would be glad to help. Well talk to you later have fun!!

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    just have fun out there and live life to the fullest while it is still here
    Email [email protected]



    [This message has been edited by PITBULLCJR (edited 02-07-2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width