Front Office Football Central

Front Office Football Central (https://forums.operationsports.com/fofc//index.php)
-   FOFC Archive (https://forums.operationsports.com/fofc//forumdisplay.php?f=27)
-   -   Ping: Visual Basic Programmers (https://forums.operationsports.com/fofc//showthread.php?t=55323)

Oilers9911 12-16-2006 06:03 PM

Ping: Visual Basic Programmers
 
I am trying to learn VB programming and my first project is a very simple soccer game based on attack and defence ratings. What I want to do is store the teams and their rating in a .dat file that can retrieve the ratings as each team plays. It is very simple. The only data I need to store is the team name (example, Liverpool) the nickname, (The Reds), home ground (Anfield), attack rating (an integer between 1 and 100) and defence rating (between 1 and 100).

What is the best way to do this? Just create a text document with something like Liverpool,The Reds,Anfield,78,76? Or do I have to create some kind of input form and write the data to a file that way?

Thanks guys.

Coder 12-16-2006 06:26 PM

create a type for the team.. like this:

Code:

Type tTeam
  Name As String * 20
  Stadium As String * 20
  AttackRating As Byte
  DefenseRating As Byte
End Type


The use random access to retrieve the data

lets see if I remember this.. might be a bit sloppy, but whatever

Code:


Dim AllTeams() as tTeam
Dim tmpTeam as tTeam
Dim TeamFile as string
Dim TeamsRead as integer

TeamFile = App.Path & "\TeamFile.dat"

Open TeamFile For Random As #1 Len = Len(tmpTeam)

Do While Not EOF(1)
  Get #1, TeamsRead, tmpTeam
  TeamsRead = TeamsRead + 1
  ReDim Preserve AllTeams(TeamsRead)
  AllTeams(TeamsRead) = tmpTeam
Loop

Close #1


Oh.. and obviously you need to save as well.. check this article out:

http://support.microsoft.com/kb/150700

Since you have so few variables, you might actually use textfiles rather than binary files though..

That's much easier..

Use the same type, but start by creating a textfile like this:

Liverpool,Anfield,60,70
Arsenal, Emirate Stadium, 99,99

Then use this little sub to read rather than the stuff I used above (replace everything from Open to Loop

Code:

Dim arTeam() as String
Dim TeamsRead as Integer

Open FileName for Input as #1
Do while not eof(1)
  Line Input #1, s
  arTeam = Split(s,",")
  tmpTeam.Name = arTeam(0)
  tmpTeam.Stadium = arTeam(1)
  tmpTeam.Attack = CInt(arTeam(2))
  tmpTeam.Defense = CInt(arTeam(3))
  TeamsRead = TeamsRead + 1
  ReDim Preserve AllTeams(TeamsRead)
  AllTeams(TeamsRead) = tmpTeam
Loop


This might need a few changes.. a bit tired here.. and I'm basically writing from memory..

Oilers9911 12-16-2006 06:35 PM

Thanks alot man. I'll give that a try.

Quote:

Originally Posted by Coder (Post 1336192)
Liverpool,Anfield,60,70
Arsenal, Emirate Stadium, 99,99



You must be an Arsenal supporter :)

Coder 12-16-2006 06:39 PM

Quote:

Originally Posted by Oilers9911 (Post 1336194)
Thanks alot man. I'll give that a try.



You must be an Arsenal supporter :)



Chelsea,Toilet,1,1

:)

daedalus 12-16-2006 06:43 PM

Quote:

Originally Posted by Coder (Post 1336192)
Liverpool,Anfield,60,70
Arsenal, Emirate Stadium, 99,99

You are CORRECT, sir! :D

Oilers9911 12-16-2006 06:51 PM

Quote:

Originally Posted by Coder (Post 1336196)
Chelsea,Toilet,1,1

:)


I would have gone with Shithole but yeah I agree. :D

Oilers9911 12-16-2006 06:53 PM

Now I assume I can do something similar with the fixture list. I would like to assign each team a number from 1 to 20 and then have the fixtures look like this:

1,20
2,19
3,18

with the home side listed first. Then at the end of the season renumber all the teams so that the fixtures change. Does that sound right?

Oilers9911 12-16-2006 06:53 PM

Quote:

Originally Posted by daedalus (Post 1336198)
You are CORRECT, sir! :D


In that case after today it would be Portsmouth 99,99 right? :D


All times are GMT -5. The time now is 11:25 PM.

Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.