-
Jul 23rd, 2013, 04:00 AM
#1
Thread Starter
Lively Member
sum numbers in a text file
Hi,
I'm trying to add the numbers in a text file and show the result on a label.
Public Function GetInitialTime(ByVal TotalTime As Integer) As String
Dim fileContents() As String = IO.File.ReadAllLines("\My Documents\my_Counter.txt")
Dim sum As Long = (From item In fileContents Select CLng(item)).Sum
TotalTime = sum
Tot_Time = TotalTime
Sec = TotalTime Mod 60
Min = ((TotalTime - Sec) / 60) Mod 60
Hrs = ((TotalTime - (Sec + (Min * 60))) / 3600)
Return Format(Hrs, "000000") & ":" & Format(Min, "00") & ":" & Format(Sec, "00")
End Function
For the mobile phone (win6.5) development it comes with an error:
"ReadAllLines" is not a member of "System.IO.File"
But if I create a development for a PC application and use the same code, it works fine.
Can anybody help me?
Or has anybody got another idea of how to add all lines (there are only numbers on each line) in my text file?
Thanks.
-
Jul 23rd, 2013, 08:56 AM
#2
Thread Starter
Lively Member
Re: sum numbers in a text file
If you're targetting Windows Mobile, you'll be using the compact framework. ReadAllLines is not supported in the compact framework.
So, I've found out that my approach is a dead end.
can anybody help me sum all the numbers in my text file somehow else?
thanks.
-
Jul 24th, 2013, 01:31 AM
#3
Fanatic Member
Re: sum numbers in a text file
You can create your own function to read the entire file, have a look at here
or use:
Code:
Private Function ReadAllLines() As String
Dim data As String = String.Empty
Try
Dim sr As New System.IO.StreamReader("\My Documents\my_Counter.txt")
data = sr.ReadToEnd()
sr.Close()
Catch generatedExceptionName As Exception
Throw
End Try
Return data
End Function
and split the ReadAllLines() result on separator vbnewline
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
|