Posts: 33
Threads: 8
Joined: Jan 2006
Hey Guys...Sorry I am asking so much questions its just that I am getting qbasic gradually and Im finding it abit hard to understand some things.
Code:
CLS
PRINT
PRINT "ENTER FILE NAME:";
INPUT FILEN$
CLS
OPEN FILEN$ FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, A$
IF A$ <> "" THEN LN = LN + 1
WEND
CLOSE
IF LN = 1 THEN PRINT "YOUR PROGRAM HAS ONLY 1 LINE OF CODE!"
PRINT "YOUR PROGRAM HAS"; LN; "LINES OF CODE"
I really dont get the middle part and how it works. Hope somone can explain...
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 324
Threads: 12
Joined: Nov 2005
Note, I changed "input #1" to "line input #1" so an entire line is read. I also changed the variable names for better readibility:
Code:
cls
print
print "ENTER FILE NAME:";
input fileName$
open fileName$ for input as #1
while not eof(1) '' while the end hasn't been reached yet ...
line input #1, tempLine '' read a line from the file
if tempLine <> "" then lineCount = lineCount + 1 '' if the line is not empty, increase the line count
wend '' repeat
close
if lineCount = 1 then
print "YOUR PROGRAM HAS ONLY 1 LINE OF CODE!"
end
end if
print "YOUR PROGRAM HAS"; lineCount; "LINES OF CODE"
Don't be sorry - all questions are relevant. Ask if you need more help.
stylin:
Posts: 33
Threads: 8
Joined: Jan 2006
Hey Thanx for that But I still dont get this part...
Code:
if tempLine <> "" then lineCount = lineCount + 1
I dont get how this checks for words in a line!!
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 6,419
Threads: 74
Joined: Mar 2002
It checks if a line is empty. <> "" means "different from empty".
Posts: 1,080
Threads: 87
Joined: Feb 2002
Personally, I would make a function to ignore comments, something like this:
[syntax="qbasic"]
'Remove leading and tailing spaces and making it all lowercase
templine=lcase$(ltrim$(rtrim$(tempLine)))
if tempLine<>"" then
'Checking if tempLine is a comment (beginning with ' or REM) but not a metacommand (beginning with '$)
if (mid$(tempLine,1,1)<>"'" or mid$(tempLine,2,1)="$") and mid$(tempLine,1,3)<>"rem") then
lineCount=lineCount+1
end if
end if[/syntax]
/post]
Posts: 684
Threads: 64
Joined: May 2004
Hybrid, incase nathan didn't clear it up...
When you learned math, you were most likely shown these signs: "<", ">", "=", etc. Well, the not-equal to sign that you have in math is not something that you can type easily. So to make a not-equal sign, you need to do this: "<>". So in our line of code:
Code:
if tempLine <> "" then
lineCount = lineCount + 1
It is saying "If templine does not equal anything, then add another line". So if a line in the file does not have anything, it doesn't count it as a line. Do you understand now?
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Posts: 2,771
Threads: 96
Joined: Oct 2003
Doesnt help when you dont proofread your posts, Torahteen! :)
Quote:Hybrid, incase nathan didn't clear it up...
When you learned math, you were most likely shown these signs: "<", ">", "=", etc. Well, the not-equal to sign that you have in math is not something that you can type easily. So to make a not-equal sign, you need to do this: "<>". So in our line of code:
Code:
if tempLine <> "" then
lineCount = lineCount + 1
It is saying "If templine does not equal nothing, then add another line". So if a line in the file does not have anything, it doesn't count it as a line. Do you understand now?
Posts: 324
Threads: 12
Joined: Nov 2005
Code:
if tempLine <> "" then lineCount = lineCount + 1
I read it as: "if tempLine compares unequal to an empty string, increment lineCount."
stylin:
Posts: 33
Threads: 8
Joined: Jan 2006
Hey thanx guys for all your help. You all really friendly...
But I still got one more problem..........
I get an Error when I want to run the program in QBASIC.
I Get "Type Mismatch"
LINE INPUT #1, tempLine
And it Highlights LINE...
Any Ideas?
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 2,404
Threads: 153
Joined: Jan 2005
That's cause Templine is ment to be a string, thus you either need a $ at the end of it:
Templine$
Or,. somewhere before you use templine (e.g., better put at the top of the code), you can do this:
Code:
DIM templine AS STRING
Which will save you from adding $'s to the end of templine every time you use it..
:wink:
Kevin (
x.t.r.GRAPHICS)