Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Search/Evaluate My.Settings.StringCollection

Search/Evaluate My.Settings.StringCollection

Scheduled Pinned Locked Moved Visual Basic
csharpdotnetvisual-studiotestingbusiness
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 4372331
    wrote on last edited by
    #1

    I wrote a "widget" to report sales data, etc. I need to make some calculations based on business days to date this month. Business days are Mon-Fri, minus any holidays. Holidays are defined in my.settings, using a string collection. The function below iterates through the days of the current month until it reaches today. For each iteration, it checks to see if the day is a weekday, then checks to see if it is listed in my.settings.holidays. If it is a weekday, and not a holiday, the counter is incremented. If it is a holiday I receive a message "Holiday". This works exactly as I expect on my dev machine. However, when running the widget on any other machine, the "IF" statement that checks the holidays never evaluates to true. Any ideas anybody? Am I missing an import statement?

    Protected Overridable Function CountBusinessDays() As Integer
        Dim BusDays As Integer
        Dim RefMonth As Integer = Month(Now)
        Dim CalcDate As Date = DateSerial(Year(Now), Month(Now), 1)
        Do While Month(CalcDate) = RefMonth
            Dim wkday As Integer = Weekday(CalcDate)
            If wkday <> 1 And wkday <> 7 Then
                If Not My.Settings.Holiday.Contains(CalcDate.ToString) Then
                    BusDays = (BusDays + 1)
                Else : MsgBox("Holiday") 'For testing....
                End If
            End If
            If CalcDate = Date.Today Then Exit Do
            CalcDate = CalcDate.AddDays(1)
        Loop
        Return BusDays
    End Function
    

    We use Visual Studio 2005, and have .Net framework 3.5 installed on all machines.

    P 1 Reply Last reply
    0
    • M Member 4372331

      I wrote a "widget" to report sales data, etc. I need to make some calculations based on business days to date this month. Business days are Mon-Fri, minus any holidays. Holidays are defined in my.settings, using a string collection. The function below iterates through the days of the current month until it reaches today. For each iteration, it checks to see if the day is a weekday, then checks to see if it is listed in my.settings.holidays. If it is a weekday, and not a holiday, the counter is incremented. If it is a holiday I receive a message "Holiday". This works exactly as I expect on my dev machine. However, when running the widget on any other machine, the "IF" statement that checks the holidays never evaluates to true. Any ideas anybody? Am I missing an import statement?

      Protected Overridable Function CountBusinessDays() As Integer
          Dim BusDays As Integer
          Dim RefMonth As Integer = Month(Now)
          Dim CalcDate As Date = DateSerial(Year(Now), Month(Now), 1)
          Do While Month(CalcDate) = RefMonth
              Dim wkday As Integer = Weekday(CalcDate)
              If wkday <> 1 And wkday <> 7 Then
                  If Not My.Settings.Holiday.Contains(CalcDate.ToString) Then
                      BusDays = (BusDays + 1)
                  Else : MsgBox("Holiday") 'For testing....
                  End If
              End If
              If CalcDate = Date.Today Then Exit Do
              CalcDate = CalcDate.AddDays(1)
          Loop
          Return BusDays
      End Function
      

      We use Visual Studio 2005, and have .Net framework 3.5 installed on all machines.

      P Offline
      P Offline
      paas
      wrote on last edited by
      #2

      How is your 'Holiday' setting originally getting populated? I am wondering if maybe the string you expect simply is not in the User.Config on the "other" machine(s). Have you checked the user.config on the other machines to see if that setting is populated?

      M 1 Reply Last reply
      0
      • P paas

        How is your 'Holiday' setting originally getting populated? I am wondering if maybe the string you expect simply is not in the User.Config on the "other" machine(s). Have you checked the user.config on the other machines to see if that setting is populated?

        M Offline
        M Offline
        Member 4372331
        wrote on last edited by
        #3

        Excellent thing to check. However, I have already checked that the holidays are there. The 'Holidays' are pre-populated with some default values at build time. The user can change them at will. The settings are there, I verified this with:

        For each st as string in My.Settings.Holidays
        msgbox(st)
        Next

        The messages show the correct dates, which reflect any changes made on the specific machine. I also have user settings for fore and back colors, window location, etc. which are always applied correctly. I also tried aggregating all the holidays into one string and search it using 'InStr'. Once again, this worked fine on the dev machine but not others. Does the problem lie in the fact that I am comparing a "date.tostring" with a "string"? But it does work on the dev machine.... :sigh:

        P 1 Reply Last reply
        0
        • M Member 4372331

          Excellent thing to check. However, I have already checked that the holidays are there. The 'Holidays' are pre-populated with some default values at build time. The user can change them at will. The settings are there, I verified this with:

          For each st as string in My.Settings.Holidays
          msgbox(st)
          Next

          The messages show the correct dates, which reflect any changes made on the specific machine. I also have user settings for fore and back colors, window location, etc. which are always applied correctly. I also tried aggregating all the holidays into one string and search it using 'InStr'. Once again, this worked fine on the dev machine but not others. Does the problem lie in the fact that I am comparing a "date.tostring" with a "string"? But it does work on the dev machine.... :sigh:

          P Offline
          P Offline
          paas
          wrote on last edited by
          #4

          Does the problem lie in the fact that I am comparing a "date.tostring" with a "string"? But it does work on the dev machine.... That may very well be the problem, since the 'ToString()' can do a default conversion to different formats on different machines. Since you know what the date format used is within the 'Holiday' setting, you should ensure that you convert to that format with ToString. For example, if your Holiday date string format is YYYYMMDD, you could do CalcDate.ToString("yyyyMMdd") in your conditional statement.

          M 1 Reply Last reply
          0
          • P paas

            Does the problem lie in the fact that I am comparing a "date.tostring" with a "string"? But it does work on the dev machine.... That may very well be the problem, since the 'ToString()' can do a default conversion to different formats on different machines. Since you know what the date format used is within the 'Holiday' setting, you should ensure that you convert to that format with ToString. For example, if your Holiday date string format is YYYYMMDD, you could do CalcDate.ToString("yyyyMMdd") in your conditional statement.

            M Offline
            M Offline
            Member 4372331
            wrote on last edited by
            #5

            Thanks! That is it. I had tried '.toshortdatestring' and a few others, and none worked. For some reason I never thought of simply formatting the string.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups