Anyone see the problem in this code to bold multiple dates?

kdawg219

Member
Joined
Oct 24, 2005
Messages
6
Programming Experience
1-3
i = 0
d = 0
For Each s In Directory.GetFiles((NewPath), "*.pdf")
myArray.Add(Mid(s, 12, 8))
xs = myArray.Item(i)
x = xs
i = i + 1
a = Mid(myArray.Item(d), 1, 4)
b = Mid(myArray.Item(d), 5, 2)
c = Mid(myArray.Item(d), 7, 2)
MsgBox(a & " " & b & " " & c)
calendarView.AnnuallyBoldedDates =
New System.DateTime() _
{
New System.DateTime(a, b, c, 0, 0, 0, 0)}
d = d + 1
Next

It is only showing the last date given as bold in the calendar rather than the 4 or more before it that go through the loop. Any ideas?
 
Where is your loop with "i"? While you are using "i" inside your code i can't see the adequate Loop unless it's happening somewhere else ...
Btw, don;t use overdated VB6 functions for string manipulation but rather use ".Substring" method instead "Mid"
However explain what you expect to happen in your code and i'll try to help you out

Regards ;)
 
Changed it

d is the counter to loop through, without it the app will only return 2005, 06, 01 instead of all the dates. Basically I have a directory, (C:\pdf), that contains pdf files. These filenames contain a string that represents a date. Example would be:
lala20050601yada.pdf
lala20050605yada.pdf
lala20050610yada.pdf
lala20050620yada.pdf
lala20050630yada.pdf
So I am trying to strip the dates out and bold the dates on a calendar control so for these examples the dates in June of 2005 that should be bold are 1, 5, 10, 20, and 30. What is happening is the 30th is the only date that is bold on the calendar control and I cannot figure out why the others aren't. Hope this makes sense and the changed code is below.


Dim
NewPath As String
NewPath = "C:\pdf"
Dim d, intStrip As Integer
Dim myArray As ArrayList = New ArrayList
Dim strFile, strYear, strMonth, strDay As String
d = 0
For Each strFile In Directory.GetFiles((NewPath), "*.pdf")
myArray.Add(strFile.Substring(11, 8))

intStrip = myArray.Item(d)
strYear = intStrip.ToString.Substring(0, 4)
strMonth = intStrip.ToString.Substring(4, 2)
strDay = intStrip.ToString.Substring(6, 2)
calendarView.AnnuallyBoldedDates =
New System.DateTime() _
{
New System.DateTime(strYear, strMonth, strDay, 0, 0, 0, 0)}
d = d + 1
Next
 
If you want a loop counter then use a For loop instead of a For Each loop. You are creating a new DateTime array with a single element each time through the loop:
VB.NET:
[SIZE=2] calendarView.AnnuallyBoldedDates = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.DateTime() _
{[/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.DateTime(strYear, strMonth, strDay, 0, 0, 0, 0)}[/SIZE]
I'm guessing that you actually mean to create a single array that contains all the dates. You need to create a single array or collection before the loop and then set an element or add an item in each iteration. Also what is this:
VB.NET:
[SIZE=2] myArray.Add(strFile.Substring(11, 8))[/SIZE]
I strongly suggest that you use the IO.Path class to manipulate file paths. I'm guessing that you are extracting a creation date from the file name. You might be better off using a FileInfo object to get the actual creation date, or else use IO.Path.GetFileNameWithoutExtension and then use Substring.
 
Back
Top