Jump to content

Visual basic simple Case statement question


karljv

Recommended Posts

Hello

 

I have a simple question. How to have the case statement execute more than one command? My code

 

Case x = 1

                TubaTemp = ((TubaTemp) + (RadikaTemp / (TubaTemp * 3))) + SoojusKadu

 

                Rad.Enabled = True

                RadikaTemp = CDec(Rad.Text)

                TTemp.Text = TubaTemp.ToString("N2")

                RTemp.Text = RadikaTemp

 

 

So it seems tu execute only the first mathematical thingy. All the rest ( Rad.enabled = true and downward) do not execute.

 

Thanks

Link to comment
Share on other sites

Okei, so i understood it completely wrong, instead of running only one line of code, it runs my entire timer1_tick code line. Why does it not select a case on every tick?

 

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

 

 

        Select Case x

            Case x = 0

                TubaTemp = ((TubaTemp) + (RadikaTemp / (TubaTemp * 3))) + SoojusKadu

                If SwitchCold > TubaTemp Then

                    RadikaTemp = 40

                End If

                If SwitchWarm < TubaTemp Then

                    RadikaTemp = 30

                End If

                Rad.Enabled = False

                TTemp.Text = TubaTemp.ToString("N2")

                RTemp.Text = RadikaTemp

            Case x = 1

                TubaTemp = ((TubaTemp) + (RadikaTemp / (TubaTemp * 3))) + SoojusKadu

                Rad.Enabled = True

                RadikaTemp = CDec(Rad.Text)

                TTemp.Text = TubaTemp.ToString("N2")

                RTemp.Text = RadikaTemp

 

        End Select

 

 

    End Sub

 

 

 

taking into account that (Dim x as integer) and on Form load x=0

Link to comment
Share on other sites

Case statements 'fall through', meaning that if you have a condition that matches a particular case, then that case and all cases below it will execute, unless you specify them not to.  This is the same for all languages with switch/case, not just VB.  That includes PHP.

 

So, how do you tell a case to execute without falling through to the next case?  You add a break statement to the end of that particular case's code.

Link to comment
Share on other sites

Why does it not select a case on every tick?

 

taking into account that (Dim x as integer) and on Form load x=0

 

You should have a static counter inside the Tick event.

 

Declare it as :

 

Static x As Integer

 

Then, you should increment it inside your Tick event, otherwise it will always only execute one segment, because x will remain the same

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.