MonthView DayBold from FileListBox?
I have a FileList Box which shows multiple textfiles that are basically dates for a calender program. The format is 01-02-2010.txt, for example. I can trim and replace the variable to convert that to 01/02/2010 which is a date I wish to make bold on the MonthView.
Can someone help with looping through the FileListBox entries and applying those to make the corresponding dates on the MonthView bold so it will indicate which dates have text entries against them?
Thanks :)
Re: MonthView DayBold from FileListBox?
I think this will give you some idea: :wave:
Code:
Option Explicit
Private Sub Command1_Click()
Dim newDate As Date
Dim i As Integer
For i = 0 To File1.ListCount - 1
'// you have to convert the filename from File1.List(i) to the date type, after making the necessary changes, and store it to the variable newdate
newDate = DateSerial(2010, 1, 1) '~~~> Here, I am using a sample date for testing. But you have to use the date from the filename here
MonthView1.DayBold(newDate) = True '~~> Making the date as Bold
Next i
End Sub
Re: MonthView DayBold from FileListBox?
Quote:
Originally Posted by
akhileshbc
I think this will give you some idea: :wave:
Code:
Option Explicit
Private Sub Command1_Click()
Dim newDate As Date
Dim i As Integer
For i = 0 To File1.ListCount - 1
'// you have to convert the filename from File1.List(i) to the date type, after making the necessary changes, and store it to the variable newdate
newDate = DateSerial(2010, 1, 1) '~~~> Here, I am using a sample date for testing. But you have to use the date from the filename here
MonthView1.DayBold(newDate) = True '~~> Making the date as Bold
Next i
End Sub
Thanks for the reply
I have it looping through with a new date appearing every loop in the variable "newDate below. The date is in the format "03/02/2010"
MonthView1.DayBold(newDate) = True
Having finished looping, none of the dates are showing bold on the MonthView. The strange thing is if I run it again (on the command button) it works. I've added MonthView1.Refresh, but that doesn't help
Ideally, I want to have the code in the form load procedure (or maybe call it from there) so it will run at form load. I've tried it in the form load, but as with the command button it doesn,t work first time round. Any ideas?
Re: MonthView DayBold from FileListBox?
Re: MonthView DayBold from FileListBox?
Show me the exact code that you are using...
Re: MonthView DayBold from FileListBox?
Thanks koolsid,
Code:
Private Sub Command1_Click()
Dim BoldDay As String
Dim newDate As String
Dim i As Integer
For i = 0 To File1.ListCount - 1
BoldDay = File1.List(i)
BoldDay = Left(BoldDay, 10)
BoldDay = Replace(BoldDay, "-", "/")
newDate = BoldDay
MonthView1.DayBold(newDate) = True
Next i
End Sub
I'm currently testing this behind a button, but will add it to or call it from the form load. I know the editing of the "BoldDay" variable could probably be done a lot prettier, but I was trying to see it change as I stepped through. Like I said before "newDate" ends up right as I can see but it only applies the DayBold on the second execution - weird!
Re: MonthView DayBold from FileListBox?
The problem is likely to be caused by your use of a String variable to store a Date value - which gives a very high chance that the MonthView will think you meant an entirely different date.
For more information, see the article Why are my dates not working properly? from our Classic VB FAQs (in the FAQ forum)
When converting a String (like you get from File1.List(i)) to a Date, you should use DateSerial, as shown at the end of the FAQ article.
Re: MonthView DayBold from FileListBox?
Changed it to
Code:
Dim newDate as date
program still runs as before.....(more head scratching!!)
Re: MonthView DayBold from FileListBox?
That is a good start, but the problem is still there because you haven't attempted to eliminate it (by using DateSerial or similar), you have simply moved the problem from the DayBold line to the one before.
The FAQ article explains all that, and you really should read it.
Just to check that it is the cause, use this rather than newDate = BoldDay:
Code:
newDate = DateSerial(2010, 1, 27)
..and then look at this month.
Re: MonthView DayBold from FileListBox?
Quote:
Originally Posted by
si_the_geek
That is a good start, but the problem is still there because you haven't attempted to eliminate it (by using DateSerial or similar), you have simply moved the problem from the
DayBold line to the one before.
The FAQ article explains all that, and you really should read it.
Just to check that it is the cause, use this rather than
newDate = BoldDay:
Code:
newDate = DateSerial(2010, 1, 27)
..and then look at this month.
I substituted what you suggested and it gave me the same result namely 27/01/2010. My previous attempt seems to give me the correct date format as on the second execution it sets the correct day to bold. What I can't understand (and there's lots! :)) is why it doesn't apply it first time round.
I put the same code under the form load procedure - but as that only execute once, not surprisingly it does not work.
I've read through your article and appreciate the importance of getting the format right, but it still has not helped in my understanding of why it is not working correctly. It's not the article - just my current understanding....I'll find the answer, but I may be gone a while....:D
Re: MonthView DayBold from FileListBox?
Quote:
Originally Posted by
donthe1
I substituted what you suggested and it gave me the same result namely 27/01/2010.
Did it make it bold correctly, or did it wait til the second attempt too?
Quote:
I've read through your article and appreciate the importance of getting the format right,
It's not about getting the format right, it is about understanding that a Date will never have a format - but a String which is meant to represent a date value will, and converting it to a Date is not a reliable thing to do (and unless you have explicit code to convert it, it is very unsafe).
Re: MonthView DayBold from FileListBox?
No, it only showed as bold on the second execution as well.
I know it's not a refresh thing as I've already tried refreshing the MonthView but that has no effect on the first pass.....
Re: MonthView DayBold from FileListBox?
Do you mean with MonthView1.Refresh? (if not, try it)
Something else to try is to change the month that is displaying, and then change it back, eg:
Code:
Dim datOldValue as Date
datOldValue = MonthView1.Value
MonthView1.Value = DateAdd("m", 1, MonthView1.Value)
MonthView1.Value = datOldValue
Re: MonthView DayBold from FileListBox?
Yes, MonthView1.Refresh
I'll try your other suggestion and get back.......
Re: MonthView DayBold from FileListBox?
Try it inside a command button's click event... Check if that works or not... :wave: