Quote:It's a dumb question but how can I assign a variable that isnt a integer, besides using INPUT.
I'm not sure what you mean by "assign a varable that isn't an integer".
Variables can be
declared as having on of the following data types:
integer --- 2 bytes from -32,7688 to +32,767
long ------- 4 bytes from -2,147,483,648 to +2,147,483,647
single ----- 4 bytes, single precision floating point
double ---- 8 bytes, double precision floaing point
Variables are
assigned by storing or setting a value into them. You can "assign" variables as follows:
1) If you just say f1=1
f1 will be set to 1, and declared as a single precision floating point variable which is the QB default.
2) However, if before the above statement you wrote DEFINT A-Z
then all subsecuent variables will be declared as integers, unless you explicitly said fx# = 1 in which case fx# is explicitly declared as a double precision floating point variable.
It's a good idea to do DEFINT A-Z at the beginning of your program because most of the time you want to declare variables as intergers, except for those declared explicitly. DEFINT A-Z says declare all variables with letters beginning with A to Z as integers, unless declared explicitly. There's also DEFLNG, DEFSNG, and DEFDBL but these are rarely used.
3) You can use any of the following suffixes after the name of a variable to explicitely declare the data type of the variables:
% for integer
& for long integer
! for single precision floating point
# for double precision floating point
4) I personally don't like using the above suffixes on the varaible names because they make the code more difficult to read. I prefer to declare them explicitly at the top of the program or function as follows:
dim a as integer
dim b as long
dim c as single
dim d as double
5) QB has the peculiarity of allowing you to use (reference) a variable that was never assigned. In you example f1 = f1 +1
you never previously assigned a value to f. QB knows this and gives you a default assigned value of zero. So, the first time you execute this instruction f1 will be 0 + 1 = 1. Don't rely on this QB "feature", if you want a variable to contain zero at the beginning, then initialize it to zero at the top of your program.
6) So, if you want to assign a starting value to a variable, you don't need to input the starting value, you can assign it as follows:
b = 5
7) Sometimes you want to assign a permanent value to a variable, that is, make it a constant that can't be changed. For this, use the CONST statement. For example, set a constant for the maximum number of characters allowed for a name field:
const maxname = 40
If by mistake some instruction in your program attempts to store something on top of maxname, the compiler will signal an error.
Hope this info helps.
*****