Solved

Calculate values from a text file

Posted on 2000-04-17
8
171 Views
Last Modified: 2010-05-02
I am working on a program that keeps track of how long each user is using Internet. I use this information to make a text file with important info. The file contains date, start- and stop time, total online time, price, and username.

The information in the text file should help me to calculate the telephone bill and make each person pay his or her percentage of the price.

Example, text file:
2000-04-16 18:31:11 18:31:31 00:00:20 0,115 0,44 User1
2000-04-16 20:59:08 20:59:40 00:00:32 0,115 0,46 User2
2000-04-16 21:18:04 21:18:33 00:00:29 0,115 0,46 User3
2000-04-17 12:16:32 12:16:42 00:00:10 0,23 0,42 User1
2000-04-17 17:33:33 17:33:45 00:00:12 0,23 0,42 User2
2000-04-17 17:34:40 17:34:55 00:00:15 0,23 0,43 User3
2000-04-17 17:49:22 17:50:17 00:00:55 0,23 0,50 User2

1. I want all the numbers in the last but one column to be summed.
2. Then I want all the user prices to be summed.
3. Then usersum/totalsum *100
4. All this should be presented a lucid way.

This was very difficult to explain but I hope you can understand what I want.
0
Comment
Question by:Ecmil
8 Comments
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
are you allowed to use a database to store this information? it could make your life much easier.
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
So, where is the problem?? You don't know how to read file, you don't know how to design interface, or what?
0
 
LVL 7

Expert Comment

by:Joe_Griffith
Comment Utility
Your data is a little confusing.  Could you break one of the lines down and identify the values in each field?  Summing the price also seems like an odd thing to do.  Is it really the price or is it cost that you want added up?
0
 
LVL 2

Accepted Solution

by:
Sage020999 earned 250 total points
Comment Utility
use the split command to break all your data into an array.  You can then sum your data with a conditional loop.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
There is a column that I don't know what it is (first line)

date = 2000-04-16
start = 18:31:11
stop = 18:31:31
total online time = 00:00:20
price = 0,115
? = 0,44
username = User1
0
 
LVL 2

Expert Comment

by:burntout
Comment Utility
You should make your own type
TYPE MyType
  Date as Date
  Start as Date
  Stop as Date
  Total as Long
  Price as Long
  User as String * 20
End Type

This will make it much easier to read and write to your text file.
Open the text file for random access.

or do as azrasound sugested as use a database.
0
 
LVL 2

Expert Comment

by:gerrymcd
Comment Utility
i agree with burnout make you own type first store you inputed values into each member of this type.

each line will be an array index of a user?  so make an array of types fro each line in your text file.

you need to explain your text file better!
0
 

Author Comment

by:Ecmil
Comment Utility
Thanks Sage, your suggestion worked. At first I wanted to avoid using a database because I thought VB could calculate the textfile easy, but apparently not. So I followed AzraSound suggestion and stored the info. in a database.

I know how to read the text file. I try explain the text file again, for those who wanted
2000-04-16 ' the date when the program started
18:31:11 ' the time when program started
18:31:31 ' the time when program ended                        
00:00:20 ' how long the program has been running            
0,115 ' the telephone fee (important to see if high or low fee) - you can leave this bit out
0,44 ' the price for 20 sec (time * fee + the call fee (0,40)) already calculated in VB
User1 ' the person how used the program for 20 sec.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now