0

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?

2 Answers2

1

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)
0

You could define the variable as string first:

DIM a AS STRING
a = "StackOverflow"
PRINT LEFT$(a, 5)
PRINT RIGHT$(a, 8)
eoredson
  • 1,167
  • 2
  • 14
  • 29