Help with VB - Input from a file

Started by
5 comments, last by Wizzy 20 years, 6 months ago
ok - i have a file with repeating data - in the exact same format over and over and over (about 3500 entries)... but at the very beginning of this text file there is a single number - that number is how many entries.... and it never repeats or has a spot... here''s an example.

2
74  74  74  76  75  75  74  67  67  60 
 68  75  74  64  95  23  8  14  1  4  1 
 1973  24  6  2400000  2  1991  4  17  14 
 0  0  0  0 
 0  0  0  0 
 3000  3000  90000  1  0  0 
 1  0  0  0  0  0 
 83530009  85770021  85660034  98770044  83540057  86770069  87690080  34440094  93230105  85340116 
 88850129  84550140  84550706  86750164  87970176  64540901  34340200  34230214  84440738  84250788 
 87670249  84540260  14340273  77650284  24130298  84540308  87660320  0  85580344  85760357 
 0  0  0  0  4  191  7  2 
 0  0  0  0  0 
-
Milan Hnilicka

drafted
133107070145082112130075117020098080125
1.16 (24.3.2002)
1.16 (24.3.2002)
-38  0  14  75  70 
 30  31  25  42  56  51  64  61  84  21 
 50  60  87  33  116  57  3  0  2  1  0 
 1990  23  10  100000  0  0  0  0  99 
 0  0  0  0 
 0  0  0  0 
 0  0  0  0  0  1 
 10  1  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  3  208  11  6 
 0  0  0  0  0 
-
Jason Wregget

- -
110060103050085105100100100100100083100
1.16 (24.3.2002)
1.16 (24.3.2002)
 0  0  29  64  172 
 
now - see the "2" at the very beginning? that''s how many entries there are in the file. the file i''m using is much bigger though.. anyway - i need to know how to make the program skip, or only read the first line a single time. i know how to make it read all that data WITHOUT that first number - i''ve done it and i can read all 3500+ entries - however i don''t know how to make it read the file when that first number is in there... and i can''t remove it because i''m making a little program for another game (eastside hockey manager for those who know it) so, how can i make my input function completely skip that first number? or better yet - read it a single time then go to my format... here''s the code i have now.

Open ("C:\Documents and Settings\Wizzykin\Desktop\EHMTest\players.ehm") For Input As #1
Do While Not EOF(1)
Input #1, Shooting, Playmaking, Stickhandling, Checking, Positioning, Hitting, Skating, Endurance, Penalty, Faceoffs
Input #1, Leadership, Strength, Potential, Consistency, Greed, Fighting, Click, Team, MainPosition, Country, Handed
Input #1, BirthYear, BirthMonth, BirthDay, Salary, ContractLength, DraftYear, DraftRound, Draftedby, Rights
Input #1, Games, Goals, Assist, GWG
Input #1, Games2, Goals2, Assist2, GWG2
Input #1, GoalsR, AssistR, PointsR, NoTradeSwitch, TwoWaySwitch, PlayerTeamOption
Input #1, Status, Rookie, ConsideringOffer, TeamOffering, Timeconsidering, Injury
Input #1, X, X, X, X, X, X, X, X, X, X
Input #1, X, X, X, X, X, X, X, X, X, X
Input #1, X, X, X, X, X, X, X, X, X, X
Input #1, GoalStreak, PointStreak, TotalGP, SuspendedGames, Training, Wght, Hght, StatusinOrg
Input #1, BeststreakGames, BeststreakGWG, BeststreakAssists, BestStreakPoints, BestStreakGoals
Input #1, X
Input #1, PlayerName
Input #1, Performance
Input #1, Drafted
Input #1, Potentialceilings
Input #1, verEHM, verEHM
Input #1, verEHM, verEHM
Input #1, Attitude, AlternatePosition, NHLRights, InjuryProne, OverallDraft

Loop

Close #1
 
see - my code reads with no first number. how can i slightly alter my code so that i can read that first number a single time? as you can see in my input file above (the example i posted) there is no space between entries (-38 0 14 75 70 - is the ending line for the first entry - then it goes right to the next entry and so on) so i can''t just put an input line for it... i hope that''s clear.
Advertisement
just to clarify - my code only works when i use the file with that first number deleted... but i can''t expect anyone who uses it to delete that number any time they want to use it.
Just add an extra Input #1, anyvariable (by the way, you should use FreeFile) before you start the loop.
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
1.) what's FreeFile?

2.) as i said - i can't put an extra "input #1", because the rest of the file doesn't repeat that number. it breaks the entire loop... it's a one time number that never repeats again - and there's no space for it anywhere else...

it's like this

3
Hello
1 2 3 4 5
Goodbye
1 2 3 4 5
What
1 2 3 4 5

-see, there's no room for an extra input...

Hello
1 2 3 4 5

is a single entry, then right below it is the next entry (goodbye)

that 3 isn't included at all in the cycle below it.

[edited by - Wizzy on October 21, 2003 6:12:12 PM]
i may have found out what to do

Do While X <> 1    Input #1, TotalPlayers    X = 1LoopDo While Not EOF(1)Input #1, Shooting, Playmaking, Stickhandling, Checking, Positioning, Hitting, Skating, Endurance, Penalty, FaceoffsInput #1, Leadership, Strength, Potential, Consistency, Greed, Fighting, Click, Team, MainPosition, Country, HandedInput #1, BirthYear, BirthMonth, BirthDay, Salary, ContractLength, DraftYear, DraftRound, Draftedby, RightsInput #1, Games, Goals, Assist, GWGInput #1, Games2, Goals2, Assist2, GWG2Input #1, GoalsR, AssistR, PointsR, NoTradeSwitch, TwoWaySwitch, PlayerTeamOptionInput #1, Status, Rookie, ConsideringOffer, TeamOffering, Timeconsidering, InjuryInput #1, X, X, X, X, X, X, X, X, X, XInput #1, X, X, X, X, X, X, X, X, X, XInput #1, X, X, X, X, X, X, X, X, X, XInput #1, GoalStreak, PointStreak, TotalGP, SuspendedGames, Training, Wght, Hght, StatusinOrgInput #1, BeststreakGames, BeststreakGWG, BeststreakAssists, BestStreakPoints, BestStreakGoalsInput #1, XInput #1, PlayerNameInput #1, PerformanceInput #1, DraftedInput #1, PotentialceilingsInput #1, verEHM, verEHMInput #1, verEHM, verEHMInput #1, Attitude, AlternatePosition, NHLRights, InjuryProne, OverallDraftMSFlexGrid1.Row = MSROWMSFlexGrid1.Col = 0MSFlexGrid1.Text = PlayerNameMSFlexGrid1.Col = MSFlexGrid1.Col + 1MSFlexGrid1.Text = MainPositionMSFlexGrid1.Col = MSFlexGrid1.Col + 1MSFlexGrid1.Text = PotentialMSFlexGrid1.Col = MSFlexGrid1.Col + 1MSFlexGrid1.Text = ConsistencyMSROW = MSROW + 1LoopClose #1 


i just added that first "do while x <> 1"

and it seems that it opens the file, reads that number into the var, then stops the loop - then the next loop continues where the other left off

Why did you put it in a loop if that code is only executed once? Just do it like clum said:

Input #1, TotalPlayers
Do While Not EOF(1)
Loop
Close #1

And yes, you need to close files when you are done using them.

[edited by - JonWoyame on October 21, 2003 7:33:29 PM]
as stated above, read in that one number after opening the file, but before the loop.

FreeFile is a function that will give you an unused file number (right now you have "open blah for input as #1"); instead of that "#1" you can use:
Dim FileNum As IntegerFileNum = FreeFileOpen blah For Input As FileNumInput FileNum, somevar... 


it is a better way to do it, since you shouldn''t always rely on the fact that file "#1" is not being used (i have never seen it used before without having done it myself, but it is just good practice since you may someday need to have many files open at once).
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

This topic is closed to new replies.

Advertisement