Getting Started
Introduction
Sample Programs
QBasic IDEs
History
Advice
Tools
Mini-Tutorial
Tutorial
Code Snippets

Resources
Web Sites
More Tutorials
Vendors
Books
Magazines
NewsLetters
NewsGroups
Forums
User Groups
Talk Shows
Blogs

GBIC >> QBasic >> Tutorial >> Data Types

QBasic Information Center Tutorials - Data Types
These tutorials were written to help you get a quick, but thorough, understanding of QBasic - the scope of the language as well as it's specific capabilities.

Data Types
There are several types of data in QBasic

     strings          "dog"   "cat"  "the_boy"
     integers         1   7  -39   37   43   0
     long integer     
     single           1.2  -17.4  83.2  171.006
     double           1.109435089627097612
     user-defined     (combination of above types, see explanation below)

All QBasic variables are one of these basic data types. In performing functions which expect a particular type of data, QBasic will try, but may not succeed, to adjust the type of data found in a variable to the type needed by the function.

Data Type Value Ranges
The minimum/maximum values of each data type is given in the next table.

    Date TypeMinimumMaximum
    String032,767 characters
    Integer-32,76832,767
    Long-2,147,483,6482,147,483,647
    Single-2.8E-453.4E+38
    Double-4.9D-3241.8DE+308

Conversion
In many programs a value of a specific data type is required. QBasic provides several ways to convert variables to specific data types.

To convert any number to a specific data type, use one of the following functions.

  • cint
  • clng
  • csng
  • cdbl

To convert a string to a specific data type, use one of the following functions.

  • cvi
  • cvl
  • cvs
  • cvd
  • cvsmbf
  • cvdmbf

User-Defined Data Type (UDT)
QBasic also supports a very useful data type which consists of more than one of the standard data types. In this example, a "Custom" data type is defined and the variable X is defined as that data type. The example shows how to assign and access the elements which make up a user-defined data type.

     Type Custom 
         a as string
         b as number
         c as double
     End Type

     Dim X as Custom

     X.a = "hello"
     X.b = 5
     X.c = 53.2429965

This technique allows you to carry multiple values around in a single variable. You can write X to a file and save all three values in a single statement.

If you have any suggestions for additions to these tutorials, please let me know.