user9104738
user9104738

Reputation:

a = "stackoverflow" does not work in QBasic

The qbasic code returns a type mismatch error.

a="StackOverflow"
print left$(a,5)
print right$(a,8)

What is the cause of this error and how can I rectify it?

Upvotes: 0

Views: 217

Answers (2)

user9104738
user9104738

Reputation:

The error is caused by the way you have named the variable. "StackOverflow" is a string and cannot be assigned to variables of any other type.

In Qbasic, string variables must end with a $ symbol. So try a$ instead of a.

So try this code instead.

a$="StackOverflow"
print left$(a$,5)
print right$(a$,8)

Upvotes: 1

eoredson
eoredson

Reputation: 1165

You could define the variable as string first:

DIM a AS STRING
a = "StackOverflow"
PRINT LEFT$(a, 5)
PRINT RIGHT$(a, 8)

Upvotes: 0

Related Questions