Saturday, 12 May 2012

Hi Peeps, maybe you wish to play around developing simple applications on vb6, here I will show you how you can make a  simple calendar using vb6. My illustration will basically contain what the user interface can look like and then your code.

Here is a simple interface I developed on small sectional form in the design area. You can decide to make your form bigger depending on how you want your calendar to look. You can use images, etc. to make your calendar more attractive.

I am making use of simply a few objects, a number labels, 2 scroll bars (1 horizontal and on vertical) and a command button. The first labels will show the current month and the horizontal scroll bar next to it will allow the user change the name of the month in the label when clicked. The second label beneath displays the current date, showing the name of the day and then the date. The preceeding labels are arranged accordingly in a calendar pattern with the first line showing the name of the days. Other labels are presented underneath this line showing each date of the day from 1 to 31, depending on the month.

The above image shows you what the the interface/application looks like when debugged. Now you can see the hidden labels holding the numbers of day.  Clicking the command button - reset, will take the application back to its default calendar values which is the current month and date.

The vertical scroll bars will allow the user toggle the number of the days so it is possible to check a future date. All you need do is to toggle the Hscroll-bar (horizontal scroll bar) for the month you wish to view in the future or past and then toggle the Vscroll-bar (vertical scroll bar) for the date/day.

I will now give you my code with which I use to run this progam and I hope you are able to do yours and come up with even better calendars.

Calendar Code
..............................................................................................................................................
Option Explicit
Dim date0, date1, date2, date3 As String
Dim x, first, tel As Integer

Private Sub Command1_Click()
HScroll1.Value = 0
HScroll2.Value = 0
date0 = DateAdd("m", HScroll1.Value, Date)
date1 = DateSerial(Format(date0, "yyyy"), Format(date0, "mm"), 1)
End Sub
Private Sub Form_Activate()
date0 = Date
Command1_Click
SetDate
End Sub
Private Sub SetDate()
Label2.Caption = UCase(Format(date0, "mmmm"))
Calendar.Caption = Format(date0, "             yyyy")
For x = 0 To 36
Label3(x).Visible = False
Label3(x).ForeColor = RGB(0, 96, 64)
Label3(x).BorderStyle = 0
Next x
first = Val(Format(date1, "w")) - 1
date2 = date1: tel = 0
For x = first To 36
date2 = DateAdd("d", tel, date1)
If DateDiff("m", date1, date2) > 0 Then Exit For
Label3(x).Caption = Day(date2)
Label3(x).Visible = True
tel = tel + 1
Next x
If date0 = Date Then
Label4.Caption = Format(Date, "dddd, dd mmmm yyyy")
For x = 0 To 36
    If Label3(x).Caption = Day(Date) Then
    Label3(x).ForeColor = vbRed
    Label3(x).BorderStyle = 1
    Exit For
    End If
Next x
End If
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = True
Calendar.Left = 2100
Credits.Show 1
End Sub

Private Sub HScroll1_Change()
date0 = DateAdd("m", (HScroll2.Value * 12) + HScroll1.Value, Date)
date1 = DateSerial(Format(date0, "yyyy"), Format(date0, "mm"), 1)
SetDate
End Sub

Private Sub HScroll2_Change()
date0 = DateAdd("m", (HScroll2.Value * 12) + HScroll1.Value, Date)
date1 = DateSerial(Format(date0, "yyyy"), Format(date0, "mm"), 1)
SetDate
End Sub

.......................................................................................................................
Ordinarily I would have love to explain in detail each line of code used but I want to count on your questions and be able to solve any challenge your face, while hoping you would try this on your own. You can try developing similar applications but with finer and more creative ideas, I still will be helpful to develop your ideas with you and introduce additional lines of codes if necessary. Infact that is the idea.


Have a wonderful time trying my simple calendar application out and feel free to invite me if you wish to show works you have developed using other platforms.

Cya!

Adeyemi

2 comments:

  1. This is good, i have been looking for something like this, i will try this out and see if i can develop new applications using the steps you have supplied

    ReplyDelete
  2. I just want to ask, how the Credits.Show 1 works? I search about it in the google and i understand what is the Show VB Credits but i really don't understand what that code does. What i come to do was to change that code into an "End " keyword so the program will be able to close.

    I hope you're willing to help

    ReplyDelete