Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Calculate values from a text file

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.
1 Solution
are you allowed to use a database to store this information? it could make your life much easier.
So, where is the problem?? You don't know how to read file, you don't know how to design interface, or what?
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?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

use the split command to break all your data into an array.  You can then sum your data with a conditional loop.
Éric MoreauSenior .Net ConsultantCommented:
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
You should make your own type
  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.
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!
EcmilAuthor Commented:
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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now