Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AS INTEGER/AS STRING
#1
I noticed on my friend's program he used things like DIM SHARED again AS STRING. He tried to explain it to me, but he kind of wandered off.

Can somebody here explain to me what AS STRING/AS INTEGER mean?
Reply
#2
It is the type of the variable, it tells the computer and compiler which values your variable can hold.

For example:
DIM a AS INTEGER

Would make it possible to put any whole value (not decimals) between and including -32768 to 32767 in the variable a

DIM a AS STRING
Simply means that a is a string variable, and can hold strings only, as opposed to numerical values.
a = "123" is a string
Whereas:
a = 123 is a numerical value


You cannot put strings into numerical variables,, nor numerical values into strings.

DIM a AS INTEGER
a = "hello"

Is invalid, and so is:

DIM a AS STRING
a = 123
Reply
#3
If you define a variable as STRING it will be able to contain text. It will allow you to apply the text operators and functions of QB.
Code:
Dim a as string, b as string
a="1234"
b="bcd"
print  a+b ,left$(a,2)
will print 1234bcd 12
in this case + does concatenate strings

If you define a variable as INTEGER it will be able to contain integer numbers. It will allow you to apply the number operators and functions of QB.

Code:
Dim a as integer, b as integer
a=1234
b=5
print  a+b , b * a
will print 1239 6170
Antoni
Reply
#4
If you wish not to declare all your variables with their types at the start of a program, however, you can define the type of a variable by putting a key character after it:


a! is a single (can include decimal values)
a% is an integer (whole values only)
a$ is a string (holds text)
a& is long (for very long numbers)
a# is a double (for very high-precision decimal numbers)

To find out more about data types, open the qbasic help, and click on "data types" in the contents. There is links to all the different data types with in depth information about each.
Reply
#5
SHARED it means that that variable you will be able to use it anywhere in that program
Reply
#6
STRING means you can put letters & numbers
INTEGER means you can only use numbers to +, -, /, or x
Reply
#7
o o and

Code:
DIM thingo AS STRING * 4

will give you a string with 4, yes, exactly 4 characters
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)