Advertise on Bikeforums.net



User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 47
  1. #1
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need VB.net help #2

    For VB 05 Express.

    I need to make a calcuator .exe that will figure out addition, subtraction, multiplication, and division. It will have two text boxes a few labels and 4 buttons for the math functions.

    I have notes, don't really help much, and I need to use the "If..Else" statements or the Case Select stuff. Yikes! I can't even figure out how to set my variables.

    DO I start out with "Dim txtBox1 as Integer"? Took a guess, heh. Ug.

    Also how do I hide labels? Or make them appear? lblmessage.show("blah")?

  2. #2
    Senior Member jaxgtr's Avatar
    Join Date
    Jul 2006
    Location
    Jacksonville, FL
    My Bikes
    Cannondale Synapse , Trek CrossRip
    Posts
    4,023
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you might need to get another book to help you out. I don't mess with the vb.net stuff much, last time was around the 2003 version, but the if..Else and Case Select are pretty simple stuff in the big scheme of programming.

    http://www.dreamincode.net/forums/showtopic13645.htm

    http://www.dreamincode.net/forums/showforum67.htm
    Brian | 2015 Cannondale Synapse Carbon 3 | 2014 Trek CrossRip Comp
    Quote Originally Posted by AEO View Post
    you should learn to embrace change, and mock it's failings every step of the way.

  3. #3
    Senior Member Malistryx's Avatar
    Join Date
    May 2007
    Location
    Aussieland
    My Bikes
    Specialized Allez Sport, Jamis Dakota Comp
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's actually a few tutorials online that show you how to make a calculator in VB.Net.

    Try doing a google search for pretty much any VB.Net question and you'll get tons of results since it's used fairly often as a beginners programming language.

  4. #4
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EJ123 View Post
    For VB 05 Express.

    I need to make a calcuator .exe that will figure out addition, subtraction, multiplication, and division. It will have two text boxes a few labels and 4 buttons for the math functions.

    I have notes, don't really help much, and I need to use the "If..Else" statements or the Case Select stuff. Yikes! I can't even figure out how to set my variables.

    DO I start out with "Dim txtBox1 as Integer"? Took a guess, heh. Ug.

    Also how do I hide labels? Or make them appear? lblmessage.show("blah")?
    1) NO. Never make a variable with a name that looks like one data type and is actually another one. "Dim txtBox1 as Integer" is nothing but a confusing mess that will get you in to trouble.

    2) Didn't you hide labels in the last assignment? Hide them until the user clicked a button?

    3) It sounds like you are not doing a standard calculator, but a very simple one to force some concepts. Two text boxes (one for each number) and buttons for +,-,/,* correct?

    My suggestion would be to have two texboxes. txtNum1 and txtNum2 or something like that. An integer variable that gets set when you click any of the math buttons. If you have a variable that sets something based on which operation was hit, then your set. (E.g. +=1, -=2, *=3, /=4).

    Then when you hit the calculate button:
    Get txtNum1 and convert to an actual number (remember its a string right now)
    Get txtNum2 and convert to an actual number
    Check the operation variable (If..Else or Case to select and perform actual calculation)
    Display results
    Quote Originally Posted by coffeecake View Post
    - it's pretty well established that Hitler was an *******.

  5. #5
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KingTermite View Post
    1) NO. Never make a variable with a name that looks like one data type and is actually another one. "Dim txtBox1 as Integer" is nothing but a confusing mess that will get you in to trouble.

    2) Didn't you hide labels in the last assignment? Hide them until the user clicked a button?

    3) It sounds like you are not doing a standard calculator, but a very simple one to force some concepts. Two text boxes (one for each number) and buttons for +,-,/,* correct?

    My suggestion would be to have two texboxes. txtNum1 and txtNum2 or something like that. An integer variable that gets set when you click any of the math buttons. If you have a variable that sets something based on which operation was hit, then your set. (E.g. +=1, -=2, *=3, /=4).

    Then when you hit the calculate button:
    Get txtNum1 and convert to an actual number (remember its a string right now)
    Get txtNum2 and convert to an actual number
    Check the operation variable (If..Else or Case to select and perform actual calculation)
    Display results
    Oh ok. I figured out how to do the hide labels. I just don't understand which variables to set, and to set them as what, and how to execute the math functions. Why can't it be something as easy as "me.lblAnswer.show(txtBox1 + txtBox2) when the user clicks the addition button? Arg. Will my variables strictly be string or will they be integer? I thought I needed to label the txtBox as a variable.

  6. #6
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EJ123 View Post
    Oh ok. I figured out how to do the hide labels. I just don't understand which variables to set, and to set them as what, and how to execute the math functions. Why can't it be something as easy as "me.lblAnswer.show(txtBox1 + txtBox2) when the user clicks the addition button? Arg. Will my variables strictly be string or will they be integer? I thought I needed to label the txtBox as a variable.
    The text boxes are variables, but they are TEXT boxes, not numbers. So you need to figure out out to convert the text to a number. Once you do that, its almost as easy as you said with the show. You need to figure out which operation it is, but then its pretty much what you have.
    Quote Originally Posted by coffeecake View Post
    - it's pretty well established that Hitler was an *******.

  7. #7
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KingTermite View Post
    The text boxes are variables, but they are TEXT boxes, not numbers. So you need to figure out out to convert the text to a number. Once you do that, its almost as easy as you said with the show. You need to figure out which operation it is, but then its pretty much what you have.
    Oh. Do I need to input the convert to integer ( cInt?) somewhere within the code?

  8. #8
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They will be separate.

    Psuedocode:

    dim TxtboxNum1 as textbox
    dim TxtboxNum2 as textbox
    dim Num1 as int
    dim Num2 as int
    dim ComputationType as int
    dim Answer as float

    when COMPUTE button pressed
    Num1 = TxtboxNum1.ConvertToNumber()
    Num2 = TxtboxNum2.ConvertToNumber()

    case (ComputationType)
    case [+]: Answer = Num1 + Num2
    case [-]: Answer = Num1 - Num2
    case [*]: Answer = Num1 * Num2
    case [/]: Answer = Num1 / Num2

    Display(answer)
    Quote Originally Posted by coffeecake View Post
    - it's pretty well established that Hitler was an *******.

  9. #9
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! That looks fantastic. I see you entered the cases near the end. Hm.
    The name I gave my text boxes were txtBox1 and txtBox2. When I changed what you said into mine, I get the green squigly lines undernearth

    Why is that happening? I correctly spelled everything, yet it won't recognice it.

    Edit: oh, I moved it to the public class form 1 above the first space for code and it worked except for the txtBox1-it's now a blue squigly.

  10. #10
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    VB.Net does a lot of the work for you. There are bonuses and drawbacks to that. A language like C may be a bit harder, but full control means YOU control everything.

    You change the name in once place, but the compiler probably still has references to it as another name elsewhere (properties of the control perhaps??) or in auto generated code near top.

    BTW...nothing says your names are wrong. A variable name is just a name, it could be "CharlieEatsLimaBeans" and still be correct. I tend to prefer using variable names that imply what it is....the more you code the more you realize how much that helps. Names like 'A' and 'variable1' don't tell me anything about what it is and it makes you much more likely to confuse your variables.
    Quote Originally Posted by coffeecake View Post
    - it's pretty well established that Hitler was an *******.

  11. #11
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I have the Dim variable variable a different name then what I listed within the properties of that control, how would it work?

  12. #12
    Senior Member jaxgtr's Avatar
    Join Date
    Jul 2006
    Location
    Jacksonville, FL
    My Bikes
    Cannondale Synapse , Trek CrossRip
    Posts
    4,023
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KingTermite View Post
    I tend to prefer using variable names that imply what it is....the more you code the more you realize how much that helps. Names like 'A' and 'variable1' don't tell me anything about what it is and it makes you much more likely to confuse your variables.
    + 1 billion. Nothing is worse that trying to work on someones code that is not commented or us vague variable names. I hate that.
    Brian | 2015 Cannondale Synapse Carbon 3 | 2014 Trek CrossRip Comp
    Quote Originally Posted by AEO View Post
    you should learn to embrace change, and mock it's failings every step of the way.

  13. #13
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EJ123 View Post
    If I have the Dim variable variable a different name then what I listed within the properties of that control, how would it work?
    Controls and basic data types are a little bit different.

    If you dim a normal variable, it won't have a "properties" window. Only your controls will. I think if you want to change a control you should do it through the properties window.
    Quote Originally Posted by coffeecake View Post
    - it's pretty well established that Hitler was an *******.

  14. #14
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SO variables should never use the names of the controls with the same name displayed in the properties window?

    I need at least 3 class-level variables (what is that?) in this .exe, and I have no idea how I could use even 1.

  15. #15
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EJ123 View Post
    SO variables should never use the names of the controls with the same name displayed in the properties window?

    I need at least 3 class-level variables (what is that?) in this .exe, and I have no idea how I could use even 1.
    I'm not sure I even understand what you are asking.

    If you put a control on the form, it automatically gives it a name. Let's say "TextBox1". Right then and there (as soon as you add it), change the name in the properties window to "TextBoxNumber1" or something like that. If you change it in the properties window, it changes it in the code.

    However, once you begin using that variable (even though its still a control, it's still a variable) though, changing the name means it needs to be changed in EVERY place its referenced. Usually its easiest to go back and change it in the properties window, then find the places the code chokes when you try to compile to fix the other places you've modified it.


    As far as using 3 class level variables.....seems like you will already have at least that many anyway: "Num1", "Num2", "ComputationType", "Result".....
    Quote Originally Posted by coffeecake View Post
    - it's pretty well established that Hitler was an *******.

  16. #16
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still don't get when to use variables. I can't imagine how I even need them in a simple calculator.

  17. #17
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KingTermite View Post
    Controls and basic data types are a little bit different.

    If you dim a normal variable, it won't have a "properties" window. Only your controls will. I think if you want to change a control you should do it through the properties window.
    I just did something like this:
    Me.lblAnswer.Text = CInt(txtBox1.Text) + CInt(txtBox2.Text)

    and replaced the math sign for each control section. It works heh, but still no need to dim a variable. =/

  18. #18
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EJ123 View Post
    I just did something like this:
    Me.lblAnswer.Text = CInt(txtBox1.Text) + CInt(txtBox2.Text)

    and replaced the math sign for each control section. It works heh, but still no need to dim a variable. =/
    The problem is you are sharp enough to "see" that you don't need the variables. I would do it exactly as you are doing it, but the teacher doesn't probably realize you are able to take that leap yet.

    What you can do, and what he probably expects is something like:
    Class Level:
    Dim Num1 as Integer
    Dim Num2 as Integer
    Dim Answer as Float


    Calculation Section:
    Num1 = CInt(txtBox1.Text)
    Num2 = CInt(txtBox2.Text)
    Answer = Num1 + Num2

    Me.lblAnswer.Text = (Convert to string)Answer
    Quote Originally Posted by coffeecake View Post
    - it's pretty well established that Hitler was an *******.

  19. #19
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi KT. Just one problem. I don't know what a Float it (never talked about it before). Have any idea on what a substitute would be?

    Edit: I used the code, and used string in place of the Float and it all works!!!!!! You make it so easy to understand that you should be the teacher Thank you!!
    Last edited by EJ123; 02-13-08 at 07:41 PM.

  20. #20
    Infamous Member chipcom's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    My Bikes
    Surly Big Dummy, Fuji World, 80ish Bianchi
    Posts
    24,373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EJ123 View Post
    Hi KT. Just one problem. I don't know what a Float it (never talked about it before). Have any idea on what a substitute would be?

    Edit: I used the code, and used string in place of the Float and it all works!!!!!! You make it so easy to understand that you should be the teacher Thank you!!
    A float is a floating decimal number. You need to use this type for doing mathematical operations rather than a string, then convert to a string to display your result in the interface, if needed.

    If you use strings for mathematical operations, you're gonna get all kinds of weird results.
    "Let us hope our weapons are never needed --but do not forget what the common people knew when they demanded the Bill of Rights: An armed citizenry is the first defense, the best defense, and the final defense against tyranny. If guns are outlawed, only the government will have guns. Only the police, the secret police, the military, the hired servants of our rulers. Only the government -- and a few outlaws. I intend to be among the outlaws" - Edward Abbey

  21. #21
    Senior Member jaxgtr's Avatar
    Join Date
    Jul 2006
    Location
    Jacksonville, FL
    My Bikes
    Cannondale Synapse , Trek CrossRip
    Posts
    4,023
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EJ123 View Post
    Hi KT. Just one problem. I don't know what a Float it (never talked about it before). Have any idea on what a substitute would be?

    Edit: I used the code, and used string in place of the Float and it all works!!!!!! You make it so easy to understand that you should be the teacher Thank you!!
    Dude, I have to ask, are you using a book, in a class or using the fly by night learning on my own training program? These are all basic items that you should have learn in the Introduction to Programming and Algorithm Design COP 1000 or what ever it called where you are. Is this the class you are taking and just using VB.Net or did you already have that class?

    Not trying to hack on you, but you might want do some addition research or pick up a language reference at a book store. Good luck.
    Brian | 2015 Cannondale Synapse Carbon 3 | 2014 Trek CrossRip Comp
    Quote Originally Posted by AEO View Post
    you should learn to embrace change, and mock it's failings every step of the way.

  22. #22
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaxgtr View Post
    Dude, I have to ask, are you using a book, in a class or using the fly by night learning on my own training program? These are all basic items that you should have learn in the Introduction to Programming and Algorithm Design COP 1000 or what ever it called where you are. Is this the class you are taking and just using VB.Net or did you already have that class?

    Not trying to hack on you, but you might want do some addition research or pick up a language reference at a book store. Good luck.
    We do silly notes in class which do not apply to the assignments, watch free VB tutorials online by some guy who made them (about 23min. videos each), and have weekly quizzes. That's it.

  23. #23
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And now this code won't show up in the exe: http://i7.photobucket.com/albums/y251/viperfx10/Huh.jpg

  24. #24
    '05 NUEser EJ123's Avatar
    Join Date
    Aug 2005
    Posts
    3,374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, does

    Dim Num1 as Integer
    Dim Num2 as Integer
    Dim Answer as Float

    constitute as holding the values of the input and the output solution?

  25. #25
    Senior Member jaxgtr's Avatar
    Join Date
    Jul 2006
    Location
    Jacksonville, FL
    My Bikes
    Cannondale Synapse , Trek CrossRip
    Posts
    4,023
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, those are just declaring the variable type. Num1 is being declared as an Integer, etc. The variables are assigned values with the vb assignment statement

    variable = value ex: num1 = txtWhatever.text
    Brian | 2015 Cannondale Synapse Carbon 3 | 2014 Trek CrossRip Comp
    Quote Originally Posted by AEO View Post
    you should learn to embrace change, and mock it's failings every step of the way.

Page 1 of 2 12 LastLast

Posting Permissions

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