Warning

 

Close

Confirm Action

Are you sure you wish to do this?

Confirm Cancel
BCM
User Panel

Site Notices
Posted: 5/6/2003 12:29:02 PM EDT
I have a VB6 Project due for a class and I'm lost.  It's my final project and worth 1/3 of my grade.  I'm having trouble formatting dates, date diff function and a variable array to look up names using SSAN's

Any help would be apprecited

Link Posted: 5/6/2003 12:46:08 PM EDT
[#1]
Formatting in VB6 can be a bear! Try checking out the format$ function. If thats not what you need, let me know and I'll dig a little deeper. Don't know the data diff function...

Try using a Collection instead of an array. Collections are pretty easy to work with.

in General section, do this:
dim colSSANums as collection

in Form, do this:
set colSSANums = new collection

then you can add stuff to it:

colSSANums.Add sSomeStringVariable

You can get the number of things in the collection from colSSANums.Count

which means you can loop through the collection looking for stuff, like this:

for i = 1 to colSSANums.Count
    do some stuff...
next

Try it, you'll like it. Arrays are clummsy.
Link Posted: 5/6/2003 12:58:23 PM EDT
[#2]
Thanks I'll try your suggestions.  The datediff is suppose to give total time between two dates/times.  My are an array of clockin/out times to figure an employees total hours.  I'm begining to question my degree choice, this is probably a very easy program that has me tottaly lost.

thanks
Link Posted: 5/6/2003 1:09:11 PM EDT
[#3]
datediff looks useful. I just looked it up.

Easy as pie to use...

dim vTime as variant
.
....(your other stuff happens here)
.
vTime = datediff(n, dateTimeBegin, dateTimeEnd)

The "n" means "Return the value to me in minutes"
You can then figure hours and minutes, etc.

Look up datediff in the help index in VB.
Link Posted: 5/6/2003 1:25:08 PM EDT
[#4]
Quoted:
datediff looks useful. I just looked it up.

Easy as pie to use...

dim vTime as variant
.
....(your other stuff happens here)
.
vTime = datediff(n, dateTimeBegin, dateTimeEnd)

The "n" means "Return the value to me in minutes"
You can then figure hours and minutes, etc.

Look up datediff in the help index in VB.
View Quote


Beat me to it, which is probably good since you wrote it more concisely than I probably would have.

If your project dictates that you HAVE to use an array, then do it thataway, but if you CAN use a collection, that's what I'd do...

You don't have to worry about redimming and all that crap... I swear I never could get the preserve command to work in my code...

Anyways, let me know if you need any help on this...

Shawn
Link Posted: 5/6/2003 1:25:52 PM EDT
[#5]
Yes it should but it isn't I have to use an array of 6 clock in and out times that must be creating the problem.

Dim Index As Integer
   For Index = 0 To 5
       intMinutes = DateDiff("n", txtIn(Index), txtOut(Index))
   Next
   End
Link Posted: 5/6/2003 1:39:23 PM EDT
[#6]
Try using "N" without the quotes around it.

hmmm... nevermind, MSDN shows quotes around their interval expressions...

I'd like to see where these two arrays are dimmed and where the values for them are assigned.

txtIn(Index), txtOut(Index))

I would expect them to look like this:

dim txtIn(0 to 100) as date
dim txtOut(0 to 100) as date

I'd like to see how the txtIn and txtOut values are assigned...

Here's a quick sub I wrote that assigns a date to a variable and messages it to the user. I'm guessing you may not be assigning valid date/times to the txtIn or txtOut variables.

Private Sub Command1_Click()
Dim txtIn(0 To 100) As Date
txtIn(1) = Now
MsgBox txtIn(1)
End Sub

That's my guess for now....
'
Shawn
Link Posted: 5/6/2003 1:39:26 PM EDT
[#7]
The documentation says that datediff returns a VARIANT, not an integer. I've noticed that VB can sometimes wig out if you try using the wrong type as a return value.

So try it using a variant instead of the integer, "intMinutes".

Also, to make your code a lot more friendly and less error prone, don't hard code the top boundary of the array loop (for index = 0 to 5). Use UBound instead of 5, like this:

if txtIn is defined like this:

Dim txtIn(0 to 5)

for index = 0 to UBound(txtIn, 1)
Link Posted: 5/6/2003 1:42:44 PM EDT
[#8]
Quoted:
The documentation says that datediff returns a VARIANT, not an integer. I've noticed that VB can sometimes wig out if you try using the wrong type as a return value.
View Quote


Here's what the MSDN documentation says:

Returns a Variant (Long) specifying the number of time intervals between two specified dates.

What kind of failure are you getting anyways?

Shawn
Link Posted: 5/6/2003 1:50:13 PM EDT
[#9]
Here's a simple subroutine I wrote. If you make a button on a form called command1 and drop this code on the form, it should work. It just assigns a date to one array member, assigns a date to another array member and then calculates the difference between them in minutes.

My advice to you is this. Make sure you are using dates in the datediff function. Make sure you are assigning the result to a long variable.

Hope this helps troubleshoot...

Private Sub Command1_Click()
Dim txtIn(0 To 100) As Date
Dim txtOut(0 To 100) As Date
Dim x As Long

txtIn(1) = "10/30/2002 5:00"
txtOut(1) = Now

x = DateDiff("N", txtIn(1), txtOut(1))

MsgBox txtIn(1)
MsgBox txtOut(1)
MsgBox x
End Sub

(Edited to clarify)
Link Posted: 5/6/2003 1:52:37 PM EDT
[#10]
run time error 13

type mismatch

Would it help if I sent the files?
Link Posted: 5/6/2003 1:55:02 PM EDT
[#11]
Quoted:
run time error 13

type mismatch

Would it help if I sent the files?
View Quote


Defintely sounds like you are assigning the result of your datediff into a variable that will not accept the value.

Try using a variant or a long for the datediff function.

Also, be sure you are diffing Dates. (Visual basic defined dates)

Shawn
Link Posted: 5/6/2003 2:00:11 PM EDT
[#12]
Quoted:
run time error 13

type mismatch

Would it help if I sent the files?
View Quote


Make sure the input dates values are Date data types...

If IsDate(myStartDate) And IsDate(myEndDate) Then
   myInterval = DateDiff("n", myStartDate, myEndate)
Else
   ' error condition
End If

Link Posted: 5/6/2003 2:04:13 PM EDT
[#13]
I suppose this is a bad time to ask, [b]WHAT THE HELL ARE YOU TALKING ABOUT!![/b] [:D]
Link Posted: 5/6/2003 2:05:54 PM EDT
[#14]
lol
Link Posted: 5/6/2003 2:12:28 PM EDT
[#15]
Here is the unfinished code for the program.  I'm trying to get the dates to format propperly but that's been a problem also.

Option Explicit
   'This program will calculate Hours worked, sick or vacation
       'and claculate gross pay
       
   Dim curGrossPay As Currency
   Dim sngTotalHours As Single
   Dim sngOverHours As Single
   Dim sngRegHours As Single
   Dim sngSickVac As Single
   Dim intMinutes As Integer
   Dim strFileName As String

Private Sub cmdCalc_Click()
   Dim Index As Integer
   For Index = 0 To 5
       intMinutes = DateDiff("n", txtIn(Index), txtOut(Index))
   Next
   End
   sngTotalHours = intMinutes / 60
   
   If sngTotalHours > 8 Then
       sngOverHours = sngTotalHours - 8
   Else: sngOverHours = "0"
       If sngTotalHours > 8 Then
           sngRegHours = sngTotalHours - sngOverHours
       Else: sngRegHours = sngTotalHours

   End If
   End If
   
   curGrossPay = (sngRegHours * 10) + (sngSickVac * 10) + (sngOverHours * (10 * 1.5))
   
   lblRegHours.Caption = Format(sngRegHours, "0.00")
   lblOverTime.Caption = Format(sngOverHours, "0.00")
   lblGrossPay.Caption = Format(curGrossPay, "currency")
End Sub

Private Sub cmdClear_Click()
   lblRegHours.Caption = "0"
   lblOverTime.Caption = "0"
   lblSickVacation.Caption = "0"
   lblGrossPay.Caption = " "
End Sub

Private Sub cmdExit_Click()
   End
End Sub




Private Sub cmdVerify_Click()
   Const conBtns = vbOKOnly = vbInformation _
       + vbdefaultbutton = vbApplicationModal
   Const comMsg1 = "Invalad Employee SSAN reenter."
   Dim strSSAN As String
   Dim strName As String
   
   
End Sub

Private Sub dtmDate_Change()
   dtmDate = Format(dtmDate.Text, vbShortDate)
End Sub

Private Sub dtmIn_Change(Index As Integer)
   dtmIn(Index) = Format(dtmIn(Index), "Short Time")

End Sub

Private Sub dtmOut_Change(Index As Integer)
   dtmOut(Index) = Format(dtmOut(Index), "Short Time")
End Sub

Private Sub Form_Load()

   Dim strEmployee(1 To 5) As String
   strEmployee(1) = "555-42-9486""Jonah Jones"
   strEmployee(2) = "884-34-9999""Mark Smith"
   strEmployee(3) = "456-78-9123""John Doe"
   strEmployee(4) = "123-45-6789""Red Green"
   strEmployee(5) = "741-85-2963""Jim Dipdap"

   
End Sub

Private Sub txtSick_Change()
   sngSickVac = Val(txtSick)
   If sngSickVac + sngTotalHours > 8 Then
       MsgBox ("Total hours must be less then 8 when employee is taking sick time")
   End If
   
End Sub


Private Sub txtVacation_Change()
   sngSickVac = Val(txtVacation)
   If sngSickVac + sngTotalHours > 8 Then
       MsgBox ("Total hours must be less then 8 when employee is taking vacation time")
   End If
End Sub


Link Posted: 5/6/2003 2:17:22 PM EDT
[#16]
If it were clear to me we wouldn't be discussing it....
Link Posted: 5/6/2003 3:14:42 PM EDT
[#17]
here's a quickie eval...


Dim intMinutes As Integer
...
intMinutes = DateDiff("n", txtIn(Index), txtOut(Index))
View Quote


intMinutes needs to be declared as a Long data type.

The textbox values need to be cast as Date data types and don't rely on the default property...
If you need to know the difference in hours, request that interval type instead of programatically consverting...
lngHours = DateDiff("h", CDate(txtIn(Index).Text), CDate(txtOut(Index).Text))


I'll look at in more detail later...
Link Posted: 5/6/2003 4:10:07 PM EDT
[#18]
The following comments apply to you cmdCalc.Click() event.....
1) For loop - You appear to be iterating through an array of textboxes containing start and stop dates. However, your processing happens after the conclusion of the loop. So, you're only processing the computation from the last set of textboxes.
2) You're expecting to process against the difference in hours of the input values. The "h" interval will give the difference in hours without having to manually computing it.
3) After the For loop you have an End statement. I assume that's a bug as your application will terminate at that point.
4) Your computed value for hours are all integer types. You should really Dim your variables accordingly. FYI, on a 32-bit system a VB Long data type is the most performant integer data type.
5) sngOverHours = "0" - You're attempting to assign a String value to a Single variable data type. That's a definite type mismatch.
6) You have a dead conditional branch in your nested If statements...
   If sngTotalHours > 8 Then
       ' ...
   Else
       If sngTotalHours > 8 Then
           ' ??? - this will never execute because it's already been evaluated
       Else
           ' ...
       End If
   End If

In your cmdExit.Click() event you have an End statement. Very bad form. Never, never ever use this statement. To terminate your application...
Call Unload(Me)

Hope that helps.
Link Posted: 5/7/2003 4:50:21 PM EDT
[#19]
Didja ever figure it out? You must really be cutting this project close! My fiance has finals this next week, and a lot of college kids are already out for the year, so it looks like you've been putting this project off a little bit.... especially if you are so desperate as to ask some AR junkies how to code...

Shawn
Link Posted: 5/7/2003 4:59:31 PM EDT
[#20]

Anyone know VB6
View Quote


!! NO _& Request.Right.Forum !!



Dang, try and use an asp tag... no workie
Close Join Our Mail List to Stay Up To Date! Win a FREE Membership!

Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!

You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.


By signing up you agree to our User Agreement. *Must have a registered ARFCOM account to win.
Top Top