Click here to Skip to main content
15,884,962 members
Articles / Programming Languages / VBScript

OCX Calendar VB

Rate me:
Please Sign up or sign in to vote.
3.29/5 (7 votes)
25 Apr 2002CPOL 396.5K   6K   16   11
OCX User Control for Visual Basic

Sample Image - OCX_Calendar.jpg

Introduction

This is an OCX Calendar User Control for Visual Basic.

To call the calendar control:

VB.NET
Calendario.Generate (Date)

The DATE parameter is the day default selected.
To get the selected date:

VB.NET
MsgBox Calendario.DateOutput

The code is very easy.

Display day of the month:

VB.NET
For intI = 1 To intCantSemanas
    For IntJ = 1 To 7
        intCantAct = intCantAct + 1
        
        If intCantAct >= intDiaSemana Then
            intDay = intDay + 1
            
            If IsDate(intDay & "/" & strMonth & "/" & strYear) Then
                strFechaOut = intDay & "/" & strMonth & "/" & strYear
                lblDay(intCantAct) = intDay
                lblDay(intCantAct).ForeColor = &H80000008
                lblDay(intCantAct).ToolTipText = Format(strFechaOut, "dd/mm/yyyy")
            Else
                intCantDes = intCantDes + 1
                strFechaOut = intCantDes & "/" & _
			Month(DateAdd("m", 1, strFechaOut)) & "/" & strYear
                lblDay(intCantAct) = intCantDes
                lblDay(intCantAct).ForeColor = &HC0C0C0
                lblDay(intCantAct).ToolTipText = Format(strFechaOut, "dd/mm/yyyy")
            End If
        Else
            strFechaOut = DateAdd("d", intCantAct - intDiaSemana, strDate)
            lblDay(intCantAct) = Day(DateAdd("d", intCantAct - intDiaSemana, strDate))
            lblDay(intCantAct).ForeColor = &HC0C0C0
            lblDay(intCantAct).ToolTipText = Format(strFechaOut, "dd/mm/yyyy")
        End If
        
        If lblDay(intCantAct) = strDay Then
            lblDay(intCantAct).BackColor = &H80000008
            lblDay(intCantAct).ForeColor = &HFFFFFF
        End If
    Next IntJ
Next intI

History

  • 25th April, 2002: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Argentina Argentina
Lic. Fernando Finelli

Comments and Discussions

 
QuestionHow to call OCX Calendar component Pin
Gopabandhu30-Aug-05 21:22
Gopabandhu30-Aug-05 21:22 
GeneralPorteño Brisco! Pin
Trompis12-Aug-04 5:47
sussTrompis12-Aug-04 5:47 
GeneralHelp! NullReference Exception Pin
horngsh16-Mar-04 13:34
horngsh16-Mar-04 13:34 
Hello, everybody. I would like to exercise the random number generation. So I write a little program called LottoNumGen.exe.
It can compile smoothly but when I ran it, it bailed out with a error message as follows:

An unhandled exception of System.NullReferenceException occurred in LottoNumGen.exe

and then I pressed the break button and the vs.net marked out my error code line as yellow at

randnumAry(i).index = i

the following is my code listing:


Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(0, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(35, 18)
Me.Label1.TabIndex = 0
Me.Label1.Text = "號碼1"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(0, 40)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(35, 18)
Me.Label2.TabIndex = 1
Me.Label2.Text = "號碼2"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(0, 72)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(35, 18)
Me.Label3.TabIndex = 2
Me.Label3.Text = "號碼3"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(0, 104)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(35, 18)
Me.Label4.TabIndex = 3
Me.Label4.Text = "號碼4"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(0, 136)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(35, 18)
Me.Label5.TabIndex = 4
Me.Label5.Text = "號碼5"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(40, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 5
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(40, 40)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 6
Me.TextBox2.Text = ""
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(40, 72)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.TabIndex = 7
Me.TextBox3.Text = ""
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(40, 104)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.TabIndex = 8
Me.TextBox4.Text = ""
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(40, 136)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.TabIndex = 9
Me.TextBox5.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(160, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 64)
Me.Button1.TabIndex = 10
Me.Button1.Text = "丟骰子"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(160, 88)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(96, 64)
Me.Button2.TabIndex = 11
Me.Button2.Text = "清除"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)
Me.ClientSize = New System.Drawing.Size(504, 333)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "樂透號碼產生器"
Me.ResumeLayout(False)

End Sub

#End Region

Sub swap(ByRef x As randNum, ByRef y As randNum)
Dim temp As New randNum
temp = y
y = x
x = temp
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim randGetNum As New Random
Dim i, j As Integer
Dim randnumAry(45) As randNum
'randnumAry = New randNum(45) {}

For i = 1 To 45
randnumAry(i).index = i
Next

For i = 1 To 86400
For j = 1 To 45
randnumAry(randGetNum.Next(1, 45)).value += 1
Next
Next

For i = 1 To 44
For j = i + 1 To 45
If randnumAry(i).value < randnumAry(j).value Then
swap(randnumAry(i), randnumAry(j))
End If
Next
Next

'For i = 1 To 5
'intAry(i) = randGetNum.Next(1, 45)
'Next

TextBox1.Text = randnumAry(1).index
TextBox2.Text = randnumAry(2).index
TextBox3.Text = randnumAry(3).index
TextBox4.Text = randnumAry(4).index
TextBox5.Text = randnumAry(5).index

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
End Sub
End Class

Public Class randNum
Public index As Integer
Public value As Integer
End Class
QuestionVB ??? Pin
datxp10-Feb-03 6:41
datxp10-Feb-03 6:41 
Generalbest article I ever read Pin
29-Apr-02 11:53
suss29-Apr-02 11:53 
GeneralRe: best article I ever read Pin
Ravi Bhavnani29-Apr-02 12:22
professionalRavi Bhavnani29-Apr-02 12:22 
GeneralRe: best article I ever read Pin
Carlos Antollini20-Jul-02 17:33
Carlos Antollini20-Jul-02 17:33 
GeneralRe: best article I ever read Pin
marker2721-Jul-03 11:32
sussmarker2721-Jul-03 11:32 
GeneralRe: best article I ever read Pin
Fernando Finelli16-Jul-04 7:54
Fernando Finelli16-Jul-04 7:54 
GeneralRe: best article I ever read Pin
Fernando Finelli16-Jul-04 7:55
Fernando Finelli16-Jul-04 7:55 
GeneralRe: best article I ever read Pin
Samurai Fugu12-Sep-06 14:39
Samurai Fugu12-Sep-06 14:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.