 |
| 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
|
|
|
|

January 31st, 2009, 07:31 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
How can i get full months date
Iâm very very new in VB6.0 in my project I need a function where I want to pass month name as variable value which will be selected from a combo box by user and the function will generate the full date from starting to end along with the weekday name.
Suppose user select the month âJANUARYâ and year from different combo box. Under combo box click event that function will work and will generate the valid date from 1st January to 31th January along with the weekday name. like:
01-Jan-09 Thursday, 02-Jan-09 Friday, 03-Jan-09 Saturday, 04-Jan-09 Sunday, 05-Jan-09 Monday, 06-Jan-09 Tuesday, 07-Jan-09 Wednesday, 08-Jan-09 Thursday, 09-Jan-09 Friday, 10-Jan-09 Saturday, 11-Jan-09 Sunday, 12-Jan-09 Monday, 13-Jan-09 Tuesday, 14-Jan-09 Wednesday, 15-Jan-09 Thursday, 16-Jan-09 Friday, 17-Jan-09 Saturday, 18-Jan-09 Sunday, 19-Jan-09 Monday, 20-Jan-09 Tuesday, 21-Jan-09 Wednesday, 22-Jan-09 Thursday, 23-Jan-09 Friday, 24-Jan-09 Saturday, 25-Jan-09 Sunday, 26-Jan-09 Monday, 27-Jan-09 Tuesday, 28-Jan-09 Wednesday, 29-Jan-09 Thursday, 30-Jan-09 Friday, 31-Jan-09 Saturday.
LevelText of 31 unique level (control) will display those dates. All the date must be valid. Iâm requesting all of my seniors, plz plz help me.
|
|

January 31st, 2009, 04:45 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Something like this:
Code:
' given month number (1 through 12) and year, generate list of all days in month:
monthNum = 1 ' or wherever you get this from, e.g., from the combo box
yearNum = 2009
Dim firstOfMonth As Date, lastOfMonth As Date
firstOfMonth = DateSerial( yearNum, monthNum, 1 )
lastOfMonth = DateSerial( yearNum, monthNum+1, 0 )
For myDate = firstOfMonth To lastOfMonth
Dim oneDate As String
oneDate = Right("0" & Day(myDate),2) & "-" & MonthName(Month(myDate),True) _
& Right(CStr(Year(myDate)),2) & " " & WeekdayName(Weekday(myDate))
... do something with "oneDate" ...
Next
It's been 10 years since I played with VB6, but I think that's right.
|
|

February 1st, 2009, 07:38 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Hello Pedent,
Thank you very much. You just push me one step ahead to my project being done. How will i place the "oneDate" value in 31 level. Should i make control array or how will i do that??
As i mentioned earlier, I'm very new in VB 6. You played 10 years but i have started playing since 7 months.
Please help me for "oneDate".
|
|

February 1st, 2009, 06:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Sorry, but I don't know what you mean by " ... in 31 level."
You mean into the 31 options of the combo box???
Sorry, but I just don't remember that, at all. If you can use an array to populate a combo box, then yes, creating an array from that code would work fine.
Code:
' given month number (1 through 12) and year, generate list of all days in month:
monthNum = 1 ' or wherever you get this from, e.g., from the combo box
yearNum = 2009
Dim firstOfMonth As Date, lastOfMonth As Date
firstOfMonth = DateSerial( yearNum, monthNum, 1 )
lastOfMonth = DateSerial( yearNum, monthNum+1, 0 )
Dim arrayOfDates
ReDim arrayOfDates( Day(lastOfMonth) - 1 )
For myDate = firstOfMonth To lastOfMonth
Dim oneDate As String
oneDate = Right("0" & Day(myDate),2) & "-" & MonthName(Month(myDate),True) _
& Right(CStr(Year(myDate)),2) & " " & WeekdayName(Weekday(myDate))
arrayOfDates( Day(myDate) - 1 ) = oneDate
Next
SOMETHING like that, at least.
|
|
The Following User Says Thank You to Old Pedant For This Useful Post:
|
|
|

February 2nd, 2009, 02:00 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Hello Pedant,
Thank you very much for the reply. Sorry Pedant i made you confuse. Actually i keep 31 individual Label(control) in the form for displaying all the month dates in its CAPTION. Its like
Label1 will contain date1
Label2 will contain date2
.
.
.
.
.
Label31 will contain date31.
Will you please help me?
|
|

February 3rd, 2009, 01:54 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
I just don't remember <FORM>s in VB6. Most of what I did was create COM DLLs for use by ASP pages, so we weren't creating any ".exe"s and of course that meant no <FORM>s.
If you could show some code as to how you create a label, *maybe* it will help me remember enough.
|
|

February 3rd, 2009, 07:29 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Coming to the rescue ;)
Do you have your labels in a collection (with index, all the same name)?
I hope you, that way the only thing you have to do is
Code:
labeldate(1).caption = oneday
if you don´t have a collection of controls, then you will need to do a select case (or an if) and write the code to fill every control by itself. I hope you can go to the first method :)
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|
The Following User Says Thank You to gbianchi For This Useful Post:
|
|
|

February 3rd, 2009, 02:01 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Hello Pedant
Dear Pedant,
Again Thank you very much for the reply. You are playing with VB for the last 10 years but Iâm still in the beginning stage of VB. My project purpose is to make âRoster dutyâ. I took a standard exe form where I placed label, text box, combo box from the toolbar. One combo box is containing month and another combo box containing year. When a month will be selected by user the date for that month will be displayed in different 31 Labels.
Name
March
2009
Sat
Sun
Mon
Tues
Wed
Thurs
Fri
1
2
Morning
Morning
3
4
5
6
7
8
9
Evening
Evening
Night
Off
Off
Morning
Morning
10
11
12
13
14
15
16
Evening
Evening
Night
Off
Off
Morning
Morning
17
18
19
20
21
22
23
Evening
Evening
Night
Off
Off
Morning
Morning
24
25
26
27
28
29
30
Evening
Evening
Night
Off
Off
Morning
Morning
31
Evening
1, 2, 3, 4⦠which are representing dates of March(selected in combo box).All the dates are displaying in label caption. Instead of 1, 2, 3, 4, .. I want to display the full date which I get from your help. Now the problem is all the dates which Iâm getting from the loop how will I place all the individual date in individual label caption??? Time is running out. If you could manage time please help me regarding it, Please Pedant help me.
|
|

February 4th, 2009, 03:27 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
I think GBianchi will be better able to help you than I.
I'm afraid I don't really even understand the question.
May I ask why you are starting to learn VB6 *NOW*??? VB6 is very badly OBSOLETE. Microsoft replaced in 2001 with VB.NET, and VB.NET is a *MUCH* better language and much more "up to date". It's also free. (Or at least the "Express" edition is.) And it has some wonderful FREE tutorials.
|
|
The Following User Says Thank You to Old Pedant For This Useful Post:
|
|
|

February 10th, 2009, 07:17 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 20
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Hello Pedant
Hello Pedant,
Sorry for late reply and for my last post. I wrote it as table was the mistake. You said right. VB 6.0 is obsolate. Surely i will start learning VB.NET right after completing my current project.
Now i can generate full month date which might not possible without your help. In this regard, again THANK YOU VERY MUCH FOR THE SUPPORT.
If i face any more problem then surely i'll knock you. I hope you wont mind to help me!!!
Take care.
|
|
 |