|
-
Dec 29th, 2011, 12:12 PM
#1
Thread Starter
Addicted Member
[RESOLVED] List of Dates
Hi, how would I go about getting a list of dates to generate on form load from "today" till a certain amount in a ListBox for example:
19/12/2011
20/12/2011
21/12/2011
22/12/2011
23/12/2011
24/12/2011
so on
It would be most appreciated if a short code sample could be posted if this is a simple thing to do thank you.
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 29th, 2011, 12:18 PM
#2
Frenzied Member
Re: List of Dates
this is a forum that helps you when you are stuck and gives you advise when you are having a problem.
no attempt = no advice
that was easy!
(1) what version of vb are you using?
(2) do you know how to make todays date ?
(3) can you format a date to look like 19/12/2011?
(4) can you add things to a listbox?
if so please show you code and we can go from there
it does not have to be correct but it needs to an attempt!
here to talk ( and scowl - and help - eventually! )
-
Dec 29th, 2011, 12:32 PM
#3
Thread Starter
Addicted Member
Re: List of Dates
oh right sorry I am using good old VB6 but haven't been for long so i am not to sure how ome thing work with the lang.
Yes I know how to make today "Date" and "Format" which I wont have to do as the default format is dd/mm/yyyy and yes I know and have used most of the functions of the ListBox.
I have searched the web but can't seem to find much so can you please direct me to a good source or give me some tips on how this can be best achieved.
Code:
Dim i As Integer
Private Sub Form_Load()
i = 1
lstDates.AddItem Date
Do
lstDates.AddItem Date + 1
i = i + 1
Loop Until i = 67
End Sub
This is my attempt ......if only in a idealistic world
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 29th, 2011, 12:42 PM
#4
Re: List of Dates
Here is a basic loop to get you started:
Code:
Dim lngDaysCount As Long
Dim i As Long
lngDaysCount = 20
For i = 1 To lngDaysCount
Debug.Print Format(DateAdd("d", i, Now), "mm/dd/yyyy")
Next
-
Dec 29th, 2011, 12:46 PM
#5
Thread Starter
Addicted Member
Re: List of Dates
this seems to work
Code:
Dim i As Integer
Private Sub Form_Load()
i = 1
lstDates.AddItem Date
Do
lstDates.AddItem Date + i
i = i + 1
Loop Until i = 67
End Sub
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 29th, 2011, 12:48 PM
#6
Frenzied Member
Re: List of Dates
 Originally Posted by seditives
oh right sorry I am using good old VB6 but haven't been for long so i am not to sure how ome thing work with the lang.
Yes I know how to make today "Date" and "Format" which I wont have to do as the default format is dd/mm/yyyy and yes I know and have used most of the functions of the ListBox.
I have searched the web but can't seem to find much so can you please direct me to a good source or give me some tips on how this can be best achieved.
Code:
Dim i As Integer
Private Sub Form_Load()
i = 1
lstDates.AddItem Date
Do
lstDates.AddItem Date + 1
i = i + 1
Loop Until i = 67
End Sub
This is my attempt ......if only in a idealistic world 
nice start ... look how close you where to the tip tyson gave you
and yes the world can be almost that simple
i hate writing code in these small windows so i'll be back shortly.
please hold your question is important to use...
-
Dec 29th, 2011, 12:54 PM
#7
Frenzied Member
Re: List of Dates
honey i'm home
Code:
Dim i As Integer
Private Sub Form_Load()
i = 1
lstDates.AddItem Now()
Do
lstDates.AddItem Now() + 1
i = i + 1
Loop Until i = 67
End Sub
look date is actually now()
and now()+1 actually works
whoo hoo
only problem is that now has a time element
so you need to format it
even if your machine is in the correct date format other arenot and you need to be in control
little ammendments are chargable things in the big bad world and wee fixes too!
now can you show us the completed work with formatting
come on the programmers!
here to talk ( and it appears encourage! )
Last edited by incidentals; Dec 29th, 2011 at 12:55 PM.
Reason: missed those pesky brackets out
-
Dec 29th, 2011, 12:56 PM
#8
Thread Starter
Addicted Member
Re: List of Dates
Now I have it working in its simplist form how would I go about variabling (yes thi i a made up word) the list up so the uer has full control, in other words what can be chnaged while the program is running.
things such as date format (seems a hard one)
number of dates shown in the list (I can already think of a way)
etc (if a list of dates can be controlled in other ways apart from looks )
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 29th, 2011, 12:59 PM
#9
Frenzied Member
Re: List of Dates
yes some vbs have date and time as enities they mess with now()
but well done for that unexpected WIN
who knew you had it in you?
anyway please complete the format thing as it would be benefitial to be able to do
here to talk ( and as you can see give PRAISE where praise is due )
on that note please remember when you have finished mark your post as closed and do not forget to rate those who helped you to help yourself!
-
Dec 29th, 2011, 01:07 PM
#10
Frenzied Member
Re: List of Dates
come on do the format thing
a=format (now(),a string in the form of the date structure you want)
the string is a quoted thing "something"
the parts are separators like - . , : characters
and the date parts are hours minutes seconds days months years
hours are h or hh for 9 or 09
days are d dd or ddd for 1 01 and monday (if it is a monday)
try formatting now() into thursday the 24 of february 2011
or anything other than 24/02/2011
go on "I dare yah"
oh yes the question
you could use a date picker to select the dates to select the start date
but dont run just yet get the formatting done first or they will be no more help
here to talk ( did you think the threat will work .. do yah , do yah? )
-
Dec 29th, 2011, 01:10 PM
#11
Thread Starter
Addicted Member
Re: List of Dates
Sorted =D
and I changed the format to a good old fashion way I remember and should be easier on the brain (tiny brain) when it comes to variables.
Code:
Private Sub Form_Load()
i = 1
lstDates.AddItem Format$(Now, "dddd mmmm yyyy")
Do
lstDates.AddItem Format$(Now + i, "dddd mmmm yyyy")
i = i + 1
Loop Until i = 100
End Sub
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 29th, 2011, 01:17 PM
#12
Re: List of Dates
 Originally Posted by incidentals
yes some vbs have date and time as enities they mess with now()
Care to explain?
-
Dec 29th, 2011, 01:18 PM
#13
Frenzied Member
Re: [RESOLVED] List of Dates
the loop could be a for loop instead
Code:
private sub form_load()
x=100
for d=date to date+x
lstdates.additem format(d,"dd/mm/yyyy")
next
end sub
what exactly does a date dddd mmmm yyyy look like
and is it usefull
here to talk
-
Dec 29th, 2011, 01:21 PM
#14
Re: [RESOLVED] List of Dates
@incidentals:
Where is you variable declarations?
-
Dec 29th, 2011, 01:24 PM
#15
Re: [RESOLVED] List of Dates
 Originally Posted by incidentals
what exactly does a date dddd mmmm yyyy look like
and is it usefull
Best way to find out is by actually trying. And of course it could be usefull to see full weekday/month name.
-
Dec 29th, 2011, 01:26 PM
#16
Thread Starter
Addicted Member
Re: [RESOLVED] List of Dates
 Originally Posted by incidentals
the loop could be a for loop instead
Code:
private sub form_load()
x=100
for d=date to date+x
lstdates.additem format(d,"dd/mm/yyyy")
next
end sub
what exactly does a date dddd mmmm yyyy look like
and is it usefull
here to talk
TY for new code, much better made little adjustment to format
Code:
Dim x As Integer
Private Sub Form_Load()
x = 100
For d = Date To Date + x
lstDates.AddItem Format$(d, "dddd, dd mmmm yyyy")
Next
End Sub
oh and this appears like this : Thursday, 29 December 2011
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 29th, 2011, 01:32 PM
#17
Thread Starter
Addicted Member
Re: [RESOLVED] List of Dates
Dim x As Integer
Dim DateFormat As String
Private Sub Form_Load()
DateFormat = "dddd, dd mmmm yyyy"
x = 100
For d = Date To Date + x
lstDates.AddItem Format$(d, DateFormat)
Next
End Sub
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 29th, 2011, 01:43 PM
#18
Frenzied Member
Re: [RESOLVED] List of Dates
well done
now don't forget to rate the posts that helped
here to talk
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|