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 February 28th, 2005, 07:42 PM
mlf mlf is offline
Registered User
 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listboxes as Date w/ validation

I am creating a .net project and am adding custom renderers. I have this code for creating the date field into 3 listboxes, the Month, theDay and theYear. I would like to add an on_change() event (or some such mechanism) to change theDay from 1-31 to the appropriate number of days (I have to consider leap years too).

---------------- Beginning of code -------------------------
Imports System.ComponentModel
Imports System.Web.UI

<ToolboxData("<{0}:DateRenderer runat=server></{0}:DateRenderer>")> Class DateRenderer
    Inherits AbstractFieldRenderer

    Private Shared ReadOnly DEFAULT_DATE = Now()

    Private Shared log As log4net.ILog = log4net.LogManager.GetLogger("DateRenderer")

    Public Overloads Sub onInit(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Init

        Dim theMonth As New ListBox
        '' theMonth.Width = Unit.Parse("21pt")
        theMonth.ID = Me.ID & "_theMonth"
        theMonth.Items.Add(New ListItem("Jan", "01"))
        theMonth.Items.Add(New ListItem("Feb", "02"))
        theMonth.Items.Add(New ListItem("Mar", "03"))
        theMonth.Items.Add(New ListItem("Apr", "04"))
        theMonth.Items.Add(New ListItem("May", "05"))
        theMonth.Items.Add(New ListItem("Jun", "06"))
        theMonth.Items.Add(New ListItem("Jul", "07"))
        theMonth.Items.Add(New ListItem("Aug", "08"))
        theMonth.Items.Add(New ListItem("Sep", "09"))
        theMonth.Items.Add(New ListItem("Oct", "10"))
        theMonth.Items.Add(New ListItem("Nov", "11"))
        theMonth.Items.Add(New ListItem("Dec", "12"))
        Me.Parent.Controls.Add(theMonth)


        Dim theDay As New ListBox
        'theDay.Width = Unit.Parse("14pt")
        theDay.ID = Me.ID & "_theDay"
        Dim i As Integer
        For i = 1 To 31
            theDay.Items.Add(New ListItem(i, i))
        Next

        Dim theYear As New ListBox
        'theYear.Width = Unit.Parse("28pt")
        theYear.MaxLength = 4
        theYear.ID = Me.ID & "_lastFour"
        Dim x As Integer = System.DateTime.Today.Year
        For i = 1900 To x
            theYear.Items.Add(New ListItem(i, i))
        Next

        Dim theMonthRequiredValidator As New RequiredFieldValidator
        theMonthRequiredValidator.ControlToValidate = Me.ID & "_theMonth"
        theMonthRequiredValidator.ErrorMessage = "Choose a month, this field is required."
        theMonthRequiredValidator.Display = ValidatorDisplay.None

        Dim theDayRequiredValidator As New RequiredFieldValidator
        theDayRequiredValidator.ControlToValidate = Me.ID & "_theDay"
        theDayRequiredValidator.ErrorMessage = "Choose a day, this field is required."
        theDayRequiredValidator.Display = ValidatorDisplay.None

        Dim theYearRequiredValidator As New RequiredFieldValidator
        theYearRequiredValidator.ControlToValidate = Me.ID & "_theYear"
        theYearRequiredValidator.ErrorMessage = "Choose a year, this field is required."
        theYearRequiredValidator.Display = ValidatorDisplay.None

        Me.Parent.Controls.Add(theMonthRequiredValidator)
        Me.Parent.Controls.Add(theDayRequiredValidator)
        Me.Parent.Controls.Add(theYearRequiredValidator)

        Me.Parent.Controls.Add(theMonth)
        Me.Parent.Controls.Add(theDay)
        Me.Parent.Controls.Add(theYear)

    End Sub
End Class
---------------- End of code -------------------------
Thanks for the help!

 
Old March 1st, 2005, 11:45 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

This would probably be better posted in Beginning VB.NOT. . .
 
Old March 2nd, 2005, 11:47 PM
mlf mlf is offline
Registered User
 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian,

Do you have some idea how I would add a lost_focus or on_change event?

Thanks!

 
Old March 4th, 2005, 09:29 PM
mlf mlf is offline
Registered User
 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have added theMonth.Items.AutoPostBack = true and would like to know how I would now find the current selected value. If I do the AutoPostBack I then get the whole INIT started again and I'm really after what is selected so that I can populate the day field.

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Validation ramesh055 ASP.NET 1.0 and 1.1 Professional 1 November 15th, 2006 11:09 AM
date validation rmscandy XSLT 1 August 7th, 2006 11:02 AM
Listboxes Sub-Listboxes and Table Linking MJB05 Access 4 September 20th, 2005 12:37 PM
Listboxes with validation mlf VB.NET 2002/2003 Basics 0 March 2nd, 2005 11:42 PM
Date validation Raul Javascript 4 February 25th, 2004 04:04 PM





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