14 Replies - 2376 Views - Last Post: 14 March 2013 - 06:51 PM Rate Topic: -----

#1 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

How to compare 6 combo box with different values?

Posted 07 March 2013 - 04:57 PM

hi!!! I am very new to visual basic and our instructor ask us to do an application about Weekly Hours Worked..

this is the instruction:
Create an application that will calculate the total hours worked of an employee. The application must ask the user to enter the time in and out per day. Regular working hours is from 8:00am to 12:00nn/pm and from 1:00pm to 5pm.
Example:
Day Time In Time Out Hours Worked
1 8:00am 5:00pm 8
2 8:30am 5:30pm 7.5

Total Hours Worked: 15.5

As you can see above, there are only 2 days, but we should make it a 6 days..
there are 30 combo boxes to made...
2 comboboxes for the hours of time in and time out
2 comboboxes for minutes of time in and time out
2 comboboxes for am/pm of time in and time out..
and so as 6 days.. is 30 combo boxes..

all i did is to call every combo boxes for a day and to a label in hours worked...
and there the condition goes...
the variables hours, minutes and day are already declared in general..
if (hours >= 8 and minutes = 00 and day = "am") and (hours <= 12 and minutes = 00 and day = "pm") then
'calculation goes here...i am finding a way to count the hours.. base on the range.
end if

i tried to execute it using the condition above but it says syntax error!!!
is there any wrong with my condition?
well, i tried to do everything to get only the range needed... beyond the range is not counted.. and so i planned also to do count()? ive searched it in the goole...

any help will be really appreciated... thanks.. :)

Is This A Good Question/Topic? 0
  • +

Replies To: How to compare 6 combo box with different values?

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to compare 6 combo box with different values?

Posted 07 March 2013 - 08:22 PM

I would suggest that you talk with your instructor. For a start, combo boxes aren't the way to go here in my opinion.
Was This Post Helpful? 0
  • +
  • -

#3 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to compare 6 combo box with different values?

Posted 07 March 2013 - 10:44 PM

View PostBobRodes, on 07 March 2013 - 08:22 PM, said:

I would suggest that you talk with your instructor. For a start, combo boxes aren't the way to go here in my opinion.


what can you suggest to me then? our instructor told us to at least use a combo box..for the hours, minutes and am/pm... so lets assume that it has only 3 combo boxes... still using the same condition.. why wouldnt it function the way i like it to be?
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to compare 6 combo box with different values?

Posted 08 March 2013 - 10:38 PM

Oh, I see. Use Comboboxes but set the style property to simple dropdown. Ok, you aren't giving us enough to be able to tell you what's wrong. Syntax error where?
Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: How to compare 6 combo box with different values?

Posted 09 March 2013 - 03:08 AM

One function that might be worth you reading up on is the DateDiff function, which will allow you to calculate the difference between two DateTime values.

You may find it useful.
Was This Post Helpful? 0
  • +
  • -

#6 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: How to compare 6 combo box with different values?

Posted 09 March 2013 - 03:19 AM

simple response abou the 'syntax errors' with the information given and no vb6 to test on...

make sure hours and minutes are pulling the actual numerical values from the combo boxes, not the string values..

and it should work logically, but i'm not sure if vb6 will want you to use the (() and ()) format.. break your code down into a bit more nesting and try it agin, see if you can narrow down exactly where the error is coming from, then cram it back onto one line.

I have to side with the others though, read the chapter you're working from again and see what they're talking about in there, whether it's datediff, or they're just trying to get you to learn conditionals or what..
Was This Post Helpful? 0
  • +
  • -

#7 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: How to compare 6 combo box with different values?

Posted 09 March 2013 - 03:57 AM

View PostTakk, on 09 March 2013 - 10:19 AM, said:

I have to side with the others though, read the chapter you're working from again and see what they're talking about in there, whether it's datediff, or they're just trying to get you to learn conditionals or what..


That's a fair point....what's the objective of the assignment (i.e.: what does your tutor want you to learn or what are you currently covering in class?)?
Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to compare 6 combo box with different values?

Posted 09 March 2013 - 10:48 PM

The logic in your pseudocode is off. It won't do anything unless the minutes = 00, meaning that you have no reason to get the minutes from the user. Also, you are only going to do a calculation if day is both am and pm, meaning never. Start by working out your logic properly. No sense fixing a syntax error if you aren't going to get the results you want anyway.
Was This Post Helpful? 0
  • +
  • -

#9 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to compare 6 combo box with different values?

Posted 11 March 2013 - 12:39 AM

View Postmaj3091, on 09 March 2013 - 03:08 AM, said:

One function that might be worth you reading up on is the DateDiff function, which will allow you to calculate the difference between two DateTime values.

You may find it useful.


thank you for giving me an idea... but what should the data type be? integer? or string then make it val?
Was This Post Helpful? 0
  • +
  • -

#10 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: How to compare 6 combo box with different values?

Posted 11 March 2013 - 06:02 AM

It should be a Date type.

Look here for details.
Was This Post Helpful? 0
  • +
  • -

#11 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to compare 6 combo box with different values?

Posted 12 March 2013 - 09:33 PM

Brer, again: your logic is off.
Was This Post Helpful? 0
  • +
  • -

#12 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to compare 6 combo box with different values?

Posted 13 March 2013 - 12:17 AM

View PostBobRodes, on 12 March 2013 - 09:33 PM, said:

Brer, again: your logic is off.


our instructor finally gave us a hint to use date as the datatype..
like this:

timein <= timeout

timein >= 8:00:00 and timein <= 17:00:00
timeout >= 8:00:00 and timeout <= 17:00:00

if timein <= 12:00:00 and timeout >= 13:00:00 then
hoursworked - 1

if timein > 12:00:00 and timeout < 13:00:00 then
timein = 13:00:00

if timein > 12:00:00 and timeout < 13:00:00 then
timein = 12:00:00
Was This Post Helpful? 0
  • +
  • -

#13 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to compare 6 combo box with different values?

Posted 13 March 2013 - 09:20 PM

Better, but your last two conditions conflict with each other.
Was This Post Helpful? 0
  • +
  • -

#14 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to compare 6 combo box with different values?

Posted 13 March 2013 - 11:36 PM

View PostBobRodes, on 13 March 2013 - 09:20 PM, said:

Better, but your last two conditions conflict with each other.


This is the code:

Public Sub displaytime()
Dim inH As String
Dim inM As String
Dim inF As String
Dim outH As String
Dim outM As String
Dim outF As String
Dim timein As Date
Dim timeout As Date
Dim hrsworked As Date
Dim vacant As Date

vacant = "1:00:00"
inH = Combo1.Text
inM = Combo2.Text
inF = Combo3.Text
outH = Combo6.Text
outM = Combo5.Text
outF = Combo4.Text

'initialize empty values
If inH = "" Then
    inH = "0"
End If
If inM = "" Then
    inM = "00"
End If
If inF = "" Then
    inF = "AM"
End If

If outH = "" Then
    outH = "0"
End If
If outM = "" Then
    outM = "00"
End If
If outF = "" Then
    outF = "AM"
End If

'convert to 24 hours
'time in
If inF = "PM" And inH <> "12" Then
    inH = inH + 12
End If
If inF = "AM" And inH = "12" Then
    inH = inH - 12
End If

timein = inH & ":" & inM & ":00"

'time out
If outF = "PM" And outH <> "12" Then
    outH = outH + 12
End If
If outF = "AM" And outH = "12" Then
    outH = outH - 12
End If

timeout = outH & ":" & outM & ":00"

'check if timein is less than or equal to timeout
If (timein <= timeout) And (timein >= "8:00:00" And timein <= "17:00:00") And (timeout >= "8:00:00" And timeout <= "17:00:00") Then
    hrsworked = timeout - timein
    Label1.Caption = hrsworked
Else
    Label1.Caption = ""
End If
End Sub
Private Sub Combo1_Click()
Call displaytime
End Sub
Private Sub Combo2_Click()
Call displaytime
End Sub
Private Sub Combo3_Click()
Call displaytime
End Sub
Private Sub Combo4_Click()
Call displaytime
End Sub
Private Sub Combo5_Click()
Call displaytime
End Sub
Private Sub Combo6_Click()
Call displaytime
End Sub
Private Sub Form_Load()
Call displaytime
End Sub



if time in and time out is within the range then it calculates the hours worked but the if time in is beyond the range then it should also calculate but it does only calculate the hours with in the range.. so the code above does not.. how to? it only calculates the hours worked within the range...

This post has been edited by BobRodes: 14 March 2013 - 06:48 PM
Reason for edit:: Please use code tags in future.

Was This Post Helpful? 0
  • +
  • -

#15 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to compare 6 combo box with different values?

Posted 14 March 2013 - 06:51 PM

This is never true: timein >= "8:00:00" And timein <= "17:00:00" because "17:00:00" is always less than "8:00:00". Any idea why? :)

Hint: while it is true that 1000 > 800, it is also true that "800" > "1000".

This post has been edited by BobRodes: 14 March 2013 - 06:53 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1