|
-
May 14th, 2013, 03:14 PM
#1
Thread Starter
New Member
Trying to pull numbers out of a listbox item and convert to a string
The problem I'm having is a bit more complicated than the title of the thread, but I wasn't sure how else to word it. Anyway, here goes...
Here's what I'm attempting to do:
Add a string to a listbox (object)
check the current time
if the listbox item date string is before now() then it will remove the items from the listbox
Check the first X items in the listbox and pull a ticket number from the string (object) in the listbox
Most of it I've got down. the trouble I'm having is trying to pull the ticket number from the listbox object for the first X items in the listbox.
Code:
Private Sub btnIssue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIssue.Click
txtNextTime.Text = Format(TimeClass.getNextTime, "h:mm tt")
lstMain.Items.Add("Ticket " & TicketClass.ticketNumber & ": " & Format(TimeClass.getNextTime, "h:mm tt"))
lstMain. = TicketClass.ticketNumber
TicketClass.ticketNumber = TicketClass.ticketNumber + 1
TimeClass.currentGuests = TimeClass.currentGuests + 1
txtOutstanding.Text = lstMain.Items.Count
'testing stuff
' Dim testtime As Date
'testtime = DateAdd(DateInterval.Minute, TimeClass.minutesPer, (TimeClass.getNextTime.Subtract(TimeSpan.FromMinutes(TimeClass.minutesPer * TimeClass.timesCount))))
TimeClass.originalTime = DateAdd(DateInterval.Minute, TimeClass.minutesPer, (TimeClass.getNextTime.Subtract(TimeSpan.FromMinutes(TimeClass.minutesPer * TimeClass.timesCount))))
If TimeClass.guestCount = TimeClass.guestsPer Then
' txtTest.Text = Format((TimeClass.originalTime.Subtract(TimeSpan.FromMinutes(TimeClass.minutesPer * (TimeClass.timesCount)))), "h:mm tt")
TimeClass.formattedTime = Format(TimeClass.originalTime.Add(TimeSpan.FromMinutes(TimeClass.minutesPer)), "h:mm tt")
Else
TimeClass.formattedTime = Format(TimeClass.originalTime, "h:mm tt")
End If
txtTest3.Text = ""
The listbox item looks like this:
Ticket 1: 3:30 PM
Ticket 2: 3:30 PM
Ticket 3: 3:30 PM
Ticket 4: 3:30 PM
Ticket 5: 3:30 PM
Ticket 6: 3:35 PM
Ticket 7: 3:35 PM
Ticket 8: 3:35 PM
Ticket 9: 3:35 PM
Ticket 10: 3:35 PM
Ticket 11: 3:40 PM
Etc.
Once 3:30 PM comes around Tickets 1 through 5 would be removed from the listbox. What I want to do after they're removed is create a string with the ticket numbers; "1-5". And once 3:35 PM came around the string would update to 6-10 and tickets 6 through 10 would be removed from the listbox. I've got the code down for removing the items from the listbox based on a timer control.
Code:
Private Sub tmrOne_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCount.Tick
Me.Text = FormatDateTime(Now, DateFormat.LongTime) & " " & TimeClass.checkStatus
Dim checkDate As Date = Format(Now, "h:mm tt")
If TimeClass.oldTime <= checkDate Then
TicketClass.removeListItems(TimeClass.oldTime)
txtOutstanding.Text = lstMain.Items.Count
txtNextTime.Text = Format(TimeClass.getNextTime, "h:mm tt")
End If
txtTest2.Text = TimeClass.getNextTime
End Sub
and TicketClass
Code:
Public Class TicketClass
Public Shared Property firstTicket As Integer
Public Shared Property ticketStatus As String
Public Shared Property ticketNumber As Integer
Public Shared Property ticketValue As New Collection
Public Shared Function removeListItems(ByVal str As String) As Boolean
Dim i As Integer
For i = 0 To frmMain.lstMain.Items.Count - 1
If InStr(frmMain.lstMain.Items(i), str) > 0 Then
frmMain.lstMain.Items.RemoveAt(i)
Exit For
End If
Next
Return True
End Function
End Class
So in the timer control I need the PREVIOUS X number of tickets (a set variable based on an option form called guestsPer) to show up as "first ticket" - "last ticket in series".
I've been staring at this for two days trying to work it out and I can't for the life of me get this part done. Once this is done and I get some validation taken care of the program will be done...
Thank you so much in advance!!
-
May 14th, 2013, 08:39 PM
#2
Thread Starter
New Member
Re: Trying to pull numbers out of a listbox item and convert to a string
Ok, going through my code I decided that my previous post may not have had enough information, so here goes:
I add items to a listbox using a button with the following code:
Code:
lstMain.Items.Add("Ticket " & TicketClass.ticketNumber & ": " & Format(TimeClass.getNextTime, "h:mm tt"))
After TimeClass.getNextTime is less than Now() it removes the item from the listbox using:
Code:
Private Sub tmrOne_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCount.Tick
Me.Text = FormatDateTime(Now, DateFormat.LongTime) & " " & TimeClass.checkStatus
Dim checkDate As Date = Format(Now, "h:mm tt")
If TimeClass.oldTime <= checkDate Then
TicketClass.removeListItems(TimeClass.oldTime)
txtOutstanding.Text = lstMain.Items.Count
txtNextTime.Text = Format(TimeClass.getNextTime, "h:mm tt")
End If
End Sub
Which references the following Function located in TicketClass.vb:
Code:
Public Shared Function removeListItems(ByVal str As String) As Boolean
Dim i As Integer
For i = 0 To frmMain.lstMain.Items.Count - 1
If InStr(frmMain.lstMain.Items(i), str) > 0 Then
frmMain.lstMain.Items.RemoveAt(i)
Exit For
End If
Next
Return True
End Function
What I want to do is when the Function removeListItems occurs to capture the TicketClass.ticketNumber from the listbox items removed. It will remove X number of items at a time based on an option the user inputs. I want to take those X number of TicketClass.ticketNumber's and put them into a string like this:
If the items removed had ticket numbers 1 through 5 then the string would display as "1-5". So capture the low and high numbers from the listbox items and put into a string. Grabbing the low and high from an array wouldn't be too hard but where I'm having trouble is grabbing the 1, 2, 3, 4, 5 from the listbox objects.
I'm pretty desperate for help! I've been staring at this for days now and I haven't been able to get it to do what I'm wanting. Thanks!
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
|