Howdy, Stranger!

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


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.

Storing Game data in seperate files

BahkranBahkran Posts: 33Member

I am writing a 3D-isometric turn-based strategy game in VB5 and I am having trouble writing and reading to and from files. When I have one section done I can change it to the rest but I can't get started. The file would compromise of People Data, for each person there are attributes assigned to them:

ID (Integer)
Name (String)
Military Potential (Integer)
Economic Potential (Integer)
Political Potential (Integer)

When the program gets the information, it sends the ID number to the file and I want the attributes assigned with that ID back and into variables. I have messed around with the Get and Put statements but alas; no luck. The data file would also need to be written from a separate file, not available to the end user but so that it is easier to put the 500+ people in.

Any ideas? Please reply here or email me: I can’t pay in money for advice but will repay in your problems if necessary.



  • MachairaMachaira Posts: 13Member
    Create a UDT to store this data, like:

    Type udtPerson
    sName As String
    iMilitaryPotential As Integer
    iEconomicPotential As Integer
    iPoliticalPotential As Integer
    End Type

    Here's code that will save and read the data:

    Dim iFileNum As Integer
    Dim iLp As Integer

    iFileNum = FreeFile

    Open "c:files est.dat" For Binary As iFileNum

    Put #iFileNum, , UBound(People)

    For iLp = 0 To UBound(People)
    Put #iFileNum, , People(iLp)
    Next iLp

    Close iFileNum

    Dim iFileNum As Integer
    Dim iLp As Integer

    iFileNum = FreeFile

    Open "c:files est.dat" For Binary As iFileNum

    Get #iFileNum, , iNumPeople
    ReDim People(iNumPeople)

    For iLp = 0 To UBound(People)
    Get #iFileNum, , People(iLp)
    Next iLp

    Close iFileNum

    HTH, let me know if there are any problems.

Sign In or Register to comment.