Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays and functions of long integers?

Status
Not open for further replies.

Grozny

Programmer
Jan 27, 2010
5
US
Two questions:

1) How do I create arrays of long integers?

Code:
DIM A(100) AS INTEGER

This statement creates an array of short (two byte) integers. But what is the comparable statement for an array of long (four byte) integers?

2) How do I create a function that returns a long integer?

Code:
DECLARE FUNCTION name% ()

PRINT name%

FUNCTION name%
     result% = 10               ' an integer under 32767
     name% = result%
END FUNCTION

This code returns a short integer. But what is the comparable code for a function that returns a long integer?
 
My qbasic is way rusty. Once Caelius had a "working" demo, I moved on. But...

1.
DIM myArray() AS LONG

2.
FUNCTION func
myLong& = 2147483647
func& = myLong&
END FUNCTION

-Geates
 
Thanks!

BTW I'm using the Microsoft user's manual which is, frankly, crap. It's not answering any of my questions. In this case there was nothing about LONG or using the & suffix. They just gave us DEFLNG and some sales-type talk about how wonderful and convenient long integers are.

Can you recommend a manual that has a comprehensive alphabetical list of all the commands and statements?

Note that I am not a total beginner. I don't need a Dummies-type book that spends 50 pages describing FOR/NEXT loops. I just need something more comprehensive than that half-baked manual that Microsoft published 20 years ago.
 
I've used Qbasic Command List in Google:


It was the first one listed for me. I don't know if it has everything you're looking for but you can compare their list to the F1 in QB.

HTH.
--MiggyD

My mind not only wanders, it sometimes leaves completely.
 
Sorry I was not watching sooner. this is part of a handout on QBASIC variables. cut & paste into notepad.

Example:

DIM MYVALUE&(100)

CREATES A TABLE OF LONG INTEGERS OF +- 2 BILLION

DIM A#(100)

CREATES A TABLE OF LONG FLOATING POINT OF 8 BYTES WITH 15 DIGITS WHICH IS AS BIG AS IT GETS
-----------------------------------------------------------
THE FOLLOWING ARE DATA DEFINITION AND TRANSFORMATION STATEMENT EXAMPLES:

A$ = “STRING” :’ CREATES A STRING OF CHARACTERS UP TO 32,767 BYTES LONG
A% = 6 :’ CREATES A SHORT INTEGER UP TO +32K = 2 BYTES BINARY + SIGN
A& = 1456789 :’ CREATES A LONG INTEGER UP TO +2 BILLION = 4 BYTES BINARY + SIGN
A! = 123.456 :’ CREATES A SHORT +FLOATING POINT NUMBER = 4 BYTES WITH 7 DIGITS x1038
A# = 1234567.123 :’ CREATES A LONG +FLOATING POINT NUMBER = 8 BYTES WITH 15 DIGITS x10308
A% = X\Y :’ RETURNS THE INTEGER VALUE OF THE DIVIDE
A% = X MOD Y :’ RETURNS THE REMAINDER AFTER DIVIDING X BY Y
A% = INT(3.685) :’ RETURNS “3" THE ROUNDED DOWN VALUE OF “3.685)
A% = FIX(3.685) :’ RETURNS “3" THE TRUNCATED VALUE OF “3.685)
A% = CINT(3.685) :’ RETURNS “4" THE ROUNDED UP VALUE OF “3.685"
A& = CLNG(3.685) :’ RETURNS A LONG INTEGER VALUE “4" THE ROUNDED UP VALUE OF “3.685"
A@ = 23.67 :’ CREATES A CURRENCY VALUE

DIM MYVALUES(50) :’ A REAL NUMERIC TABLE WITH 50 ENTRIES
DIM NAMELIST$(200) :’ A CHARACTER TYPE TABLE WITH 200 ENTRIES
DIM BOWLINGSCORES(60,100) :’ A TWO DIMENSIONED TABLE WITH 60 ENTRIES OF A 100 ENTRIES EACH


Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top