|
20 Mar 2005, 12:53
|
#1
|
Insanity Prawn Boy!
Join Date: Dec 2001
Location: In a bush where you can't find me
Posts: 2,474
|
VB Help
i need some help with a VB program i'm writing.
what i've got is a txt file with a list of names, times and scores in the form of
"Name","Time",Score
What i'd like to do is be able to press a button, and a msgbox pop up telling me what the average score is. I know it's a pretty simple problem, but i just can't for the life of me figure it out
Help me please!
__________________
They shall not grow old, as we who are left grow old:
Age shall not weary them, nor the years condemn.
At the going down of the sun and in the morning
We shall remember them.
|
|
|
20 Mar 2005, 13:23
|
#2
|
Friendly geek of GD :-/
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
|
Re: VB Help
K, I can't be arsed writing this in the compiler, but it should go like this:
Code:
Dim i as long, j as long
Dim FileContent as String
Dim FileNum as Long
Dim Lines() As String
Dim Items() As String
FileNum = FreeFile()
' If you use App.Path, remember it returns something like "C:\" on roots, but else "C:\temp"
Open YourPathNameHere For Binary Access Read As FileNum
Get FileNum, 1, FileContent
Close FileNum
'Now, split to lines
Lines() = Split(FileContent, vbCRLF)
For i = 0 to UBound(Lines(), 1)
Lines(i) = Trim$(Lines(i)) 'remove spaces
If Len Lines(i)) > 0 Then ' Ignore empty lines
Items() = Split(Lines(i), ",")
For j = 0 to UBound(Items())
Items(j) = Trim$(Items(j)) 'remove leading / trailing spaces again
'Now you've got everything you need...
' Just fill your array with it...
'I.e. MyArrayType(i).Item(j) = Item(j)
Next j
End If
Next i
__________________
[ »] Entropy increases! :-/
|
|
|
20 Mar 2005, 13:37
|
#3
|
Insanity Prawn Boy!
Join Date: Dec 2001
Location: In a bush where you can't find me
Posts: 2,474
|
Re: VB Help
Quote:
Originally Posted by JetLinus
blah
|
blimey, i had no idea it was going to be that complicated
__________________
They shall not grow old, as we who are left grow old:
Age shall not weary them, nor the years condemn.
At the going down of the sun and in the morning
We shall remember them.
|
|
|
20 Mar 2005, 13:47
|
#4
|
Rawr rawr
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
|
Re: VB Help
Quote:
Originally Posted by Demon Dave
blimey, i had no idea it was going to be that complicated
|
Parsing in general is quite complicated to write in low-level languages that are not equiped with standard parsing functions.
But you could use PHP and regular expressions if you think that's too much code.
__________________
"Yay"
|
|
|
20 Mar 2005, 13:55
|
#5
|
Friendly geek of GD :-/
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
|
Re: VB Help
I forgot to include the actual "calculation" code, but will do so shortly...
It's not complicated at all. Split() is a nice function, and I personally use Trim$() quite a lot. Also you should know what UBound() does!
__________________
[ »] Entropy increases! :-/
|
|
|
20 Mar 2005, 13:59
|
#6
|
Insanity Prawn Boy!
Join Date: Dec 2001
Location: In a bush where you can't find me
Posts: 2,474
|
Re: VB Help
just a quick one, If Len Lines(i)) > 0 Then ' Ignore empty lines comes up as a syntax error
EDIT: Never mind, i think i'll just leave it for now. Thanks for the help anyway
__________________
They shall not grow old, as we who are left grow old:
Age shall not weary them, nor the years condemn.
At the going down of the sun and in the morning
We shall remember them.
|
|
|
20 Mar 2005, 15:23
|
#7
|
Friendly geek of GD :-/
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
|
Re: VB Help
Of course, it should be Len(Lines(i))...
Ok, apart from that, you're very close to your solution already...
__________________
[ »] Entropy increases! :-/
|
|
|
|
All times are GMT +1. The time now is 23:43.
| |