Click here to Skip to main content
15,914,406 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Set time out for sending mail with attachment Pin
Luc Pattyn23-May-09 5:11
sitebuilderLuc Pattyn23-May-09 5:11 
QuestionNewbie looking for direction Pin
mxrobuk22-May-09 8:58
mxrobuk22-May-09 8:58 
AnswerRe: Newbie looking for direction Pin
0x3c022-May-09 9:18
0x3c022-May-09 9:18 
AnswerRe: Newbie looking for direction Pin
Mycroft Holmes22-May-09 22:02
professionalMycroft Holmes22-May-09 22:02 
GeneralRe: Newbie looking for direction Pin
TheMrProgrammer23-May-09 6:31
TheMrProgrammer23-May-09 6:31 
GeneralRe: Newbie looking for direction Pin
Mycroft Holmes23-May-09 14:00
professionalMycroft Holmes23-May-09 14:00 
GeneralRe: Newbie looking for direction Pin
Zaegra24-May-09 4:24
Zaegra24-May-09 4:24 
AnswerRe: Newbie looking for direction Pin
LCARS x3225-May-09 14:00
LCARS x3225-May-09 14:00 
Wow. Those were really useful posts... Way to help out. BTW: VB.NET can do ANYTHING that C# can do. Anything. Mad | :mad:

The easiest way to do what you want is with a collection. I would also get rid of the timer and just use Now.timeOfDay to get the current time. Heres an example:

The example below needs the following controls on it's form:

Control            Name
=================================
TextBox            txtID
Button             btnAdd
Button             btnSave
ListBox            lstResults
=================================


'Begin Code:
'============================================================================================================
Option Explicit On
Option Strict On

Public Class Form1

    'Create a new structure to make saving our data easy.
    Private Structure Competitor
        Dim ID As String
        Dim FinishTime As DateTime
    End Structure

    'Create a collection to hold all of the competitors.
    'I like using collections instead of arrays because 
    'they're easy to resize
    Dim myCompetitors As New Collection

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        'Create a competitor variable to temporarily hold the
        'competitor we are adding.
        Dim currentCompetitor As New Competitor

        'Set their ID to the the text of the textbox
        currentCompetitor.ID = txtID.Text
        'Set the finish time to the current date/time
        currentCompetitor.FinishTime = Now

        'Add the competitor to the collection
        myCompetitors.Add(currentCompetitor)

        'Update the list of competitors/times
        UpdateResults()

        'Reset the textbox and give it focus 
        'so we don't have to click on anything
        'to enter the next competitor.
        txtID.Text = ""
        txtID.Focus()

    End Sub

    Private Sub UpdateResults()
        'This sub updates the listbox with all of 
        'the competitors in the collection.

        'Clear the contents of the listbox
        lstResults.Items.Clear()

        'Loop through the collection, adding the competitors information
        'to the listbox.
        For Each currentCompetitor As Competitor In myCompetitors

            'add the competitor's ID followed by the date and time of their finish.
            'if you want to show just their time, you would 
            'change currentCompetitor.FinishTime.ToString to currentCompetitor.FinishTime.timeOfDay.ToString
            lstResults.Items.Add("ID: " & currentCompetitor.ID.ToString & " Finish Time: " & currentCompetitor.FinishTime.ToString)

        Next

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'Create a new SaveFileDialog to ask the user where to save the file.
        'You could also create a String variable if you want to hard-code the 
        'location of the file.
        Dim myFile As New SaveFileDialog
        'Create a DialogResult to tell us which button on the SaveFileDialog they clicked.
        Dim fileResult As DialogResult

        'Set the SaveFileDialog to save the file as a .txt file.
        myFile.Filter = "[*.txt] Text File|*.txt"

        'Show the dialog and set the fileResult to the button they click
        fileResult = myFile.ShowDialog

        'If they clicked on the OK button, then...
        If fileResult = Windows.Forms.DialogResult.OK Then

            '...save the file!
            FileOpen(1, myFile.FileName, OpenMode.Output)

            'loop through the collection, saving a new line to the file
            'as we go:
            For Each currentCompetitor As Competitor In myCompetitors
                PrintLine(1, "ID: " & currentCompetitor.ID.ToString & " Finish Time: " & currentCompetitor.FinishTime.ToString)
            Next

            'We're done saving, so close the file!
            FileClose(1)
        End If

    End Sub
End Class

'===========================================================================================================
'End Code


I hope that's what you're looking for.

-Ray
QuestionKerberos Pin
Fahad Sadah22-May-09 6:15
Fahad Sadah22-May-09 6:15 
AnswerRe: Kerberos Pin
Dave Kreskowiak22-May-09 7:16
mveDave Kreskowiak22-May-09 7:16 
AnswerRe: Kerberos Pin
0x3c022-May-09 9:19
0x3c022-May-09 9:19 
QuestionAccessing Outlook custom task form data Pin
penguin500022-May-09 0:16
penguin500022-May-09 0:16 
AnswerRe: Accessing Outlook custom task form data Pin
penguin500022-May-09 0:23
penguin500022-May-09 0:23 
QuestionError on H323 Voice chat Pin
Thayhor21-May-09 20:21
Thayhor21-May-09 20:21 
AnswerRe: Error on H323 Voice chat Pin
Mycroft Holmes21-May-09 22:12
professionalMycroft Holmes21-May-09 22:12 
QuestionScan and verify an image in database. Pin
Gagan.2021-May-09 19:54
Gagan.2021-May-09 19:54 
AnswerRe: Scan and verify an image in database. Pin
0x3c021-May-09 21:33
0x3c021-May-09 21:33 
GeneralRe: Scan and verify an image in database. Pin
Gagan.2021-May-09 23:21
Gagan.2021-May-09 23:21 
GeneralRe: Scan and verify an image in database. Pin
Christian Graus22-May-09 2:50
protectorChristian Graus22-May-09 2:50 
GeneralRe: Scan and verify an image in database. Pin
Mycroft Holmes22-May-09 3:04
professionalMycroft Holmes22-May-09 3:04 
GeneralRe: Scan and verify an image in database. Pin
Dave Kreskowiak22-May-09 3:45
mveDave Kreskowiak22-May-09 3:45 
Questionautomatic key generation for database Pin
hrishiS21-May-09 19:51
hrishiS21-May-09 19:51 
AnswerRe: automatic key generation for database Pin
Mycroft Holmes21-May-09 22:19
professionalMycroft Holmes21-May-09 22:19 
GeneralRe: automatic key generation for database Pin
hrishiS21-May-09 22:29
hrishiS21-May-09 22:29 
GeneralRe: automatic key generation for database Pin
Mycroft Holmes21-May-09 23:40
professionalMycroft Holmes21-May-09 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.