nested If statments!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angelina

    nested If statments!!

    Hi,

    I need some help in writing a 'if-then-else' statement.
    I currently have wrote one that looks something like this..

    If Combobox1 = xxx and textbox1 <> "" then
    'run stored procedure 1 to obtain the relevant
    records and place them in a datagrid.
    elseif combox1 = yyy and textbox2 <> "" or textbox3 <> ""
    then
    'run stored procedure 2 to obtain the relevant
    records and place them in a datagrid.
    elseif combox1 = zzz and textbox4 <> "" then
    'run stored procedure 3 to obtain the relevant
    records and place them in a datagrid.


    what i want to do is to also include some nested if
    statments to ensure that a message box is displayed if any
    of the textboxes (Where the parameter is obtained for the
    stored procedure) is empty.

    I also wanted to know how to diplay a message if the
    result of the sproc is empty.

    any advise and help is appreciated.

    thx in advance
  • Cor

    #2
    Re: nested If statments!!

    Hi Angelina,

    Looking at the code I think I would do it in the way I have typed in direct
    beneath (so not tested or something)

    This procedure you can make endless therefore.

    I hope this solves your problem?

    Cor
    \\\
    if Combobox1.text = xxx then
    if myproc(textbox1 , nothing) = true then
    'run stored procedure 1
    end if
    elseif
    if Combobox1.text = yyy then
    if myproc(textbox2 , textbox3) = true then
    'run procedure 2
    etc etc
    ////
    \\\
    Private Function MyProc (byval text1 as textbox, byval text2 as textbox) as
    boolean
    if Not text2 Is Nothing then
    if text2.text ="" then
    messagebox.show (error)
    return false
    end if
    end if
    if text1.text = "" then
    messagebox.show (error)
    return false
    end if
    return true
    end function
    ///[color=blue]
    >
    >
    > what i want to do is to also include some nested if
    > statments to ensure that a message box is displayed if any
    > of the textboxes (Where the parameter is obtained for the
    > stored procedure) is empty.
    >
    > I also wanted to know how to diplay a message if the
    > result of the sproc is empty.
    >
    > any advise and help is appreciated.
    >
    > thx in advance[/color]


    Comment

    • Angelina

      #3
      Re: nested If statments!!

      Hi Cor,

      thx for the code,
      Im a liitle confused on how MyProc works though!!.
      How do i ensure that for the second part of my if
      stataments a message box is displayed if either one of my
      textboxes are empty (Or both)?? (i.e i am using 2
      textboxes in this case so that the user can search by
      their first and last name)
      Does the code u showed me below only meant for a single
      textbox? if so how can it be modifed?

      also y do have a NOT for the first textbox (text2) and not
      for text1?? .....

      if Not text2 Is Nothing then
      if text2.text ="" then
      messagebox.show (error)
      return false
      end if
      end if
      if text1.text = "" then
      messagebox.show (error)
      return false
      end if
      return true
      end function


      One final question.....
      How do i integrate an if statment into your code that
      displays that the results of the query are empty? At the
      moment the datagrid just shows up empty with just the
      column headings? Im not to sure on how to code this?
      Can the if statment u provided me be extended to include
      any number of if staments e.g...

      if Combobox1.text = xxx then[color=blue]
      > if myproc(textbox1 , nothing) = true then
      > 'run stored procedure 1
      > end if[/color]
      [color=blue]
      >elseif
      >if Combobox1.text = yyy then
      > if myproc(textbox2 , textbox3) = true then
      > 'run procedure 2
      >etc etc[/color]

      [color=blue]
      >-----Original Message-----
      >Hi Angelina,
      >
      >Looking at the code I think I would do it in the way I[/color]
      have typed in direct[color=blue]
      >beneath (so not tested or something)
      >
      >This procedure you can make endless therefore.
      >
      >I hope this solves your problem?
      >
      >Cor
      >\\\
      >if Combobox1.text = xxx then
      > if myproc(textbox1 , nothing) = true then
      > 'run stored procedure 1
      > end if
      >elseif
      >if Combobox1.text = yyy then
      > if myproc(textbox2 , textbox3) = true then
      > 'run procedure 2
      >etc etc
      >////
      >\\\
      >Private Function MyProc (byval text1 as textbox, byval[/color]
      text2 as textbox) as[color=blue]
      >boolean
      >if Not text2 Is Nothing then
      > if text2.text ="" then
      > messagebox.show (error)
      > return false
      > end if
      >end if
      >if text1.text = "" then
      > messagebox.show (error)
      > return false
      >end if
      >return true
      >end function
      >///[color=green]
      >>
      >>
      >> what i want to do is to also include some nested if
      >> statments to ensure that a message box is displayed if[/color][/color]
      any[color=blue][color=green]
      >> of the textboxes (Where the parameter is obtained for[/color][/color]
      the[color=blue][color=green]
      >> stored procedure) is empty.
      >>
      >> I also wanted to know how to diplay a message if the
      >> result of the sproc is empty.
      >>
      >> any advise and help is appreciated.
      >>
      >> thx in advance[/color]
      >
      >
      >.
      >[/color]

      Comment

      • Cor

        #4
        Re: nested If statments!!

        Hi Angelina,

        I did not understand that the textboxes where from a datagrid, but I dont
        think that does make a difference.

        I take some rows from my code

        if myproc(textbox1 , nothing) = true then
        test if the result from the action done in myproc is true, it is false if
        there was an error and true if not
        (understand it think it does, I did not test it, I have written it direct in
        this mail, you have to test it yourself, but it is very standard, but there
        can be some thinking or typing errors)

        You can give to myprocedure two parameters, in the first test it was
        "textbox1" and "nothing" (because in your example there were one or two
        textboxes, but not always and therefore the second can be nothing)
        (And do not be afraid, only the place(reference ) of the textbox is
        transported not the textbox itself)

        In the procedure is
        Private Function MyProc (byval text1 as textbox, byval text2 as textbox)
        "text1" a reference to the first by you supplied textbox
        "text2" a reference to the second supplied textbox (can also be nothing)

        if Not text2 Is Nothing then
        because you can give "nothing" as textbox (no reference adres)
        In other words "If there is a textbox supplied then"
        (I wish there was something in the syntax as
        "If text2 Is Something" but it is not.)

        You give always a first textbox so that has not to be tested, althought the
        text can be empty.

        if text2.text =""
        This is an supplied textbox withouth text

        return false
        is the only thing you want to know before you start the SP

        return true
        There where in both(or one) textbox texts so you can go on.

        I hope this explains it?

        Cor


        Comment

        • angelina

          #5
          Re: nested If statments!!

          Hi Cor,

          thx for taking your time to explain your code. U have been
          a great help :o)
          As u can tell im a beginner on vb.net

          Can i just ask u if u know how i can check if a datatable
          is empty.

          i.e i want to include a statment in my if statment that
          checks if the results of the query is empty. If the result
          is empty i want a label displayed to the user that
          states 'no records were found' rather than just displaying
          an empty datagrid.

          thx in advance
          [color=blue]
          >-----Original Message-----
          >Hi Angelina,
          >
          >I did not understand that the textboxes where from a[/color]
          datagrid, but I dont[color=blue]
          >think that does make a difference.
          >
          >I take some rows from my code
          >
          >if myproc(textbox1 , nothing) = true then
          >test if the result from the action done in myproc is[/color]
          true, it is false if[color=blue]
          >there was an error and true if not
          >(understand it think it does, I did not test it, I have[/color]
          written it direct in[color=blue]
          >this mail, you have to test it yourself, but it is very[/color]
          standard, but there[color=blue]
          >can be some thinking or typing errors)
          >
          >You can give to myprocedure two parameters, in the first[/color]
          test it was[color=blue]
          >"textbox1" and "nothing" (because in your example there[/color]
          were one or two[color=blue]
          >textboxes, but not always and therefore the second can be[/color]
          nothing)[color=blue]
          >(And do not be afraid, only the place(reference ) of the[/color]
          textbox is[color=blue]
          >transported not the textbox itself)
          >
          >In the procedure is
          >Private Function MyProc (byval text1 as textbox, byval[/color]
          text2 as textbox)[color=blue]
          >"text1" a reference to the first by you supplied textbox
          >"text2" a reference to the second supplied textbox (can[/color]
          also be nothing)[color=blue]
          >
          >if Not text2 Is Nothing then
          > because you can give "nothing" as textbox (no[/color]
          reference adres)[color=blue]
          >In other words "If there is a textbox supplied then"
          >(I wish there was something in the syntax as
          >"If text2 Is Something" but it is not.)
          >
          >You give always a first textbox so that has not to be[/color]
          tested, althought the[color=blue]
          >text can be empty.
          >
          > if text2.text =""
          >This is an supplied textbox withouth text
          >
          >return false
          >is the only thing you want to know before you start the SP
          >
          >return true
          >There where in both(or one) textbox texts so you can go[/color]
          on.[color=blue]
          >
          >I hope this explains it?
          >
          >Cor
          >
          >
          >.
          >[/color]

          Comment

          • Cor

            #6
            Re: nested If statments!!

            Hi angelina,

            if ds.tables(0).co unt = 0
            then there is no table
            if ds.tables(0).ro ws.count=0
            then there are no rows,

            I do not know what it is in your case.

            If you get an error message, because i do not know how you load the
            datatable in your dataset.
            But I think it is one of these.

            Just try.

            I hope this works?

            Cor




            Comment

            Working...