Type,For/next/each problem.

Blitz3D Forums/Blitz3D Beginners Area/Type,For/next/each problem.

collimic(Posted 2014) [#1]
Hello once again.
I am having a problem understanding Types with For next and each.
I am trying to gather some information both integer and string and want to save it to a file for printing at a later date. The code below is what I do not understand so I know i am doing it wrong just do not know how to fix it.

cd# = .075

Type stud
	Field v ;Student number
	Field w$ ;Student Name
	Field x$ ;Student Home Room
	Field y ;Days in DI
	Field z ;Credits
End Type

stu%=Input("How many students enrolled in you class during credit check " + cc + "? ")

For stutemp = 1 To stu
	cur.stud = New stud
	cur\v = stutemp
	cur\w = Input("Students name: ")
	cur\x = Input("Students home room: ")
	cur\y = Input("Days of Directed Instruction: ")
; z is not used yet but will be  cur\y * cd
;	cur\z = cur\y *cd 

Next
For cur.stud = Each stud 
	cur\v = cur\v + 1 
Next 

; To check and see what if anything is going on.
Print cur\v + " " + cur\w + " " + cur\x + " " +cur\y + " " ;+cur\z + " "


Once I get to the print section my debug all sets back to null and I get an "Object does not exist" error and it is all over.

If anyone can shed a little light on how this really works it would be great. The over all goal is to get this information do the math and save it to a comma separated file. I think I can use maybe the Print Str$() command if i can figure out the types and for / each command and I can figure out how to put the Print Str$() command into use.

Thank you all again. You have been great help.


Floyd(Posted 2014) [#2]
It's the same basic idea as this:

For n = 1 To 7 Step 2
	Print " n = " + n
Next

Print " After loop, n = " + n
WaitKey

Notice the "end" value would never be reached, so checking for n=7 would fail. The loop actually checks to see if n has gone past the end, and doesn't loop back to the start in that case.

That would be unusual with a Type list, but could happen if you were doing something tricky. In any case For-Each works like For-Next. It continues until the loop variable runs off the end.

If you want to examine the last element then use the Last command.


Yue(Posted 2014) [#3]
Here pdf. Types.
https://dl.dropboxusercontent.com/u/39767349/AOBPwB3D.pdf


Midimaster(Posted 2014) [#4]
In your code "cur" is only defined local inside the FOR/NEXT loop. To print it you have to move the PRINT command also inside a loop:

For cur.stud = Each stud 
	cur\v = cur\v + 1 
	Print cur\v + " " + cur\w + "... " 
Next 


For cur.stud = Each stud 
	cur\v = cur\v + 1 
Next 
For cur.stud = Each stud 
	Print cur\v + " " + cur\w + "... "
Next 


or like Floyd sayd:
For cur.stud = Each stud 
	cur\v = cur\v + 1 
Next 
cur.stud = Last stud
Print cur\v + " " + cur\w + "... "