You are here:

Qbasic, Quickbasic/new DATA is NOT workign with the program

Advertisement


Question
QUESTION: Hi Alex,

I'm getting a "Type Mismatch" error message, when I'm trying to RUN it;
the words: "SUBSTR$"  from lines 452 and 453 are being highlighted.
I found out that a TYPE MISMATCH means a numeric value is assigned
to a string variable or, a string is assigned to a numeric value.

I'm using QuickBASIC versions: 1.0, 4.5, 6.1 and, 7.1
can you PLEASE help me - during my 54 years of existence (I'm 54), I don't think I ever encountered such a message before.

Thank you!.
Michael.
*********************************************************************************
1 CLS
200 DIM N$(4), B$(4), C$(4)
210 REM - READ Number Of Records:
220 READ K
230 REM - READ Records Into ARRAYS:
240  FOR I = 1 TO K
250   READ N$(I), B$(I), C$(I)
260  NEXT I
350 REM - Repeat
360 PRINT "Please, ENTER s.s.number to be SEARCHED in the Employee RECORDS ";
370 INPUT R$
380 REM - SEARCH For RECORD: S.S.Number ALREADY Chosen
390 FOR I = 1 TO K
400   IF R$ <> B$(I) THEN 481
401 PRINT
402 PRINT
403 PRINT
420 PRINT "S. S.Number you've entered was ALREADY on LIST since : "; N$(I), "S.S.Number was an EXACT MATCH:"; B$(I), "Date FIRED:"; C$(I)
430 PRINT
440 PRINT
450 PRINT "No Record Found!. Would you like to try again?. (Y/N)"; F$
451  INPUT F$
452 IF SUBSTR$(UCASE$(F$), 1, 1) = "N" THEN GOTO 480
453 IF SUBSTR$(UCASE$(F$), 1, 1) = "Y" THEN GOTO 500
480  END
481  NEXT I
500 GOTO 350
1000 REM - DATA:
1010 REM - Number Of Records:
1020 DATA 4
1030 REM - N$=Date HIRED, B$=Soc. Sec. Number, C$=Date FIRED
1040 DATA "01-25-2001", "331-01-5981", "09-11-2011"
1050 DATA "03-30-1981", "053-00-9153", "01-20-2000"
1060 DATA "11-13-1983", "004-35-5391", "12-13-2009"
1070 DATA "10-29-2011", "365-76-1200", "10-30-2013"
9999 END
***************************************************************************
Why am I getting this Type Mismatch message error for these lines?.

THANK YOU!.
Michael.

ANSWER: Hi Micheal,

Like I said in the previous answer, I mixed up my languages and SUBSTR$( ... ) should really be MID$( ... ):

452 IF MID$(UCASE$(F$), 1, 1) = "N" THEN GOTO 480
453 IF MID$(UCASE$(F$), 1, 1) = "Y" THEN GOTO 500


The type mismatch is because QBasic thinks SUBSTR$ is a string, and we're using it like a function, and this was because, as I said, I mixed up the function name (some languages, to get pieces of strings, use substr rather than mid).

Fixes to the lines I just sent you (same as in the previous answer) should resolve your issue.

Also, on the tail end of 450, you can remove the F$, since that will append the last set value of F$ (initial run will be "", second (and beyond) runs would presumably be "Y").

I hope that helps,
-Alex

---------- FOLLOW-UP ----------

QUESTION: Hi Alex,
I was told that I can't use s.s.numbers in my DATA because of privacy issues but, can use employee record numbers which is a number such as: "11,20,22,30,31,40"  (ALWAYS a six number); but, THIS type of numbers is NOT being recognized by the program - what changes should I make to the program?.  I've tried to RUN it, with such numbers rather than s.s.# but, it's NOT working.
***************************************************************
1 CLS
200 DIM N$(4), B$(4), C$(4)
210 REM - READ Number Of Records:
220 READ K
230 REM - READ Records Into ARRAYS:
240  FOR I = 1 TO K
250   READ N$(I), B$(I), C$(I)
260  NEXT I
350 REM - Repeat
360 PRINT "Please, ENTER employee number to be SEARCHED in the LIST ";
370 INPUT R$
380 REM - SEARCH For RECORD: The Number ALREADY Chosen
390 FOR I = 1 TO K
400   IF R$ <> B$(I) THEN 481
401 PRINT
402 PRINT
403 PRINT
420 PRINT "The Employee Number you've entered exists since : "; N$(I), "The Number was an EXACT MATCH:"; B$(I), "DATE FIRED:"; C$(I)
430 PRINT
440 PRINT
450 PRINT "Would you like to try again?. (Y/N)";
451  INPUT F$
452 IF MID$(UCASE$(F$), 1, 1) = "N" THEN GOTO 480
453 IF MID$(UCASE$(F$), 1, 1) = "Y" THEN GOTO 500
480  END
481  NEXT I
500 GOTO 350
1000 REM - DATA:
1010 REM - Number Of Records:
1020 DATA 4
1030 REM - N$=Date HIRED, B$=Employee Number, C$=Date FIRED
1040 DATA  "02-04-1995", "11,20,21,24,29,42",  "09-11-2011"
1050 DATA  "01-07-1995", "24,31,33,35,40,44",  "01-20-2000"
1060 DATA  "12-10-1994", "21,23,35,37,39,48",  "12-13-2009"
1070 DATA  "10-22-1994", "10,16,20,28,39,40",  "10-20-2013"
9999 END
**************************************************************************
What changes should I make, so that if I enter "11,20,21,24,29,42" the program would recognize it and, tell me when the employee was HIRED and, FIRED.

Thank you,
Michael.

Answer
Hey Michael,

QBasic's INPUT is a little weird, because it tries to do some basic parsing on the data you type in.  When you type in commas in the INPUT response, QBasic will actually interpret those as a series of variables.  For example, if I had:

INPUT "Test Input:", A$
PRINT A$


Run it:

Test Input: Some,Data,I,Give
Some


This is because QBasic can actually deal with multiple variables in an INPUT, which works like this:

INPUT "Test Input:", A$, B$, C$, D$
PRINT A$, B$, C$, D$


Run it:

Test Input: Some,Data,I,Give
Some    Data    I   Give


So, since we know that there will always be 6 sets of numbers, the easiest way to deal with those commas would be:

370 INPUT R1$, R2$, R3$, R4$, R5$, R6$
317 R$ = LTRIM( RTRIM$( R1$ ) + "," + LTRIM( RTRIM$( R2$ ) + "," + LTRIM( RTRIM$( R3$ ) + "," + LTRIM( RTRIM$( R4$ ) + "," + LTRIM( RTRIM$( R5$ ) + "," +LTRIM( RTRIM$( R6$ )


Not the nicest looking code, but it works.

I want to mention that if this is code that you want to run in an actual business, I'd really recommend something in C (or any other modern language) and use a proper database like SQLite.  There may even be free applications out there to use, too.  That's not to discourage you from making this, but there are other tools available, and often times the wheel doesn't need to be re-invented.

Otherwise, I hope that fix helps,
-Alex

Qbasic, Quickbasic

All Answers


Ask Experts

Volunteer


Alex Barry

Expertise

I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, QB64, c/c++, python, lua, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.

Experience

I have been programming in *Basic dialects since 2000, as mentioned in my expertise. After a year of QBasic, I learned C and C++, and dabbled a little in ASM (I don't program in ASM - I literally just played around to see how things work). When QB64 and FreeBASIC were released, I played with those languages. At the time, FreeBASIC offered more functionality and I sided with that language for a while. During that time, while I was learning new languages, that I would see what scripting languages are available, where I took up python and lua. I started to notice a staleness to QB64's development (which I kept tabs on from time to time), and am now trying to be active in it's community and maybe in it's development in the future. Currently, I am only active on the QB64.net forums, but I appear on occasion on FreeBASIC.net's forums as well.

Education/Credentials
Highschool - 2007

©2016 About.com. All rights reserved.