Jump to content

noob help VB program (IF loop)

Go to solution Solved by fizzlesticks,

The problem if that you are defining "Dim iMinWaarde As Integer" inside the function. You need this to be a global variable and only set to 999 once so it does not get redefined to 999 every time the timer goes off.

 

Edit: Or you can not define it at all and just read the value back from lblValMinimumTemperatuur.Text

hey people

 

somehow i got stuck at this piece of code. The problem is: the label that should be outputting the minimum value, keeps updating the same values as the current random generated value.  I guess its just a stupid error of me, but staring at it doesn't seem to help for me. (as i wrote it in Dutch, i tried to translate as much as possible in the comments)

Its visual basic 2010 express if it matters...

 

thanks

 

 

8be00160cb026f9bc1bd6eb58ef6bf6e.png

 

    'the error should be below here    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        Dim iMinWaarde As Integer        iMinWaarde = 999 'setting the minimum value higher than the maximum random-generated value 51        Dim iRndmGetal As Integer        iRndmGetal = rndm.Next(1, 51) 'make a random value in iRndmGetal between 1 and 51        Chart1.Series(0).Points.AddXY(Now, iRndmGetal) 'putting the current value in a chart (this works)        lblValHuidigeTemperatuur.Text = Convert.ToString(iRndmGetal) 'set the current-value label as the current-value random value        'what am i doing wrong in this IF below here?        If iRndmGetal < iMinWaarde Then 'if the current value is smaller then the minimum value,             iMinWaarde = iRndmGetal 'then say the minimum value equals the random value,            lblValMinimumTemperatuur.Text = Convert.ToString(iMinWaarde) 'now show it in the minimum value         End If    End Sub

build log: diagonalmod (RIP?)


i know i use many of these: ( ) and these: ... (i really do... (sry...) ) edit: and edits

Link to comment
https://linustechtips.com/topic/115381-noob-help-vb-program-if-loop/
Share on other sites

Link to post
Share on other sites

visual basic express 2010 ( VB) or do you mean like windows forms application?

extention is .vb

Edited by darkspeedy26

build log: diagonalmod (RIP?)


i know i use many of these: ( ) and these: ... (i really do... (sry...) ) edit: and edits

Link to post
Share on other sites

The problem if that you are defining "Dim iMinWaarde As Integer" inside the function. You need this to be a global variable and only set to 999 once so it does not get redefined to 999 every time the timer goes off.

 

Edit: Or you can not define it at all and just read the value back from lblValMinimumTemperatuur.Text

1474412270.2748842

Link to post
Share on other sites

The problem if that you are defining "Dim iMinWaarde As Integer" inside the function. You need this to be a global variable and only set to 999 once so it does not get redefined to 999 every time the timer goes off.

oooooooooooooooooooooooooooooooohhhhh ok thanks :D

build log: diagonalmod (RIP?)


i know i use many of these: ( ) and these: ... (i really do... (sry...) ) edit: and edits

Link to post
Share on other sites

...

Edit: Or you can not define it at all and just read the value back from lblValMinimumTemperatuur.Text

 

I am only seeing Visual Basic about 2 weeks in school now, and my teacher said it we HAD to turn that option off in the settings to prevent other problems. but yeah, if we could turn it on again it would have been an option ;)

build log: diagonalmod (RIP?)


i know i use many of these: ( ) and these: ... (i really do... (sry...) ) edit: and edits

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×