|
-
Feb 8th, 2000, 04:14 AM
#1
Thread Starter
New Member
When I read in my data file I want to read in each character separately and after the return key to move to the next line in my data file. Can I use Input$(i,#filename)
and increment it i=i+1 or do I have to use another function.
Thanks
Coco
-
Feb 8th, 2000, 04:16 AM
#2
Why would you want to read in a file, 1 Character at a time? This would be very slow and Teadious.
If you want to do something to the Data 1 Character at a Time, load the whole file into a String First, then manipulate it, it'll be much quicker and easier.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
-
Feb 8th, 2000, 05:27 AM
#3
Thread Starter
New Member
Thanks
I am actualy trying to read a 13 hand of cards and total up the score.
The Data looks like this
A231KQQJAK513
2944336AQ7118
1878KQJJ95798
This is my code so far
Private Sub PassEol_Click()
Dim ch As String * 1
Dim Cardvalue
Dim EOL
Dim Cardcounter
Dim i As Integer
Open "c:\VB\a2.txt" For Input As #1
EOL = Chr(10)
Cardvalue = 0
Cardcounter = 0
i = 1
Picture1.Cls
Do Until EOF(1) Or (ch = EOL)
ch = Input$(1, #1)
Select Case ch
Case "A"
Cardvalue = 4
Case "K"
Cardvalue = 3
Case "Q"
Cardvalue = 2
Case "J"
Cardvalue = 1
Case Else
Cardvalue = 0
End Select
Cardcounter = Cardcounter + Cardvalue
Picture1.Print ch; ""
Loop
Picture1.Print "Score for Hand"; i; "is"; Cardcounter; ""
Picture1.Print
Cardcounter = 0
ch = 0
Cardvalue = 0
End Sub
What I am missing is a loop to get it to read the next line of the data file.
I need it read through all the whole data file and give me the value of each hand. The code above will only work for line.
When I have tried to do anoher do loop I have been unable to increment it to the next line.
Thanks
Coco
-
Feb 8th, 2000, 05:45 AM
#4
Try:
Code:
Private Sub Command1_Click()
Dim iFile As Integer
Dim sHand As String
iFile = FreeFile
Open "C:\Hand.txt" For Input As iFile
While Not EOF(iFile)
Line Input #iFile, sHand
Debug.Print "Hand: " & sHand, "Scores: " & TallyScore(sHand)
Wend
Close iFile
End Sub
Private Function TallyScore(ByVal sCards As String) As Integer
Dim iScore As Integer
While Len(sCards)
If Not IsNumeric(Left$(sCards, 1)) Then
Select Case Left$(sCards, 1)
Case "A"
iScore = iScore + 4
Case "K"
iScore = iScore + 3
Case "Q"
iScore = iScore + 2
Case "J"
iScore = iScore + 1
End Select
End If
sCards = Mid$(sCards, 2)
Wend
TallyScore = iScore
End Function
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
-
Feb 8th, 2000, 06:06 AM
#5
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|