Qbasicnews.com
April 09, 2020, 06:45:49 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: defAULT a-z  (Read 1761 times)
andy
Senior Member
**
Posts: 175



WWW
« on: October 07, 2003, 07:46:08 AM »

A lot of programs I have seen use the "default" A-Z command. What does this do.
Logged

eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #1 on: October 07, 2003, 07:56:00 AM »

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 %)
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #2 on: October 07, 2003, 07:59:39 AM »

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? Smiley
Logged
Phydaux
Senior Member
**
Posts: 200



« Reply #3 on: October 07, 2003, 08:05:20 AM »

It might be worth a look here if you are unsure on data types.
http://qbasicnews.com/qboho/qckadvr.dtp.shtml
Logged

url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79][/url]
END OF LINE.
Mango
Wandering Guru
***
Posts: 360



« Reply #4 on: October 07, 2003, 10:32:11 AM »

Quote from: "andy"
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
Logged
andy
Senior Member
**
Posts: 175



WWW
« Reply #5 on: October 07, 2003, 12:45:29 PM »

Thanks, I know what the different type of variables are, i just didn't know what the defint a-z statement did
Logged

eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
toonski84
__/--\__
*****
Posts: 2567



« Reply #6 on: October 07, 2003, 12:48:40 PM »

don't forget your helpful friends at microsoft wrote a nifty little manual for that sort of stuff.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!