Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Some help with If statement logic

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    Resolved [RESOLVED] [2005] Some help with If statement logic

    I know this should be really simple but I'm having trouble figuring out the logic.

    I have a form that can create scheduled tasks. To create the task the user must complete 3 different sections

    Days of Week
    Days of Month
    Task Command Line

    For the Days of Week and Days of Month there are various checkboxes they can check and I assign an Integer to the Tag property of each one.

    The Task Command line is a simple textbox

    Now, when they click the CREATE TASK button I want to check that they have selected at least one checkbox in the Days of Week and Days of Month sections as well as entered a command line

    I was doing this before

    Code:
            For Each Ctrl As Control In Me.GroupBox_DaysofMonth.Controls
                If TypeOf Ctrl Is CheckBox AndAlso DirectCast(Ctrl, CheckBox).Checked Then
                    DaysOfMonthValue = DaysOfMonthValue + CInt(DirectCast(Ctrl, CheckBox).Tag.ToString)
                End If
            Next
    
            For Each Ctrl As Control In Me.GroupBox_DaysofMonth.Controls
                If TypeOf Ctrl Is CheckBox AndAlso DirectCast(Ctrl, CheckBox).Checked Then
                    DaysOfWeekValue = DaysOfWeekValue + CInt(DirectCast(Ctrl, CheckBox).Tag.ToString)
                End If
            Next
    
    If DaysOfMonthValue + DaysOfWeekValue = 0 AndAlso Me.CommandToRun.Text.Equals(String.Empty) Then
    But I just realised that this allows them to select any number of checkboxes but leave the command line blank.

    Any advice appreciated
    ManagePC - the all-in-one PC management and inventory tool

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Some help with If statement logic

    Shouldn't that last line be OrElse rather than AndAlso? Surely you want to know where either one or the other is True.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    Re: [2005] Some help with If statement logic

    I tried that. But if the user selects checkboxes in the Days Of Week section , none in the Days Of Month section AND enters a command line it still says throws the error message
    ManagePC - the all-in-one PC management and inventory tool

  4. #4
    Fanatic Member Lerroy_Jenkins's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    661

    Re: [2005] Some help with If statement logic

    Well I am assuming that this is all run inside of a button_click event, so why not have a check.

    Are the appropriate CheckBoxes ticked? If yes then carry on.

    Is the Command Line Blank? If yes Carry on.

    Etc
    Lerroy

    "η β π", or "Eta Beta Pi" (Eat A Better Pie)

    01001000
    01000101
    01001100
    01010000


    My Own Code - WordCounter

    Useful Forum Links -Reputation - What is it?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    Re: [2005] Some help with If statement logic

    Well, I have to add up the values of the Tag properties anyway because it is used as a value by the WMI namespace Win32_ScheduledJob so it made sense to just check whether the combined value was 0 or not
    ManagePC - the all-in-one PC management and inventory tool

  6. #6
    Fanatic Member Lerroy_Jenkins's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    661

    Re: [2005] Some help with If statement logic

    Well it does seem like a good idea to me. but if it is not working, then you will have to change your idea. Unless there is something else I have missed.
    Lerroy

    "η β π", or "Eta Beta Pi" (Eat A Better Pie)

    01001000
    01000101
    01001100
    01010000


    My Own Code - WordCounter

    Useful Forum Links -Reputation - What is it?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    Re: [2005] Some help with If statement logic

    Ah well, I had to change it in the end as I realised I was COMPLETELY misunderstaning how WMI creates Scheduled Tasks
    ManagePC - the all-in-one PC management and inventory tool

  8. #8
    Fanatic Member Lerroy_Jenkins's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    661

    Re: [2005] Some help with If statement logic

    So it is all sorted?

    Mind Marking this thread resolved then please.

    Glad you have it sorted
    Lerroy

    "η β π", or "Eta Beta Pi" (Eat A Better Pie)

    01001000
    01000101
    01001100
    01010000


    My Own Code - WordCounter

    Useful Forum Links -Reputation - What is it?

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    Re: [2005] Some help with If statement logic

    Well, not yet no as I'm now using a 3rd party class that acts as a wrapper for the WMI Win32_ScheduledJob namespace. It's MUCH easier
    ManagePC - the all-in-one PC management and inventory tool

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