Questions

VB6 DayBold

Tags:
+
0 Votes
Locked

VB6 DayBold

bobboland
Hi,
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
  • +
    0 Votes
    scott_heath

    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.

    +
    0 Votes
    scott_heath

    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)
    list.Add("11/01/2007")
    list.Add("11/15/2007")
    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.

    +
    0 Votes
    bobboland

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

    +
    0 Votes
    scott_heath

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

    +
    0 Votes
    scott_heath

    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
    Next

    End Sub

    +
    0 Votes

    WOW

    bobboland

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

    +
    0 Votes
    scott_heath

    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.

    +
    0 Votes
    bobboland

    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

    +
    0 Votes
    scott_heath

    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.

    +
    0 Votes
    bobboland

    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.

    +
    0 Votes

    OK

    scott_heath

    I needed to start a new thread as we reached our max level!

    You typed your variables more strongly and changed some of the code up a bit. I'm reviewing it now and I'll get back to you.

    +
    0 Votes
    scott_heath

    I didn't get the type mismatch on the line you specified, i got it here:

    MonthView1.DayBold(fso_file.Name) = True

    The problem being the filename is "11.10.2007.rtf". That isn't going to work. That's why I included the code that turned it to a string that looks like "11/10/2007".

    +
    0 Votes
    bobboland

    I forgot to mention that I changed the way the file was being saved. (sorry) It seems RitchTextBox doesn't need the ".rtf" extension to know it's a ".rtf" file. The file name now looks like ; ..\2007\11.07.2007
    I've tried everything I can think of and still get runtime error 13 on the line I specified.

    "That's why I included the code that turned it to a string that looks like "11/10/2007"."

    May I see it?
    Am I on the right track?
    Thanks Again, Bob

    +
    0 Votes
    scott_heath

    Here is the original code I posted for you. See the line where I set the variable sDate. That splits the file name into a readable date for the monthview control.

    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
    Next

    End Sub

    +
    0 Votes
    bobboland

    Now I get it. I wasn't even quite sure what "sMonth" was for until just now. I'm not very familiar with "Mid". (or VB) The only programming experience I've had was with C,
    and that was WAY back when. With this code, I still have the problem with every date clicked "Bolds" and stays that way regardless of whether a file exists. It doesn't do that for you? I've searched the entire project and there is no DayBloding going on anywhere else. I would send you my code, but I don't think anyone but me could make heads or tails out of it. This is so frustrating. Thanks for bearing with me.

    +
    0 Votes
    bobboland

    I've tried all kinds of things to make the days without files "unbold", with no luck.
    If it's possible; how would I go about populating an array from a FileListBox and
    checking the dates from the array? That way
    I could refresh the array each time so it could recheck if the file exists? Does that make sense or am I grasping at straws?
    The way it is now; when the "day" is clicked a file is created. If nothing is written to the file then it is deleted when the next "day" is clicked, it stays BOLD because the file WAS there. Right?

    +
    0 Votes
    scott_heath

    I have only a snippet of code so I can't really say why it stays bold.

    Can you zip the vb6 project and send it to me? I promise I won't divuldge any secrets! :)

  • +
    0 Votes
    scott_heath

    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.

    +
    0 Votes
    scott_heath

    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)
    list.Add("11/01/2007")
    list.Add("11/15/2007")
    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.

    +
    0 Votes
    bobboland

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

    +
    0 Votes
    scott_heath

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

    +
    0 Votes
    scott_heath

    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
    Next

    End Sub

    +
    0 Votes

    WOW

    bobboland

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

    +
    0 Votes
    scott_heath

    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.

    +
    0 Votes
    bobboland

    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

    +
    0 Votes
    scott_heath

    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.

    +
    0 Votes
    bobboland

    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.

    +
    0 Votes

    OK

    scott_heath

    I needed to start a new thread as we reached our max level!

    You typed your variables more strongly and changed some of the code up a bit. I'm reviewing it now and I'll get back to you.

    +
    0 Votes
    scott_heath

    I didn't get the type mismatch on the line you specified, i got it here:

    MonthView1.DayBold(fso_file.Name) = True

    The problem being the filename is "11.10.2007.rtf". That isn't going to work. That's why I included the code that turned it to a string that looks like "11/10/2007".

    +
    0 Votes
    bobboland

    I forgot to mention that I changed the way the file was being saved. (sorry) It seems RitchTextBox doesn't need the ".rtf" extension to know it's a ".rtf" file. The file name now looks like ; ..\2007\11.07.2007
    I've tried everything I can think of and still get runtime error 13 on the line I specified.

    "That's why I included the code that turned it to a string that looks like "11/10/2007"."

    May I see it?
    Am I on the right track?
    Thanks Again, Bob

    +
    0 Votes
    scott_heath

    Here is the original code I posted for you. See the line where I set the variable sDate. That splits the file name into a readable date for the monthview control.

    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
    Next

    End Sub

    +
    0 Votes
    bobboland

    Now I get it. I wasn't even quite sure what "sMonth" was for until just now. I'm not very familiar with "Mid". (or VB) The only programming experience I've had was with C,
    and that was WAY back when. With this code, I still have the problem with every date clicked "Bolds" and stays that way regardless of whether a file exists. It doesn't do that for you? I've searched the entire project and there is no DayBloding going on anywhere else. I would send you my code, but I don't think anyone but me could make heads or tails out of it. This is so frustrating. Thanks for bearing with me.

    +
    0 Votes
    bobboland

    I've tried all kinds of things to make the days without files "unbold", with no luck.
    If it's possible; how would I go about populating an array from a FileListBox and
    checking the dates from the array? That way
    I could refresh the array each time so it could recheck if the file exists? Does that make sense or am I grasping at straws?
    The way it is now; when the "day" is clicked a file is created. If nothing is written to the file then it is deleted when the next "day" is clicked, it stays BOLD because the file WAS there. Right?

    +
    0 Votes
    scott_heath

    I have only a snippet of code so I can't really say why it stays bold.

    Can you zip the vb6 project and send it to me? I promise I won't divuldge any secrets! :)