Qbasicnews.com

Full Version: defAULT a-z
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A lot of programs I have seen use the "default" A-Z command. What does this do.
You know all the variable types qb supports? Integer, single, etc

Well, DEFINT A-Z sets the default type to integer for all variables that start with any letter from A to Z (in other words, all variables will be integers)

Example:
Code:
DEFINT B
DEFSNG S

blah = 0  ' this is an integer (because it starts with b)
bbb! = 0   ' this is a single (because of the !)

s = 1234  ' this is a single (because it starts with s)
s% = 5  ' this is an integer (because of the %)
You probably mean the DEFTYPE A-Z statement.

Well, this statement instructs qb to dim all undimmed variables as TYPE.

E.g. take a look at this:
Code:
DEFINT A-Z
a = 0 'now a is an integer
DEFSNG A-Z
b = 0 'b is now a single
DEFDBL A-Z
DIM c AS INTEGER
c = 0 'c is integer, as you dimmed it integer specifically
d% = 0 'd is integer, as you told d to be integer by the %-sign
e = 0 'e is a double, as it is undimmed, so the last deftype is applied

http://qbasicnews.com/qboho/qckdefint.shtml is the online help about DEFTYPE.

EDIT: It was kinda race eh Sterling? Who clicked submit first? Smile
It might be worth a look here if you are unsure on data types.
http://qbasicnews.com/qboho/qckadvr.dtp.shtml
Quote:A lot of programs I have seen use the "default" A-Z command. What does this do.

I know the previous 3 responses answered the question. Let me try to be more clear.

When a computer uses a variable, that variable must have a type. Data needs type information because it is really just some binary data that we want to assign human-type meaning to. Therefore the binary data is treated differently depending on if it represents a string, an integer, or and floating point numbers.

In QB, All variables have one of the 3 basic data types. For very simple programs, sometimes the programmer doesn't know, or care what the type is. For example if you said:

a = 11
b = a + 2

and I ask you, "what is the type of a and b?", you might very well answer, "Duh...they're numbers, stupid". However, what I'm really asking is "are they integers, or floating point numbers?", which is a valid question.

suppose instead of the preceeding, I had written, instead

a = 11
b = a / 2

now, the type is very important. If b is an floating point number, it will hold the value of 5.5 if b is an integer, it will hold = 5.5, but if it is an integer, then b = 5.

so...in QB there are two basic ways to control the type of a variable. Read this carefully.

1) You can give all instances of the variable a suffex that indicates it's type.

2) You can use a DEFtype statement to set the default type to the type of your choosing.

The suffex rout works well, and it makes the type clear when reading code...howver, it is tedious to always type the suffexes.

the DEFtype rout is more convenient when coding, but it's harder to debug, because it means a variable's type is not obvious.

The suffex list is as follows:
a! floating point (single presision)
a# floating point (double precision)
a% integer(16-bit)
a& integer(32-bit)
a$ text character string

if you want to use DEFtype you do it like so:

DEFINT a-z 'makes all variables 16-bit integers unless a suffex is given

DEFINT a-m 'makes all variable beginning with the letters "a"-"m" integers unless a suffex is given
DEFSNG n-z 'makes all variables starting with "n"-"z" floating point unless a suffex is given.

I hope this helps
Thanks, I know what the different type of variables are, i just didn't know what the defint a-z statement did
don't forget your helpful friends at microsoft wrote a nifty little manual for that sort of stuff.