VB6 DayBold

By bobboland ·
I'm VERY new to VB (and programming). I have a "Journal" application that creates/opens an RTF file in a RichTextBox when you click a date on the MonthView control. If there is any text in the file, it is automatically saved as that date & ".rtf". (i.e. 11.01.2007.rtf) Otherwise it is deleted. How can I get
MonthView to DayBold the dates that have corresponding files?
I guess I should mention that the files are saved in a directory named from the year. (i.e. ..\2007\11.01.2007.rtf)

Thanks in advance

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Can I make a suggestion?

by scott_heath In reply to VB6 DayBold

To avoid having 18000 files created, you should use a database. Are you programming in .NET? I'm thinking you are, so you can use SQLCE to create a self-contained DB that doesn't require a DB server to be running. You just have to have the SQLCE runtimes installed, which you can make a prerequisite when running the installer.

Then you can have a table for each yr-month, ie 200711, 200712, 200801, etc. You include code to create the table when a day is click on in a new month. When a month is changed a query checks to see what days for that month have data and bold the days.

I couldn't find an easy way to make the days bold in my 5 minutes of messing around. I think that's going to be some serious work. But storing your data in a DB is a must. File system access to that many files is going to be a real beating.

Collapse -


by scott_heath In reply to Can I make a suggestion?

OK, I found something. You can bold days easily if you are using the MonthCalendar control. Check out this code snippet:

Dim list As New List(Of Date)
MonthCalendar1.BoldedDates = list.ToArray

Let me know if you have questions. Obviously using a DB makes your program initially more complex, but it will be a better learning experience and more stable.

Collapse -


by bobboland In reply to VB6 DayBold

...I'm using VB6. Thats why I titled the post;
"VB6 DayBold".
This is an update to an existing application.
I have no interest in re-writing it, I would just like to DayBold the dates with corresponding files. (with MonthView)
Thanks guys

Collapse -


by scott_heath In reply to Actually...

Sorry about that. I guess I saw the VB and not the 6! I'll look into it tomorrow.

Collapse -

Let me try again...

by scott_heath In reply to Actually...

Here is the sample code. I created a folder called c:\test\2007 and added some files to it for Oct, Nov, & Dec 2007. When scrolling between months it bolded the days for the files as needed. You'll need to add logic in case the year folder doesn't exist yet. You'll also need to work out the whole 'click' thing. They didn't have an event for monthchange or whatever. You could write an an if..then so if the sMonth hasn't changed since the last click it doesn't parse the files again. Or maybe it should. You'll also need to add a refernece to the Windows Script Host Object Model. Anyway, I hope this helps, let me know if I can do anything else.

Private Sub MonthView1_Click()
Dim sFolder, sMonth As String
Dim fso, Folder, Files As Variant

sFolder = "c:\test\" & MonthView1.Year
sMonth = MonthView1.Month

Set fso = CreateObject("Scripting.FileSystemObject")
Set Folder = fso.GetFolder(sFolder)
Set Files = Folder.Files

For Each File In Files
Dim sFile, sDate As String
sFile = File.Name
If Mid(sFile, 1, 2) = sMonth Then
sDate = Mid(sFile, 1, 2) & "/" & Mid(sFile, 4, 2) & "/" & Mid(sFile, 7, 4)
MonthView1.DayBold(sDate) = True
End If

End Sub

Collapse -


by bobboland In reply to Let me try again...

Thank you Scott. I've posted this question
on several forums around the www, and you are the only one that came up with a solution.
I don't have time to try it right now, but I'll get on it this evening. I think if I put it in the "SelChange" event; it should work nicely.
Thanks again, your THE MAN!!

Collapse -

No problem

by scott_heath In reply to WOW

I tried the selchange, but it seemed to be looking for an actual day selection change. When I scrolled between the months it did not update the bolded days.

I'm glad I could help. If you have questions or you find a way to make it update by changing months without using the click even, let me know.

Collapse -


by bobboland In reply to No problem

I've been playing with your code.
I've tried it with "MouseMove" and "DateClick".
It works real well the first time. It bolds the dates that have corresponding files, but...
(Are you ready for the but)
Any date that you click after that "Bolds" and stays bold whether it has a file or not.
Any Ideas?
Thanks again

Collapse -

I'll give it a whack...

by scott_heath In reply to Hmmm

I don't have your code, so it's hard to say. So we can do a couple of things. You can email me the source code, I am contactable through my profile, or you can provide me snippets here you think might be useful. If you have some other code that bolds the day when clicked or something then the code I wrote won't un-bold it if a file is never created.

We should move the code that scans the files to it's own sub routine and work in a call after new journal entries are submitted.

Collapse -

1st Try

by bobboland In reply to I'll give it a whack...

This is a very small part of the project.
There are 14 forms and 15 modules. Thats a lot of code to mail out.
This is what I tried originally, but I can't
figure out why I'm getting a runtime error 13
on the line;
Set fso_folder = fso.GetFolder(strDirPath)
I've checked the contents of strDirPath and it
contains exactly wht it should.

Dim fso_folder As Folder
Dim fso_file As File
Dim i As Long
Dim file_names() As String
Dim strDirPath As String
Dim strYear As String
strYear = Format(MonthView1.Value, "yyyy")
strDirPath = strCad & "\YLD\" & strName & "\Data\Jrnl\" & strYear

Set fso = New FileSystemObject

Set fso_folder = fso.GetFolder(strDirPath) 'Runtime Error 13 -- Type Mismatch Here

ReDim file_names(1 To fso_folder.Files.Count)
i = 1
For Each fso_file In fso_folder.Files

file_names(i) = fso_file.Name

MonthView1.DayBold(fso_file.Name) = True
i = i + 1

Next fso_file

Why would that be a mismatch, and would this even work if it wasn't?
Thanks for the help Scott. This is the very last piece of the puzzle, and I'm finished.
I SOOO want to be finished.

Related Discussions

Related Forums