Go Back   Gaming Gutter > Non-Gaming > Programming


Programming - All general programming discussion in here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post This account has been...
Today 11:49 AM
Last post by Zombieshot
Today 12:09 PM
4 Replies, 5 Views
Go to first new post I kissed a Grarrl and I...
Today 11:57 AM
by qtpie
Last post by Snakebite
Today 12:09 PM
3 Replies, 4 Views
Go to first new post Fastest Way To Get...
Today 11:20 AM
by Sicklez
Last post by Zombieshot
Today 12:06 PM
12 Replies, 13 Views
Go to first new post Irritating computer...
Today 09:48 AM
Last post by xBiscuit
Today 12:06 PM
18 Replies, 19 Views
Go to first new post Programming Contest!
08-22-2008 08:32 AM
by |G3|
Last post by lain
Today 12:06 PM
22 Replies, 23 Views
Reply
 
LinkBack Thread Tools Display Modes

 [vb2008] Need arrays help
Old 06-01-2008, 10:15 AM   #1 (permalink)
revolution revolution is offline Gender Male
Underground
 
revolution's Avatar
 
revolution is offline
Join Date: Aug 2007
Location: Hiram, Georgia
Age: 19
Posts: 557
iTrader: 2 / 100%
revolution Is Recognizable
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




  Reply With Quote

 
Old 06-04-2008, 12:16 PM   #2 (permalink)
rcadble rcadble is offline Gender Male
Underground
 
rcadble is offline
Join Date: Sep 2006
Posts: 217
iTrader: 0 / 0%
rcadble Is Recognizable
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.
  Reply With Quote

 
Old 06-04-2008, 12:34 PM   #3 (permalink)
revolution revolution is offline Gender Male
Underground
 
revolution's Avatar
 
revolution is offline
Join Date: Aug 2007
Location: Hiram, Georgia
Age: 19
Posts: 557
iTrader: 2 / 100%
revolution Is Recognizable
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




  Reply With Quote

 
Old 06-04-2008, 12:36 PM   #4 (permalink)
rcadble rcadble is offline Gender Male
Underground
 
rcadble is offline
Join Date: Sep 2006
Posts: 217
iTrader: 0 / 0%
rcadble Is Recognizable
Rep Power: 6
Quote:
Originally Posted by revolution View Post
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.
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -7. The time now is 12:10 PM.


vBulletin skin developed by: eXtremepixels
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.17126107 seconds (100.00% PHP - 0% MySQL) with 19 queries