Posts: 21
Threads: 10
Joined: Feb 2005
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?
Posts: 3,522
Threads: 189
Joined: Dec 2003
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
Posts: 1,407
Threads: 117
Joined: Dec 2002
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
Posts: 2,771
Threads: 96
Joined: Oct 2003
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.
Posts: 17
Threads: 4
Joined: Nov 2004
SHARED it means that that variable you will be able to use it anywhere in that program
Posts: 21
Threads: 6
Joined: Jul 2004
STRING means you can put letters & numbers
INTEGER means you can only use numbers to +, -, /, or x