karljv Posted October 9, 2011 Share Posted October 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248735-visual-basic-simple-case-statement-question/ Share on other sites More sharing options...
karljv Posted October 9, 2011 Author Share Posted October 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248735-visual-basic-simple-case-statement-question/#findComment-1277413 Share on other sites More sharing options...
KevinM1 Posted October 9, 2011 Share Posted October 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248735-visual-basic-simple-case-statement-question/#findComment-1277483 Share on other sites More sharing options...
HanneSThEGreaT Posted October 13, 2011 Share Posted October 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248735-visual-basic-simple-case-statement-question/#findComment-1278904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.