Reading a label as Time

grags

Active member
Joined
Mar 26, 2005
Messages
26
Programming Experience
Beginner
Image.JPG


Hi, can someone PLEASE!! tell me how I can add up the times stored in them labels. I've tried everything, i've spent all day on it searching high and low all over the internet for some sort of code that can read the labels as time and then total it all up.

The labels are stored into a class array 'cvlTime(3, 20)'

So basically what im after is something like this...

VB.NET:
        Dim ldtAgentTime, ldtSecretAgentTime, ldt00AgentTime As DateTime

        For lviY = 1 To 20
            ldtAgentTime += cvlTime(1, lviY).ToDate
            ldtSecretAgentTime += cvlTime(2, lviY).ToDate
            ldt00AgentTime += cvlTime(3, lviY).ToDate
        Next

Obviously the code above is wrong but i'm trying to give the best idea possible of what it is i'm trying to accomplish.

I'm using VB.Net 2003


Note to moderators: If i've posted in the wrong forum please accept my apologies, and could it be moved to the correct forum. Thankyou.


Thanks for looking :)
Grags
 
Why would you need to read anything from the Labels in the first place? The user can't input anything into a Label, so you must be getting the data from somewhere to display in the Labels. You should be adding up THAT data, not converting the Text of a Label back to a value that you already had in the first place.
 
Thankyou for your reply.

The information is downloaded from a HTML table(in a huge string manipulation program) as a string and then stored. Even when i'm inputing the data they're still inputed as strings, so I still have the same problem.

The huge string manipulation program.

VB.NET:
        Dim web As New Net.WebClient
        Dim lviLevel, lvicount, lvimember, lviAgent As Integer
        Dim lviLoop1, lviLoop2, lviloop3, lviloop4, lviloop5, lviloop6, lviloop7, lviloop8 As Integer
        Dim strLevel, strName, strtime, strscore, strMember(2000), lvsLevel(20) As String
        Dim lvbOK As Boolean

        FileOpen(2, gfPath() + "Members.txt", OpenMode.Output)
 
        For lviLevel = 1 To 20
            Me.Text = "Updating " + lvsLevel(lviLevel)
            FileClose(1)
            FileOpen(1, gfPath() + "level" + Trim(Str(lviLevel)) + ".txt", OpenMode.Output)
            strLevel = System.Text.Encoding.Default.GetString(web.DownloadData("[URL]http://www.the-elite.net/GE/stage[/URL]" + Trim(Str(lviLevel)) + ".htm"))
            For lviLoop1 = 1 To Len(strLevel)
                If Mid(strLevel, lviLoop1, 8) = "</table>" Then
                    Exit For
                End If
                If Mid(strLevel, lviLoop1, 4) = "<td>" Then
                    For lviLoop2 = lviLoop1 + 4 To Len(strLevel)
                        If Mid(strLevel, lviLoop2, 1) = ">" Then
                            For lviloop3 = lviLoop2 + 1 To Len(strLevel)
                                If Mid(strLevel, lviloop3, 1) = "<" Then
                                    'We have the name!!! = strName
                                    strName = Mid(strLevel, lviLoop2 + 1, lvicount)
                                    lvicount = 0
                                    For lviloop4 = lviLoop2 + 1 To Len(strLevel)
                                        If Mid(strLevel, lviloop4, 4) = "<td>" Then
                                            For lviloop5 = lviloop4 + 4 To Len(strLevel)
                                                If Mid(strLevel, lviloop5, 1) = "<" Then
                                                    'We have the time!!! = strTime
                                                    strtime = Trim(Mid(strLevel, lviloop4 + 4, lvicount - 2))
                                                    lvicount = 0
                                                    For lviloop6 = lviloop5 To Len(strLevel)
                                                        If Mid(strLevel, lviloop6, 1) = ">" Then
                                                            For lviloop7 = lviloop6 + 1 To Len(strLevel)
                                                                If Mid(strLevel, lviloop7, 1) = "<" Then
                                                                    'We have the score!!! = strScore
                                                                    strscore = Mid(strLevel, lviloop6 + 1, lvicount)
                                                                    lvicount = 0
                                                                    lviLoop1 = lviloop7
                                                                    lviAgent += 1
                                                                    If lviAgent = 4 Then
                                                                        lviAgent = 1
                                                                    End If
                                                                    Write(1, strName, lviAgent, strtime, strscore)
                                                                    If lviLevel = 1 Then
                                                                        lvbOK = True
                                                                        For lviloop8 = 1 To 2000
                                                                            If strMember(lviloop8) = strName Then
                                                                                lvbOK = False
                                                                                Exit For
                                                                            End If
                                                                        Next
                                                                        If lvbOK Then
                                                                            lvimember += 1
                                                                            strMember(lvimember) = strName
                                                                            Write(2, strName)
                                                                        End If
                                                                    End If
                                                                    Exit For
                                                                End If
                                                                lvicount += 1
                                                            Next
                                                            Exit For
                                                        End If
                                                    Next
                                                    Exit For
                                                End If
                                                lvicount += 1
                                            Next
                                            Exit For
                                        End If
                                    Next
                                    Exit For
                                End If
                                lvicount += 1
                            Next
                            Exit For
                        End If
                    Next
                End If
            Next
            psbTotal.Increment(4)
        Next
        FileClose()

As you can see I still have the same problem of converting the Strings to a TimeSpan. And yes... I know the code is messy, but it works :)

Feal free to contact me on AIM.
 
Last edited:
As I always say, the first thing you should be doing is reading the relevant documentation. You want to create TimeSpan objects? You read the documentation for the TimeSpan structure. The member listing describes Parse method like so:
Constructs a new TimeSpan object from a time interval specified in a string.
and the TryParse method like so:
Constructs a new TimeSpan object from a time interval specified in a string. Parameters specify the time interval and the variable where the new TimeSpan object is returned.
 
I appreciate your trying to help, but I just don't undertsand?

It's bugging the life out of me. I've tried everything, and your comment doesn't make any sense to me. As much as i've read it over and over to try to gain some understanding it's just not clear to me.

I understand what im asking is probably very simple and straight forward to most people. But my knowledge of .net isn't great.

As I always say, the first thing you should be doing is reading the relevant documentation
I would never post before spending hours and hours trying to figure the problem out for myself. I've spent countless hours before and after this thread searching high and low for the slightest hint. With no success.
 
Last edited:
Here are some examples:
VB.NET:
Dim ts1 As TimeSpan = TimeSpan.Parse("0:53")
Dim ts2 As TimeSpan = TimeSpan.Parse("0:59")
Dim ts As TimeSpan = ts1.Add(ts2)
Here's the online doc reference for TimeSpan Structure if you're interested, but I usually use the local version myself (just press F1 key, or use Help menu) because it's much faster to read and navigate.
 
I told you that you had to use a TimeSpan and I told you that had to use the Parse and/or TryParse methods. The documentation for the Parse method has a big code example that shows you how to use it and how it works. I see so many people posting that they've spent so much time searching for information but they obviously haven't looked in the one place they should have from the start: the MSDN documentation for the type they're using.
 
Back
Top