Results 1 to 15 of 15

Thread: MonthView DayBold from FileListBox?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Lightbulb 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


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: MonthView DayBold from FileListBox?

    I think this will give you some idea:
    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

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Re: MonthView DayBold from FileListBox?

    Quote Originally Posted by akhileshbc View Post
    I think this will give you some idea:
    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?


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Re: MonthView DayBold from FileListBox?

    Help !!!.....


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: MonthView DayBold from FileListBox?

    Show me the exact code that you are using...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    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!


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Re: MonthView DayBold from FileListBox?

    Changed it to

    Code:
    Dim newDate as date
    program still runs as before.....(more head scratching!!)


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.
    Last edited by si_the_geek; Jan 27th, 2010 at 10:32 AM.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Re: MonthView DayBold from FileListBox?

    Quote Originally Posted by si_the_geek View Post
    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....


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: MonthView DayBold from FileListBox?

    Quote Originally Posted by donthe1 View Post
    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?

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

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

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


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Re: MonthView DayBold from FileListBox?

    Yes, MonthView1.Refresh
    I'll try your other suggestion and get back.......


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  15. #15
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: MonthView DayBold from FileListBox?

    Try it inside a command button's click event... Check if that works or not...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width