Skip to content

Instantly share code, notes, and snippets.

@darkodemic
Last active April 25, 2017 19:05
Show Gist options
  • Save darkodemic/8992fb2b4c3e70edb2140064c3dddece to your computer and use it in GitHub Desktop.
Save darkodemic/8992fb2b4c3e70edb2140064c3dddece to your computer and use it in GitHub Desktop.
Domaci zadatak iz Uvoda u Objektno Programiranje
Public Class Form1
//Generisanje niza bez onih pozitivnih i negativnih suma
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim i As Integer 'Brojac
Dim randomValue As Integer 'Var gde cuvamo nasu random vrednost
Dim upperbound As Integer = 40 'Gornja granica
Dim lowerbound As Integer = -10 'Donja granica
For i = 1 To 40 Step 1 'Idemo 40 puta sa promenom od 1 i svaki put generisemo nasumican broj izmedju nasih granica
randomValue = CInt(Math.Floor((upperbound - lowerbound + 1) * Rnd())) + lowerbound
TextBox1.Text += Str(randomValue) + " " 'Ispisujemo taj broj, tacnije dodajemo ga na vec postojuci sadrzaj textbox1
Next
End Sub
Private Sub Button_Color_Click(sender As Object, e As EventArgs) Handles Button3.Click, Button4.Click, Button5.Click
Button6.BackColor = sender.BackColor 'Menjamo boju u zavisnosti od dugmeta koje ga je poslalo
End Sub
//Generisanje nasumicnih nizova
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
Dim randomValue As Integer
Dim upperbound As Integer = 40
Dim lowerbound As Integer = -10
Dim sumaPoz As Integer = 0
Dim sumaNeg As Integer = 0
'Znam da je trazen "niz" ali ovde nema potrebe za njim posto nigde nam se ne trazi da cuvamo sve to kako bi kasnije iterirali kroz njega
'Jedna promenjiva je daleko bolja otpimizacija sto se tice memorije i performansi
For i = 1 To 30 Step 1
randomValue = CInt(Math.Floor((upperbound - lowerbound + 1) * Rnd())) + lowerbound
TextBox2.Text += Str(randomValue) + " "
If randomValue < 0 Then
sumaNeg += randomValue
Else sumaPoz += randomValue
End If
Next
TextBox3.Text = Str(sumaPoz)
TextBox4.Text = Str(sumaNeg)
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
Timer1.Start()
Else Timer1.Stop()
End If
End Sub
Public passCount As Integer = 1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim startLocationX As Integer = 9
Dim endLocationX As Integer = 110
If Label3.Location.X >= endLocationX Or Label3.Location.X < startLocationX Then
passCount += 1
End If
If passCount Mod 2 = 1 Then
'This is our first/third/fifth.. run so we go forward
Label3.Location = New Point(Label3.Location.X + 5, Label3.Location.Y)
Else
Label3.Location = New Point(Label3.Location.X - 5, Label3.Location.Y)
End If
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment