[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2006-10-10T09:26:59-05:00 http://www.petesqbsite.com/phpBB3/app.php/feed/topic/1782 2006-10-10T09:26:59-05:00 2006-10-10T09:26:59-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12926#p12926 <![CDATA[Sub Script out of range]]>
I dont fully understand what you mean with
I would like to print on either separate, or sequensial screens
But what i look at your source (i cant test it atm since my dosbox got messed by some reason) youre on good road there.
Surely there is lot's of places where you could do things different, but to say honest, your program looks very good.

Keep on learning and youll find some lines, where you prolly want to make program run differently.

Personally i would like to do DIM like this.

Code:

DIM freshSTU(30) AS STRINGDIM freshGPA(30) AS DOUBLEDIM freshA, FreshB, FreshTemp, FreshTotal AS DOUBLEDIM freshX AS INTEGER      freshX = 0 
But your way is as workable than my one. No reason to change. But i think it's easier to read on way i do it. But thats totally opinion matter.

You could also try to use indent's on your code.

Code:

WHILE NOT EOF(1)INPUT #1, stu, class, GPASELECT CASE classCASE "Freshman"freshSTU(freshX) = stufreshGPA(freshX) = GPAfreshX = freshX + 1CASE "Sophomore"sophSTU(sophX) = stusophGPA(sophX) = GPAsophX = sophX + 1CASE "Junior"juniSTU(juniX) = stujuniGPA(juniX) = GPAjuniX = juniX + 1CASE "Senior"seniSTU(seniX) = stuseniGPA(seniX) = GPAseniX = seniX + 1END SELECTWENDCLOSE #1 
or

Code:

FOR freshA = 0 TO 29FOR freshB = 0 TO freshAIF freshGPA(freshB) < freshGPA(freshB + 1) THENfreshTemp = freshGPA(freshB)freshGPA(freshB) = freshGPA(freshB + 1)freshGPA(freshB + 1) = freshTempEND IFNEXT freshBNEXT freshA
Doesnt it look easier to follw?
One more thing i would recommend to you is comments.
Even your code aint longer than 192 lines and prolly it's very easy and simple to understand, for others (like me) it takes time to go thru it and get full picture of what it does and how.

Dont comment every line.

Code:

FOR x = 0 TO sophX - 1PRINT x, sophSTU(x), sophGPA(x)NEXT xSLEEP
Im sure you instantly now know what that part of code does. But others, it's a totally different thing.

Code:

' Goes thru XXX because of reason XXXFOR x = 0 TO sophX - 1    PRINT x, sophSTU(x), sophGPA(x)NEXT xSLEEP
Short simple explanations on code, makes it way easier to read.

Statistics: Posted by bungytheworm — Tue Oct 10, 2006 9:26 am


]]>
2006-10-09T19:53:26-05:00 2006-10-09T19:53:26-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12924#p12924 <![CDATA[Sub Script out of range]]>

CLS
DIM stu AS STRING
DIM class AS STRING
DIM GPA AS DOUBLE

DIM freshSTU(30) AS STRING
DIM freshGPA(30) AS DOUBLE
DIM freshA AS DOUBLE
DIM freshB AS DOUBLE
DIM freshTemp AS DOUBLE
DIM freshTotal AS DOUBLE
DIM freshX AS INTEGER
freshX = 0

DIM sophSTU(30) AS STRING
DIM sophGPA(30) AS DOUBLE
DIM sophA AS DOUBLE
DIM sophB AS DOUBLE
DIM sophTemp AS DOUBLE
DIM sophTotla AS DOUBLE
DIM sophX AS INTEGER
sophX = 0

DIM juniSTU(30) AS STRING
DIM juniGPA(30) AS DOUBLE
DIM juniA AS DOUBLE
DIM juniB AS DOUBLE
DIM juniTemp AS DOUBLE
DIM juniTotal AS DOUBLE
DIM juniX AS INTEGER
juniX = 0

DIM seniSTU(30) AS STRING
DIM seniGPA(30) AS DOUBLE
DIM seniA AS DOUBLE
DIM seniB AS DOUBLE
DIM seniTemp AS DOUBLE
DIM SeniTemo AS DOUBLE
DIM seniX AS INTEGER
seniX = 0

DIM x AS INTEGER


OPEN "students.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, stu, class, GPA

SELECT CASE class

CASE "Freshman"
freshSTU(freshX) = stu
freshGPA(freshX) = GPA
freshX = freshX + 1

CASE "Sophomore"
sophSTU(sophX) = stu
sophGPA(sophX) = GPA
sophX = sophX + 1

CASE "Junior"
juniSTU(juniX) = stu
juniGPA(juniX) = GPA
juniX = juniX + 1

CASE "Senior"
seniSTU(seniX) = stu
seniGPA(seniX) = GPA
seniX = seniX + 1

END SELECT
WEND
CLOSE #1



FOR freshA = 0 TO 29
FOR freshB = 0 TO freshA
IF freshGPA(freshB) < freshGPA(freshB + 1) THEN
freshTemp = freshGPA(freshB)
freshGPA(freshB) = freshGPA(freshB + 1)
freshGPA(freshB + 1) = freshTemp
END IF
NEXT freshB
NEXT freshA

PRINT
PRINT

FOR x = 0 TO freshX - 1
PRINT x, freshSTU(x), freshGPA(x)
NEXT x

x = 0
FOR x = 0 TO freshX - 1
freshTotal = freshGPA(x) + freshTotal
NEXT x

freshTotal = freshTotal / (freshX - 1)

PRINT
PRINT "Freshman Class Average",
PRINT USING "#.##"; freshTotal
SLEEP

FOR sophA = 0 TO 29
FOR sophB = 0 TO sophA
IF sophGPA(sophB) < sophGPA(sophB + 1) THEN
sophTemp = sophGPA(sophB)
sophGPA(sophB) = sophGPA(sophB + 1)
sophGPA(sophB + 1) = sophTemp
END IF
NEXT sophB
NEXT sophA

PRINT
PRINT

FOR x = 0 TO sophX - 1
PRINT x, sophSTU(x), sophGPA(x)
NEXT x
SLEEP

x = 0
FOR x = 0 TO sophX - 1
sophTotal = sophGPA(x) + sophTotal
NEXT x

sophTotal = sophTotal / (sophX - 1)

PRINT
PRINT "Sophomore Class Average",
PRINT USING "#.##"; sophTotal

FOR juniA = 0 TO 29
FOR juniB = 0 TO juniA
IF juniGPA(juniB) < juniGPA(juniB + 1) THEN
juniTemp = juniGPA(juniB)
juniGPA(juniB) = juniGPA(juniB + 1)
juniGPA(juniB + 1) = juniTemp
END IF
NEXT juniB
NEXT juniA

PRINT
PRINT

FOR x = 0 TO juniX - 1
PRINT x, juniSTU(x), juniGPA(x)
NEXT x
SLEEP

x = 0
FOR x = 0 TO juniX - 1
juniTotal = juniTotal + juniGPA(x)
NEXT x

juniTotal = juniTotal / (juniX - 1)

PRINT
PRINT "Junior Class Average",
PRINT USING "#.##"; juniTotal

PRINT
PRINT

FOR seniA = 0 TO 29
FOR seniB = 0 TO seniA
IF seniGPA(seniB) < seniGPA(seniB + 1) THEN
seniTemp = seniGPA(seniB)
seniGPA(seniB) = seniGPA(seniB + 1)
seniGPA(seniB + 1) = seniTemp
END IF
NEXT seniB
NEXT seniA

FOR x = 0 TO seniX - 1
PRINT x, seniSTU(x), seniGPA(x)
NEXT x
SLEEP

x = 0
FOR x = 0 TO seniX - 1
seniTotal = seniGPA(x) + seniTotal
NEXT x

seniTotal = seniTotal / (seniX - 1)

PRINT
PRINT "Senior Class Average",
PRINT USING "#.##"; seniTotal

[/quote]

Statistics: Posted by TheWicker — Mon Oct 09, 2006 7:53 pm


]]>
2006-10-07T14:17:23-05:00 2006-10-07T14:17:23-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12893#p12893 <![CDATA[Sub Script out of range]]>

Code:

x = 0FOR x = 0 TO 100PRINT x, sophSTU(x), sophGPA(x)x = x + 1SLEEPNEXT x 
Why you grow x + 1 even you are using FOR NEXT loop that does increase value of x every round?

When you are reading from students.txt, you increase value of x every round.
Is that really your purpose? Since x gets + 1 every round, two arrays() gets empty cells.

example: lets think x has value 5
CASE "Sophomore"
sophSTU(x) = stu
sophGPA(x) = GPA
x = x + 1 ' now x is 6

rest of arrays(5) dont get anything. If you wana create seperate arrays, you need to use different counter (this case only counter is x) for each array.

I edited your code a bit. I hope that explains it better than my bad english.
With this one, you can decrease also your array entries. I leaved them to 100. Dont wana give you finished code.

Let us know if this not helping.

Code:

CLSDIM stu AS STRINGDIM class AS STRINGDIM GPA AS DOUBLEDIM freshSTU(100) AS STRINGDIM freshGPA(100) AS DOUBLEDIM freshX AS IntegerfreshX = 0DIM sophSTU(100) AS STRINGDIM sophGPA(100) AS DOUBLEDIM sophX AS IntegersophX = 0DIM juniSTU(100) AS STRINGDIM juniGPA(100) AS DOUBLEDIM juniX AS IntegerjuniX = 0DIM seniSTU(100) AS STRINGDIM seniGPA(100) AS DOUBLEDIM seniX AS IntegerseniX = 0DIM x AS IntegerOPEN "students.txt" FOR INPUT AS #1WHILE NOT EOF(1)INPUT #1, stu, class, GPASELECT CASE classCASE "Freshman"freshSTU(freshX) = stufreshGPA(freshX) = GPAfreshX = freshX + 1CASE "Sophomore"sophSTU(sophX) = stusophGPA(sophX) = GPAsophX = sophX + 1CASE "Junior"juniSTU(juniX) = stujuniGPA(juniX) = GPAjuniX = juniX + 1CASE "Senior"seniSTU(seniX) = stuseniGPA(seniX) = GPAseniX = seniX + 1END SELECTWENDCLOSE #1 ' remember to close file too ;)FOR x = 0 TO freshXPRINT x, freshSTU(x), freshGPA(x)NEXT x FOR x = 0 TO sophXPRINT x, sophSTU(x), sophGPA(x)NEXT x FOR x = 0 TO juniXPRINT x, juniSTU(x), juniGPA(x)NEXT x FOR x = 0 TO seniXPRINT x, seniSTU(x), seniGPA(x)NEXT x 
You see few bugs on code i did left there with purpose. Output of that program gives something extra from arrays. Now solve how you get riddof them ;)

[edit]
when you get your program running as you need, please post it here so we see what you ended with :)
[/edit]

Statistics: Posted by bungytheworm — Sat Oct 07, 2006 2:17 pm


]]>
2006-10-07T11:57:56-05:00 2006-10-07T11:57:56-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12891#p12891 <![CDATA[Sub Script out of range]]>

here is the updated code
DIM stu AS STRING
DIM class AS STRING
DIM GPA AS DOUBLE
DIM freshSTU(100) AS STRING
DIM freshGPA(100) AS DOUBLE
DIM sophSTU(100) AS STRING
DIM sophGPA(100) AS DOUBLE
DIM juniSTU(100) AS STRING
DIM juniGPA(100) AS DOUBLE
DIM seniSTU(100) AS STRING
DIM seniGPA(100) AS DOUBLE
DIM x AS INTEGER
OPEN "students.txt" FOR INPUT AS #1
CLS
x = 0
WHILE NOT EOF(1)
INPUT #1, stu, class, GPA
SELECT CASE class
CASE "Freshman"
freshSTU(x) = stu
freshGPA(x) = GPA
x = x + 1

CASE "Sophomore"
sophSTU(x) = stu
sophGPA(x) = GPA
x = x + 1
CASE "Junior"
juniSTU(x) = stu
juniGPA(x) = GPA
x = x + 1
CASE "Senior"
seniSTU(x) = stu
seniGPA(x) = GPA
x = x + 1
END SELECT
WEND

x = 0
FOR x = 0 TO 100
PRINT x, sophSTU(x), sophGPA(x)
x = x + 1
SLEEP
NEXT x

Statistics: Posted by TheWicker — Sat Oct 07, 2006 11:57 am


]]>
2006-10-07T09:13:10-05:00 2006-10-07T09:13:10-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12888#p12888 <![CDATA[Sub Script out of range]]> Subscript out of range.

Change your array dims to 100 or something. And hey, pay attention in class.

Statistics: Posted by Z!re — Sat Oct 07, 2006 9:13 am


]]>
2006-10-06T22:18:55-05:00 2006-10-06T22:18:55-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12885#p12885 <![CDATA[Sub Script out of range]]>

Statistics: Posted by TheWicker — Fri Oct 06, 2006 10:18 pm


]]>
2006-10-06T18:25:06-05:00 2006-10-06T18:25:06-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12881#p12881 <![CDATA[Sub Script out of range]]>
STU0758,Freshman,2.81
dim stu as string
dim class as string
dim gpa as integer
Is it my eyes or what but i do see String, String, Double on that .txt file?

Statistics: Posted by bungytheworm — Fri Oct 06, 2006 6:25 pm


]]>
2006-10-06T18:15:37-05:00 2006-10-06T18:15:37-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12880#p12880 <![CDATA[Sub Script out of range]]>

Code:

while x < 30 print freshSTU(x), freshGPA(x) x = x + 1 wend
Before the while, you need to set x=0,
otherwise the while will start off with x equal to what it was before.

*****

Statistics: Posted by moneo — Fri Oct 06, 2006 6:15 pm


]]>
2006-10-06T16:22:07-05:00 2006-10-06T16:22:07-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12879#p12879 <![CDATA[Sub Script out of range]]> Statistics: Posted by Patz QuickBASIC Creations — Fri Oct 06, 2006 4:22 pm


]]>
2006-10-06T14:42:21-05:00 2006-10-06T14:42:21-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12878#p12878 <![CDATA[Sub Script out of range]]>
STU0758,Freshman,2.81
STU0454,Senior,2.03
STU0584,Senior,2.56
STU0429,Freshman,3.71
STU0470,Freshman,2.58
STU0702,Junior,3.46
STU0645,Junior,3.18
STU0558,Freshman,3.72
STU0531,Junior,1.22
STU0668,Freshman,1.23
STU0533,Senior,1.12
STU0800,Senior,3.33
STU0349,Junior,1.91
STU0837,Sophomore,3.07
STU0403,Junior,2.84
STU0056,Sophomore,2.15
STU0541,Junior,3.75
STU0765,Freshman,2.72
STU0987,Senior,3.55
STU0820,Sophomore,1.23
STU0867,Freshman,3.69
STU0166,Sophomore,2.18
STU0995,Senior,2.72
STU0677,Sophomore,1.50
STU0236,Freshman,2.08
STU0145,Senior,3.81
STU0783,Sophomore,3.78
STU0497,Sophomore,2.13
STU0405,Senior,3.93
STU0726,Senior,2.89
STU0070,Freshman,2.22
STU0804,Junior,3.75
STU0241,Freshman,3.47
STU0916,Freshman,1.42
STU0093,Freshman,3.14
STU0576,Sophomore,1.19
STU0844,Sophomore,3.09
STU0378,Freshman,2.72
STU0125,Sophomore,2.93
STU0065,Junior,3.29
STU0600,Freshman,3.48
STU0043,Junior,1.89
STU0592,Sophomore,1.51
STU0251,Junior,1.49
STU0543,Junior,3.21
STU0302,Freshman,1.59
STU0803,Senior,2.66
STU0982,Sophomore,2.95
STU0046,Senior,2.18
STU0644,Junior,1.52
STU0419,Senior,2.21
STU0570,Junior,3.41
STU0126,Freshman,1.13
STU0119,Junior,2.11
STU0101,Freshman,2.36
STU0462,Senior,3.29
STU0893,Freshman,1.72
STU0738,Senior,1.19
STU0724,Sophomore,3.23
STU0228,Sophomore,1.74
STU0430,Sophomore,1.74
STU0996,Junior,1.06
STU0219,Junior,2.41
STU0476,Sophomore,2.50
STU0104,Junior,2.76
STU0740,Sophomore,3.90
STU0569,Senior,2.41
STU0110,Junior,1.83
STU0620,Senior,2.54
STU0779,Sophomore,3.87
STU0556,Sophomore,2.18
STU0152,Freshman,3.27


and I am getting the error on all of the case lines that assign stu or gpa to the arrays

Statistics: Posted by TheWicker — Fri Oct 06, 2006 2:42 pm


]]>
2006-10-06T13:58:10-05:00 2006-10-06T13:58:10-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12876#p12876 <![CDATA[Sub Script out of range]]>
Subscript out of Range is a terrible error; it can mean way to many things. It just doesn't make sense. Stupid microshit.

Statistics: Posted by {Nathan} — Fri Oct 06, 2006 1:58 pm


]]>
2006-10-06T08:03:10-05:00 2006-10-06T08:03:10-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12875#p12875 <![CDATA[Sub Script out of range]]> Could you post your students.txt too?
As far as i see, there should be no problems on that code of your.
Fix me fellas if im wrong. Cant acces to qbasic atm.

Statistics: Posted by bungytheworm — Fri Oct 06, 2006 8:03 am


]]>
2006-10-06T00:00:14-05:00 2006-10-06T00:00:14-05:00 http://www.petesqbsite.com/phpBB3/viewtopic.php?p=12873#p12873 <![CDATA[Sub Script out of range]]>
dim stu as string
dim class as string
dim gpa as integer
dim freshSTU(30) as string
dim freshGPA(30) as integer
dim sophSTU(30) as string
dim sophGPA(30) as integer
dim juniSTU(30) as string
dim juniGPA(30) as integer
dim seniSTU(30) as string
dim seniGPA(30) as integer
dim x as integer

open "students.txt" for input as #1
x = 0
while not EOF(1)
input #1, stu, class, gpa

if class = "Freshman" then
freshSTU(x) = stu
freshGPA(x) = gpa
x = x + 1
elseif class = "Sophomore" then
sophSTU(x) = stu
sophGPA(x) = gpa
x = x + 1
elseif class = "Junior" then
juniSTU(x) = stu
juniGPA(x) = gpa
x = x + 1
elseif class = "Senior" then
seniSTU(x) = stu
seniGPA(x) = gpa
x = x + 1
endif
wend

while x < 30
print freshSTU(x), freshGPA(x)
x = x + 1
wend

Statistics: Posted by TheWicker — Fri Oct 06, 2006 12:00 am


]]>