Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 1st, 2006, 11:29 AM
Registered User
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need advice to clean up my date manipulation code

I am new to VB6 so please bear with me. I have to take the date a salesman started and see if they have worked for 24 months yet. BUT! If they start after January of a given year, they are to be considered as having started January 1 of the following year. For example: I started 1 February 2006, I need my comparison date to become 1 January 2007.

What I have done so far works, but it is extremely ugly. I would like a more elegant way to accomplish this.

Here is my code so far:
Dim tempmonth As String
Dim comparedate As String

tempmonth = Month(rsAgtRateUpdate![Fin Date])

If tempmonth <> 1 Then
    comparedate = "1/1/" & (Year(rsAgtRateUpdate![Fin Date]) + 1)
    comparedate = rsAgtRateUpdate![Fin Date]
End If

'If the difference between the start date and the compare date is less than 24 months, it's a new hire
If DateDiff("m", DateValue(comparedate), xBegDate) < 24 Then
    rsAgtRateUpdate!AgtFlag = "2"
    rsAgtRateUpdate!AgtFlag = "1"
End If
I thank you in advance.
Old June 2nd, 2006, 01:29 PM
Authorized User
Join Date: Dec 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts

Since you only care if the person started in January or not, it looks to me that you could combine your "tempmonth" assignment and "if" statement comparison into:

If Month(rsAgtRateUpdate![Fin Date]) > 1 then

That would eliminate on of your temporary variables, but given the method of determining length of employment, the rest looks necessary. Other than that, I don't see much else to change. In my humble opinion, however, if it works, use it.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Manipulation pallone Javascript How-To 2 May 5th, 2006 02:15 PM
HELP Needed in Date Manipulation kunjan SQL Language 9 March 19th, 2006 09:51 PM
ask for advice about image manipulation/search raybristol ASP.NET 1.0 and 1.1 Basics 1 January 25th, 2006 06:03 AM
Date manipulation otarboy Access 1 September 20th, 2004 11:50 AM
code to clean and modify dbase lord_brighton Access VBA 0 August 8th, 2004 07:26 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.