Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Record Concept

sad.boysad.boy Posts: 90Member
let me ask my question like this
i want to get 100 names and 100 scores of one hundred students

wich one is better

[code]
'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
[/code]
grant that #1 is a name of random file
now check this:
[code]
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
[/code]
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?

Comments

  • doofusboydoofusboy Posts: 256Member
    : let me ask my question like this
    : i want to get 100 names and 100 scores of one hundred students
    :
    : wich one is better
    :
    : [code]
    : '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
    : [/code]
    : grant that #1 is a name of random file
    : now check this:
    : [code]
    : 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
    : [/code]
    : 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.
  • DrMartenDrMarten Posts: 748Member
    : let me ask my question like this
    : i want to get 100 names and 100 scores of one hundred students
    :
    : wich one is better
    :
    : [code]
    : '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
    : [/code]
    : grant that #1 is a name of random file
    : now check this:
    : [code]
    : 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
    : [/code]
    : 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.

    '[blue]
    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
    '[/blue]


    Regards,

    Dr M.


Sign In or Register to comment.