» Site Navigation | | | » Advertisement | | | » Recent Threads | | | | | | | | | | | |  |  | [vb2008] Need arrays help |  |
06-01-2008, 10:15 AM
|
#1 (permalink)
| | Underground
revolution is offline
Join Date: Aug 2007 Location: Hiram, Georgia Age: 19 Posts: 557 Rep Power: 4 | [vb2008] Need arrays help I was taught arrays a while back and have forgotten how to use them. I'm making a program that I plan on releasing here. The point of the program is to select what time you work, AM or PM, what time you get off work, AM or PM. It will then calculate your total hours (the program is for the entire week, not just one day) as well as input how much you make per hour. Will also create a text document, or append to one, and add to it your schedule for that week, the total hours, and how much money you should make, give or take a bit due to certain tax equations.
My problem is all the coding for each day of the week. I've only done Sunday and I'm already over 150 lines of code and I haven't even done time intervals yet, only whole hours (meaning I need to do 15, 30, 45 minutes and I only have set times for hours 1-12). I could simply copy and paste, replacing "sun" with "mon", "tue", etc, but I'm looking to optimize the coding.
There are 2 combo boxes for each day, and with the addition of the minute intervals, there will be 4. I need have an array, and I'm thinking also a For Next statement (i'm terrible with those) that will run through the days to add their amounts to the total hours.
If whoever's helping needs more information, let me know.
__________________ Trades Completed: Yummy, Kismet, Konekokoi, xRuinationx | |
| |  |  | |  |
06-04-2008, 12:16 PM
|
#2 (permalink)
| | Underground
rcadble is offline
Join Date: Sep 2006 Posts: 217 Rep Power: 6 | I just spent a decent amount of time working on this -- I was able to create my own program with 7 pairs of inputboxes (sunday start time, sunday stop time, etc). I made it so on form load, these comboboxes are populated with times in 15 minute intervals(though this can be changed by you). I then wrote a function to calculate the total number of minutes working throughout the week. Code: Public Class TimeDifferenceFinder
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i As Integer = 1 To 7
LoadTimes(DirectCast(Me.Controls.Find("time" & i & "a", True)(0), ComboBox))
LoadTimes(DirectCast(Me.Controls.Find("time" & i & "b", True)(0), ComboBox))
Next
End Sub
Private Sub LoadTimes(ByRef cmbBox As ComboBox)
For amhour As Integer = 1 To 11
For amminute As Integer = 0 To 45 Step 15
If amminute = 0 Then
cmbBox.Items.Add(amhour & ":00 AM")
Else
cmbBox.Items.Add(amhour & ":" & amminute & " AM")
End If
Next
Next
For pmminute As Integer = 0 To 45 Step 15
If pmminute = 0 Then
cmbBox.Items.Add("12:00 PM")
Else
cmbBox.Items.Add("12:" & pmminute & " PM")
End If
Next
For pmhour As Integer = 1 To 11
For pmminute As Integer = 0 To 45 Step 15
If pmminute = 0 Then
cmbBox.Items.Add(pmhour & ":00 PM")
Else
cmbBox.Items.Add(pmhour & ":" & pmminute & " PM")
End If
Next
Next
For amminute As Integer = 0 To 45 Step 15
If amminute = 0 Then
cmbBox.Items.Add("12:00 AM")
Else
cmbBox.Items.Add("12:" & amminute & " AM")
End If
Next
End Sub
Private Function CalculateMins() As Integer
Dim totalMins As Integer
For i As Integer = 1 To 7
Dim timeString As String = CalculateDifference(DirectCast(Me.Controls.Find("time" & i & "a", True)(0), ComboBox), DirectCast(Me.Controls.Find("time" & i & "b", True)(0), ComboBox))
If (timeString.Substring(0, InStr(timeString, ":") - 1) * 60) < 0 Then
totalMins += (((Val(timeString.Substring(0, InStr(timeString, ":") - 1) * 60) - timeString.Substring(InStr(timeString, ":"), 2)) + 1440))
Else
totalMins += (timeString.Substring(0, InStr(timeString, ":") - 1) * 60) + timeString.Substring(InStr(timeString, ":"), 2)
End If
Next
Return totalMins
End Function
Private Function CalculateDifference(ByVal first As ComboBox, ByVal second As ComboBox) As String
Dim firstTime As String = first.Text
Dim secondTime As String = second.Text
firstTime = Format(Date.Parse(firstTime), "HH:mm")
secondTime = Format(Date.Parse(secondTime), "HH:mm")
Dim T1 As Object
T1 = New TimeSpan(firstTime.Substring(0, InStr(firstTime, ":") - 1), firstTime.Substring(InStr(firstTime, ":"), 2), 0)
Dim T2 As Object
T2 = New TimeSpan(secondTime.Substring(0, InStr(secondTime, ":") - 1), secondTime.Substring(InStr(secondTime, ":"), 2), 0)
Return T2.Subtract(T1).ToString()
End Function
Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click
MsgBox(CalculateMins)
End Sub
End Class Comboboxes are named time1a, time1b through time7a, time7b.
__________________
Omnipresent Autobuyer, the best free autobuyer.
Version 1.2
Always around, always present.
| |
| |  |
06-04-2008, 12:34 PM
|
#3 (permalink)
| | Underground
revolution is offline
Join Date: Aug 2007 Location: Hiram, Georgia Age: 19 Posts: 557 Rep Power: 4 | I'll have to test it out when I get home. My code was a lot longer than this, but that's because after trying the program, I wanted to make it so you could do like 3 PM in and 7 AM out and get only 4 hours. Went through and got everything working like it should along with several error messages such as negative hours (in at 7 pm, out at 3pm for example), 12 or 12+ hour shifts.
__________________ Trades Completed: Yummy, Kismet, Konekokoi, xRuinationx | |
| |
06-04-2008, 12:36 PM
|
#4 (permalink)
| | Underground
rcadble is offline
Join Date: Sep 2006 Posts: 217 Rep Power: 6 | Quote:
Originally Posted by revolution I'll have to test it out when I get home. My code was a lot longer than this, but that's because after trying the program, I wanted to make it so you could do like 3 PM in and 7 AM out and get only 4 hours. Went through and got everything working like it should along with several error messages such as negative hours (in at 7 pm, out at 3pm for example), 12 or 12+ hour shifts. | If you did 9:00 PM to 3:00 AM this will return 360 (6 hours = 360 minutes). So if you have the night shift, this'll still work.
__________________
Omnipresent Autobuyer, the best free autobuyer.
Version 1.2
Always around, always present.
| |
| |  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |