User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 20 Mar 2005, 12:53   #1
Demon Dave
Insanity Prawn Boy!
 
Demon Dave's Avatar
 
Join Date: Dec 2001
Location: In a bush where you can't find me
Posts: 2,474
Demon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriend
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.
Demon Dave is offline   Reply With Quote
Unread 20 Mar 2005, 13:23   #2
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow 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! :-/
JetLinus is offline   Reply With Quote
Unread 20 Mar 2005, 13:37   #3
Demon Dave
Insanity Prawn Boy!
 
Demon Dave's Avatar
 
Join Date: Dec 2001
Location: In a bush where you can't find me
Posts: 2,474
Demon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriend
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.
Demon Dave is offline   Reply With Quote
Unread 20 Mar 2005, 13:47   #4
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
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"
Structural Integrity is offline   Reply With Quote
Unread 20 Mar 2005, 13:55   #5
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow 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! :-/
JetLinus is offline   Reply With Quote
Unread 20 Mar 2005, 13:59   #6
Demon Dave
Insanity Prawn Boy!
 
Demon Dave's Avatar
 
Join Date: Dec 2001
Location: In a bush where you can't find me
Posts: 2,474
Demon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriendDemon Dave needs a job and a girlfriend
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.
Demon Dave is offline   Reply With Quote
Unread 20 Mar 2005, 15:23   #7
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow 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! :-/
JetLinus is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 03:01.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018