[Help] Differences between Constants and Variables [Solved]

Posts 1–10 of 10 · Page 1 of 1
[Help] Differences between Constants and Variables [Solved]
so i have been taking a course of VB recently...and ive been doing fine but now its gotten a bit more difficult...heres a link to the project i have to make...
any help will be greatly appreciated

http://rion.ws/Mesa/Project2Assign.pdf

im a bit comfused about the dim and constant....i dont know which one im suppose to use
I dont understand your question...
Dim its to declare things like string, integer blabla...
what would i declare for this project???

Accessories (Stereo system = $425.76, Leather interior = $987.41, Computer navigation = $1,741.23), Detailing (Standard = 0, Pearlized = $345.72, Customized = $599.99), Tax rate = 8%

so out of all of this which would be my const and dim???
it's like a calculator dude.....
On the button Calculate you must do something like this:

Code:
TextboxTotal.Text = CInt(TextboxPrice.Text) + CInt(TextboxPrice2.Text) ' ETC...
And on the CheckBox Checked Change do this:

Code:
If YourCheckBox.Checked = True Then 

TextboxPrice.Text = "Your Price"

End if

if YourCheckbox2.Checked = True Then

TextboxPrice2.Text = "Your 2 Price"

End if
Its almost the same to the radio buttons...

Its something like that xD
Now just think about it!
Consts are "Constants" the value that they hold cannot be changed at runtime. Dim declares a variable which, like it sounds, holds a variable value. You can make it hold any value of the same type (String. Integer, Decimal). So if those prices are fixed within your program, declare them as constants.
In Visual Basic, Dim officially tells the compiler that we are going to declare a variable. A variable can change its value anywhere in the program.

Constants, on other hand are variable modifiers that represent a constant value, a value that can be computed at compile-time. Constants are fixed values and cannot change their value once initialized.

Having said that, use constants if you are not going to change the values. Else, simply use variables.
Quote Originally Posted by Hassan View Post
In Visual Basic, Dim officially tells the compiler that we are going to declare a variable. A variable can change its value anywhere in the program.

Constants, on other hand are variable modifiers that represent a constant value, a value that can be computed at compile-time. Constants are fixed values and cannot change their value once initialized.

Having said that, use constants if you are not going to change the values. Else, simply use variables.
For reference: Constants are pretty much semantics. In memory, they're all the same as normal integer values.
thank you everyone...i understand better...
Alrighty glad we could be of service. Thread marked solved, I doubt there is any need for anyone to post further.
Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?