3 Replies - 687 Views - Last Post: 05 June 2014 - 12:14 PM Rate Topic: -----

#1 pensioenvizier   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 16-April 14

Problem with if statement

Posted 04 June 2014 - 02:16 AM

Guys,

I have a problem with a if statement. Look code

       If cbxHuis.Checked Then

            Dim waardehuisperjaar As Integer

            Dim looptijdhuis As Integer

            Dim stoplooptijdhuis As Integer

            Dim jaarhuis As Integer

            Dim waardehuis As Integer

            jaarhuis = CInt(txtJaarHuis.Text)

            looptijdhuis = CInt(txtLooptijdHuis.Text)

            waardehuis = CInt(txtWaardeHuis.Text)

            stoplooptijdhuis = jaarhuis + (looptijdhuis - 1)


            waardehuisperjaar = waardehuis / looptijdhuis

            stoplooptijdhuis = jaarhuis + (looptijdhuis - 1)

            REM periode 1 2 3

            If rustigjaar < stoplooptijdhuis And stoplooptijdhuis < 99 Then

                If jaarhuis < rustigjaar Then

                    If jaarhuis < stopjaar Then



                        For lengtehuisper1 = jaarhuis To stopjaar - 1

                            Chart1.Series("Huis").Points.AddXY(lengtehuisper1, waardehuisperjaar)

                        Next

                        For lengtehuisper2 = stopjaar To rustigjaar - 1

                            Chart2.Series("Huis").Points.AddXY(lengtehuisper2, waardehuisperjaar)
                        Next

                        For lengtehuisper3 = rustigjaar To stoplooptijdhuis

                            Chart3.Series("Huis").Points.AddXY(lengtehuisper3, waardehuisperjaar)


                        Next
                    End If


                End If

            End If


            REM periode 3

            If rustigjaar < stoplooptijdhuis And stoplooptijdhuis < 99 Then




                For lengtehuisper3 = jaarhuis To stoplooptijdhuis

                    Chart3.Series("Huis").Points.AddXY(lengtehuisper3, waardehuisperjaar)

                Next

            End If
       End if




I have 2 if statement in one block, but im struggling with if statement REM periode 123 and periode 3

As soon as all conditions are true in if statement REM periode 123 also the if statement periode 3 is true.
This means that chart 1 and 2 are correct but the values chart 3 in if statement REM periode 123 are being overwritten by REM periode 3 which gives a different output. Is there a way as soon as REM periode 3 is true the code stops, so it wont take the values of the if statement in REM periode 3 for chart 3

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with if statement

#2 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1824
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Problem with if statement

Posted 04 June 2014 - 02:27 AM

You can always have a boolean variable to check if the if the previous code was executed or not. Then use it to decide either to run the second if or not
'declare a boolean value set it to false

'comes a condition that can be true or not
     'if this block was executed, set the variable to tru
'end of block

'now if I have another condition here, I can check if the variable is true or false...

Was This Post Helpful? 1
  • +
  • -

#3 pensioenvizier   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 16-April 14

Re: Problem with if statement

Posted 05 June 2014 - 12:10 PM

Indeed this helped me. Thanks
Was This Post Helpful? 0
  • +
  • -

#4 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1824
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Problem with if statement

Posted 05 June 2014 - 12:14 PM

I am glad I could help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1