How do I TYPE? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How do I TYPE?

Dr. COM WIZDr. COM WIZ Posts: 74Member
Hello, world!
This is Dr. COM WIZ. I've seen it everywhere--in tyle scrollers, in image loaders, even in my back pocket (just kidding)!
What am I referring to? The TYPE command. Sometimes knowing this is critical. When I want to accomplish certain challenging tasks, the tutorials and example codes usually assume I know how to TYPE! (I mean, I know how to type. I was just using the TYPE command as a verb.) The TYPE blocks are usually in a large list, like an Assembler, and contain lots of variables which can sometimes end in "AS INTEGER" or "AS STRING * 5."

So, to be able to reach my advanced level in programming, I would, ofcourse, have to know what TYPE really does. May someone please teach me how to use the TYPE commad or point me to an online tutorial who will teach me?

This has been,
Dr. COM WIZ
PS Thank you and goodnight!

Comments

  • Cpp_JunkyCpp_Junky Posts: 5Member
    I guess (do not really know) it declares the type of data that will be used with this variable.

    For example:

    INTEGER: numbers between -32768 and 32767
    STRING: Characters
    DOUBLE: numbers between 2.2e-308 and 1.8e308
    FLOAT: floating numbers between 1.2e-38 and 3.4e38

    Hope this could help you

  • BASIC FriendBASIC Friend Posts: 354Member
    : I guess (do not really know) it declares the type of data that will be used with this variable.
    :
    : For example:
    :
    : INTEGER: numbers between -32768 and 32767
    : STRING: Characters
    : DOUBLE: numbers between 2.2e-308 and 1.8e308
    : FLOAT: floating numbers between 1.2e-38 and 3.4e38
    :
    : Hope this could help you
    :

    Hey Com Wiz and CPP Junky,

    I'm assumming by your handle (Cpp_junky) that your familiar with C++. A TYPE is almost the same thing as a struct in C.

    With a TYPE you can bundle several variables into a single variable.

    I'm going to look through some of my code so that I can give you guys a useful example. I like to use TYPEs to read from or write to binary files.


  • retrogeekretrogeek Posts: 93Member
    : Hello, world!
    : This is Dr. COM WIZ. I've seen it everywhere--in tyle scrollers, in image loaders, even in my back pocket (just kidding)!
    : What am I referring to? The TYPE command. Sometimes knowing this is critical. When I want to accomplish certain challenging tasks, the tutorials and example codes usually assume I know how to TYPE! (I mean, I know how to type. I was just using the TYPE command as a verb.) The TYPE blocks are usually in a large list, like an Assembler, and contain lots of variables which can sometimes end in "AS INTEGER" or "AS STRING * 5."
    :
    : So, to be able to reach my advanced level in programming, I would, ofcourse, have to know what TYPE really does. May someone please teach me how to use the TYPE commad or point me to an online tutorial who will teach me?
    : This has been,
    : Dr. COM WIZ
    : PS Thank you and goodnight!
    :

    I'll take a stab at this one from another viewpoint.....

    When a programmer/annalyst must design a program, she must decide how to represent real-world information in the computer as data that is stored and manipulated in memory. For just one example, a bookkeeping program will have to store running money totals. Should they be stored as a floating-point number? Should they be stored as two integers, one for the dollar amount and a second for the cents amount? This concept of creating a "type" of machine data storage that corresponds to its real-world counterpart is called "Abstract Data Typing".

    Qbasic supplies the programmer with several simple built-in types such as integer, long integer, floating point, etc. But in many applications, real-world data consists of a group of different kinds of data. Qbasic's TYPE statement allows the programmer/annalyst to easily implement these more complicated abstact data types.

    For example, a real-world bookeeping transaction might consist of a date, a referance or check number, a payee or payor referance, a transaction amount, and a running total. The TYPE statement can be used:

    [code]
    TYPE datetype
    month AS INTEGER
    day AS INTEGER
    year AS INTEGER
    ENDTYPE

    TYPE transtype
    tdate AS datetype
    refnum AS INTEGER
    pay AS STRING * 32
    tamount AS SINGLE
    total AS DOUBLE
    ENDTYPE
    [/code]
    A variable is created like this:
    [code]
    DIM transaction AS transtype
    [/code]

    Each part of the type can be accessed with a dot:
    [code]
    PRINT "The amout is";transaction.tamount
    PRINT "The month is";transaction.tdate.month
    [/code]
    Each entry can easily be stored in an array, on in a disk file.

    It would be possible to implement this abstract data type without using the TYPE statement but the progam would be much more difficult to understand or write. Each of the different parts of the ADT would have to be stored in its own array, or they could all be stored in the same array as the same basic type (string?) and then converted to there native type when manipulated -- much more difficult.

    Hope this helps --

    rg


  • BASIC FriendBASIC Friend Posts: 354Member
    Ok! Here's a simple program that uses a type. It reads pif files. The reason I use STRING * 1 is because QB does not have a BYTE variable.

    Compile it and run it like this: [b]PIFREAD filename.PIF[/b]
    [code]
    'PIFREAD.BAS
    TYPE PIFHEADER
    reserved AS STRING * 1
    checksum AS STRING * 1
    title AS STRING * 30
    maxmem AS INTEGER
    minmem AS INTEGER
    path AS STRING * 63
    clexit AS STRING * 1
    drive AS STRING * 1
    directory AS STRING * 64
    parameters AS STRING * 64
    screenmode AS STRING * 1
    pages AS STRING * 1
    firstint AS STRING * 1
    lastint AS STRING * 1
    rows AS STRING * 1
    columns AS STRING * 1
    xpos AS STRING * 1
    ypos AS STRING * 1
    sysmem AS INTEGER
    sharedpath AS STRING * 64
    shareddata AS STRING * 64
    progflags AS INTEGER
    END TYPE

    START:
    DIM pif AS PIFHEADER
    OPEN COMMAND$ FOR BINARY AS #1
    GET #1, , pif
    CLOSE #1
    PRINT "Reserved:"; ASC(pif.reserved)
    PRINT "Checksum:"; ASC(pif.checksum)
    PRINT "Title: "; (pif.title)
    PRINT "Maximum memory:"; pif.maxmem
    PRINT "Minimum memory:"; pif.minmem
    PRINT "Path and Filename: "; (pif.path)
    PRINT "Close on exit?: "; ASC(pif.clexit)
    PRINT "Default Drive: "; ASC(pif.drive)
    PRINT "Startup directory: "; (pif.directory)
    PRINT "Parameters: "; (pif.parameters)
    PRINT "Screenmode:"; ASC(pif.screenmode)
    PRINT "Number of text pages:"; ASC(pif.pages)
    PRINT "First interupt:"; ASC(pif.firstint)
    PRINT "Last interupt:"; ASC(pif.lastint)
    PRINT "Number of rows:"; ASC(pif.rows)
    PRINT "Number of columns:"; ASC(pif.columns)
    PRINT "X Position:"; ASC(pif.xpos)
    PRINT "Y position:"; ASC(pif.ypos)
    PRINT "System memory:"; pif.sysmem
    PRINT "Shared path: "; (pif.sharedpath)
    PRINT "Shared data: "; (pif.shareddata)
    PRINT "Program flags:"; pif.progflags
    END




Sign In or Register to comment.