[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
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.
Originally Posted by Hassan
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.