Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Record Concept Posted by sad.boy on 8 Mar 2006 at 1:59 AM
let me ask my question like this
i want to get 100 names and 100 scores of one hundred students

wich one is better

'Module Code
Private Type my record
names As String
scores As Single
End Type
 public rec as my record 
'main program Code

put #1,,rec

grant that #1 is a name of random file
now check this:
Private Type my record
names(100) As String
scores(100) As Single
End Type
 public rec as my record 
'main program Code

put #1,1,rec

the second one is rec with fileds:names and scores that ther are arrays
and the record number is 1 when putting


now i want to know wich one is better to use?
Report
Re: Record Concept Posted by doofusboy on 8 Mar 2006 at 7:59 AM
: let me ask my question like this
: i want to get 100 names and 100 scores of one hundred students
:
: wich one is better
:
:
: 'Module Code
: Private Type my record
: names As String
: scores As Single
: End Type
:  public rec as my record 
: 'main program Code
: 
: put #1,,rec
: 

: grant that #1 is a name of random file
: now check this:
:
: Private Type my record
: names(100) As String
: scores(100) As Single
: End Type
:  public rec as my record 
: 'main program Code
: 
: put #1,1,rec
: 

: the second one is rec with fileds:names and scores that ther are arrays
: and the record number is 1 when putting
:
:
: now i want to know wich one is better to use?
:
It is probably better to use the first one, as the second one simply gives you the ability to store 100 different names and 100 hundred different scores for EACH 'my record' (which should probably be 'my_record' by the way).

It seems to me, if you have 100 students for which you want to maintain a record of their name & score you would do something like this:

Private Type student_record
student_name As String
student_score As Integer
End Type
Dim my_students(99) As student_record 'Zero based array for 100 students

And then assign each record:
my_students(0).student_name = "Joe Smith" 'first student name
my_students(0).student_score = 85 'first student score
my_students(1).student_name = "Joe Jones" '2nd student name
my_students(2).student_score = 95 '2nd student score


On the other hand, if you want EACH RECORD to be able to hold 100 different names and 100 different scores, then the second example you gave is the way to go.
Report
Re: Record Concept. I'd go with the ARRAY method. Posted by DrMarten on 8 Mar 2006 at 4:53 PM
: let me ask my question like this
: i want to get 100 names and 100 scores of one hundred students
:
: wich one is better
:
:
: 'Module Code
: Private Type my record
: names As String
: scores As Single
: End Type
:  public rec as my record 
: 'main program Code
: 
: put #1,,rec
: 

: grant that #1 is a name of random file
: now check this:
:
: Private Type my record
: names(100) As String
: scores(100) As Single
: End Type
:  public rec as my record 
: 'main program Code
: 
: put #1,1,rec
: 

: the second one is rec with fileds:names and scores that ther are arrays
: and the record number is 1 when putting
:
:
: now i want to know wich one is better to use?
:


======================================================================

By the way did you know arrays also include a number 0 element so
names(0) is valid in the array names(100)?

You can do the whole lot in a FOR NEXT LOOP too.

'
Dim index as Integer
Dim names() As String
For index=0 to 99 'Use 1 to 100 if you like
names(index)="whatever?" 'Assign the values from a file here if you like.

Next
'



Regards,

Dr M.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.