Cycling and bicycle discussion forums. 
   Click here to join our community Log in to access your Control Panel  


Go Back   > >

Foo Off-Topic chit chat with no general subject.

User Tag List

Reply
 
Thread Tools Search this Thread
Old 02-11-08, 09:15 PM   #1
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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")?
EJ123 is offline   Reply With Quote
Old 02-11-08, 09:59 PM   #2
jaxgtr
Senior Member
 
jaxgtr's Avatar
 
Join Date: Jul 2006
Location: Jacksonville, FL
Bikes: Trek ALR 6, Trek CrossRip, Trek X-Caliber 8
Posts: 4,356
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 1 Post(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 Trek Emonda ALR 6 | 2015 Trek X-Caliber 8 | 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.
jaxgtr is offline   Reply With Quote
Old 02-12-08, 06:48 AM   #3
Malistryx
Senior Member
 
Malistryx's Avatar
 
Join Date: May 2007
Location: Aussieland
Bikes: Specialized Allez Sport, Jamis Dakota Comp
Posts: 73
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
Malistryx is offline   Reply With Quote
Old 02-12-08, 10:05 AM   #4
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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 *******.
KingTermite is offline   Reply With Quote
Old 02-12-08, 11:53 AM   #5
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
EJ123 is offline   Reply With Quote
Old 02-12-08, 12:10 PM   #6
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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 *******.
KingTermite is offline   Reply With Quote
Old 02-12-08, 05:44 PM   #7
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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?
EJ123 is offline   Reply With Quote
Old 02-12-08, 05:56 PM   #8
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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 *******.
KingTermite is offline   Reply With Quote
Old 02-12-08, 06:06 PM   #9
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
EJ123 is offline   Reply With Quote
Old 02-12-08, 06:16 PM   #10
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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 *******.
KingTermite is offline   Reply With Quote
Old 02-12-08, 06:27 PM   #11
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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?
EJ123 is offline   Reply With Quote
Old 02-12-08, 08:12 PM   #12
jaxgtr
Senior Member
 
jaxgtr's Avatar
 
Join Date: Jul 2006
Location: Jacksonville, FL
Bikes: Trek ALR 6, Trek CrossRip, Trek X-Caliber 8
Posts: 4,356
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 1 Post(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 Trek Emonda ALR 6 | 2015 Trek X-Caliber 8 | 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.
jaxgtr is offline   Reply With Quote
Old 02-12-08, 09:12 PM   #13
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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 *******.
KingTermite is offline   Reply With Quote
Old 02-12-08, 11:00 PM   #14
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
EJ123 is offline   Reply With Quote
Old 02-12-08, 11:13 PM   #15
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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 *******.
KingTermite is offline   Reply With Quote
Old 02-12-08, 11:27 PM   #16
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
I still don't get when to use variables. I can't imagine how I even need them in a simple calculator.
EJ123 is offline   Reply With Quote
Old 02-12-08, 11:29 PM   #17
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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. =/
EJ123 is offline   Reply With Quote
Old 02-12-08, 11:41 PM   #18
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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 *******.
KingTermite is offline   Reply With Quote
Old 02-13-08, 07:32 PM   #19
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
EJ123 is offline   Reply With Quote
Old 02-13-08, 08:29 PM   #20
chipcom 
Infamous Member
 
chipcom's Avatar
 
Join Date: Sep 2005
Location: Ohio
Bikes: Surly Big Dummy, Fuji World, 80ish Bianchi
Posts: 24,366
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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
chipcom is offline   Reply With Quote
Old 02-13-08, 08:47 PM   #21
jaxgtr
Senior Member
 
jaxgtr's Avatar
 
Join Date: Jul 2006
Location: Jacksonville, FL
Bikes: Trek ALR 6, Trek CrossRip, Trek X-Caliber 8
Posts: 4,356
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 1 Post(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 Trek Emonda ALR 6 | 2015 Trek X-Caliber 8 | 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.
jaxgtr is offline   Reply With Quote
Old 02-13-08, 08:52 PM   #22
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
EJ123 is offline   Reply With Quote
Old 02-13-08, 08:53 PM   #23
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
And now this code won't show up in the exe: http://i7.photobucket.com/albums/y251/viperfx10/Huh.jpg
EJ123 is offline   Reply With Quote
Old 02-13-08, 09:05 PM   #24
EJ123
'05 NUEser
Thread Starter
 
EJ123's Avatar
 
Join Date: Aug 2005
Bikes:
Posts: 3,370
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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?
EJ123 is offline   Reply With Quote
Old 02-13-08, 09:34 PM   #25
jaxgtr
Senior Member
 
jaxgtr's Avatar
 
Join Date: Jul 2006
Location: Jacksonville, FL
Bikes: Trek ALR 6, Trek CrossRip, Trek X-Caliber 8
Posts: 4,356
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 1 Post(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 Trek Emonda ALR 6 | 2015 Trek X-Caliber 8 | 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.
jaxgtr is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -6. The time now is 11:56 AM.