You are on page 1of 26

PANEVROPSKI UNIVERZITET APEIRON

FAKULTET POSLOVNE INFORMATIKE

Vanredne studije
Smjer „Poslovna informatika”

Predmet
Viši programski jezici i RAD alati
Programiranje u VB-u

„ RIJEŠENI PRIMJERI ”
(seminarski rad)

Predmetni nastavnik
Prof. dr Zoran Avramović

Student
Niko Đurić
Index br. 46-14/vpi

Bijeljina, Juli 2017.
SADRŽAJ

1. Načiniti program koji beskonačno sabira sve brojeve. ................................................ 3
2. Načiniti program koji određuje prosječnu vrijednost niza u listboxu od 10 brojeva. . 3
3. Načiniti program koji određuje da li je broj paran ili neparan. ................................... 4
4. Načiniti program koji omogućava prijavljivanje pomoću korisničkog imena i
lozinke. ................................................................................................................................... 5
5. Načiniti program koji prikazuje informacije o osobi. ................................................. 7
6. Načiniti program koji prikazuje godine u danima. ...................................................... 7
7. Načiniti program koji prikazuje funkcionalan digitalan sat. ....................................... 9
8. Načiniti program koji simulira instalaciju programa pomoću progress bara. ........... 10
9. Načiniti program koji predstavlja štopericu. ............................................................. 11
10. Načiniti program koji služi za ispravljanje pogrešnih riječi na engleskom jeziku. ... 12
11. Načiniti program koji prikazuje kalendar. ................................................................. 14
12. Načiniti program koji predstavlja mazewall igricu. .................................................. 15
13. Načiniti program koji prikazuje podjelu nagrada za ljetovanje kod ćerke I sina. ..... 16
14. Načiniti program koji prikazuje određivanje većeg broja u textboxu. ...................... 17
15. Načiniti program koji prikazuje minimalni element cjelobrojnog niza.................... 18
16. Načiniti program koji predstavlja povrsinu I obim pravouganika. ............................ 19
17. Načiniti program koji predstavlja upotrebu CPU u procentima. ............................... 21
18. Načiniti program pomoću kojeg je moguće slati email poruke. ................................ 22
19. Načiniti program koji predstavlja alarm. ................................................................... 24
20. Načiniti program koji predstavlja notepad, to jest tekstualnu aplikaciju. ................. 25
1. Načiniti program koji beskonačno sabira sve brojeve.

KOD:

Public Class Form1

Private Sub Izracunaj_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Izracunaj.Click
rezultat.Text = text1.Text + Val(text2.Text)

End Sub
End Class

2. Načiniti program koji određuje prosječnu vrijednost niza u listboxu
od 10 brojeva.

KOD:

Public Class Form1

Private Sub prosjek_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles prosjek.Click
Dim n(10) As Integer
Dim z As Integer
For i = 1 To 10
n(i) = Val(InputBox("Unesi" + Str(i) + ". element niza: "))
z = z + n(i)
Lista.Items.Add(n(i))

Next i
txtprosjek.Text = Str(z / 10)
End Sub
End Class
Private Sub obrisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles obrisi.Click
list.items.clear()

End Sub

3. Načiniti program koji određuje da li je broj paran ili neparan.

KOD:

Public Class Form1
Dim broj As Integer
Dim poruka As String
Private Sub btnodredi_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnodredi.Click
broj = txtbroj.Text
If broj Mod 2 = 0 Then
poruka = "BROJ JE PARAN"
Else
poruka = "BROJ JE NEPARAN"
End If
txtporuka.Text = poruka

End Sub
End Class

4. Načiniti program koji omogućava prijavljivanje pomoću korisničkog
imena i lozinke.

KOD:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If TextBox1.Text = "nikodjuric" And TextBox2.Text = "12345" Then
MsgBox("Sada ste logovani", MsgBoxStyle.Information, "Prijavi se")
Else
If TextBox1.Text = "" And TextBox2.Text = "" Then
MsgBox("Netacno korisnicko ime ili sifra", MsgBoxStyle.Critical,
"Greska")
Else
If TextBox1.Text = "" Then
MsgBox("Netacno korisnicko ime ili sifra", MsgBoxStyle.Critical,
"Greska")
Else
If TextBox2.Text = "" Then
MsgBox("Netacna sifra", MsgBoxStyle.Critical, "Greska")
Else
MsgBox("Netacno korisnicko ime ili sifra",
MsgBoxStyle.Critical, "Greska")

End If
End If
End If
End If
End Sub
End Class
5. Načiniti program koji prikazuje informacije o osobi.

KOD:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("Moje ime je Niko Djuric i rodjen sam 14.10.1995. godine")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub
End Class

6. Načiniti program koji prikazuje godine u danima.

KOD:

Public Class Form1

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles godineudanima.Click

End Sub

Private Sub btnizracunaj_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnizracunaj.Click
Dim inttxtgodine, intgodineudanima As Integer
'Nabavi informacije i stavi ih u varijablu intageinyears'
inttxtgodine = txtgodine.Text

intgodineudanima = inttxtgodine * 365

godineudanima.Text = "Vase godine u danima su: " & intgodineudanima
End Sub
End Class
7. Načiniti program koji prikazuje funkcionalan digitalan sat.
Public Class sat

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles vrijeme.Click
vrijeme.Text = TimeOfDay
End Sub

Private Sub Clock_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Timer1.Start()

End Sub
End Class
8. Načiniti program koji simulira instalaciju programa pomoću
progress bara.

KOD:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(1)
If ProgressBar1.Value = 100 Then
Label1.Text = "Instalacija uspjesna"
End If
Label2.Text = ProgressBar1.Value & (" &")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Timer1.Stop()
ProgressBar1.Value = 0
Label1.Text = "Programiranje Visual Basic"
Label2.Text = "0 %"
End Sub
End Class

9. Načiniti program koji predstavlja štopericu.

Public Class Form1

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
timer1.enabled = True
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Timer1.Enabled = False
Label1.Text = 0.0
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Label1.Text = Label1.Text + 0.01
End Sub
End Class

10.Načiniti program koji služi za ispravljanje pogrešnih riječi na
engleskom jeziku.
KOD:
Imports Microsoft.Office.Interop
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pogresnarijec.LostFocus
If pogresnarijec.TextLength > 0 Then
Dim wordapp As New Word.Application
wordapp.Visible = False
Dim doc As Word.Document = wordapp.Documents.Add()
Dim range As Word.Range
range = doc.Range()
range.Text = pogresnarijec.Text
doc.Activate()
doc.CheckSpelling()
Dim chars() As Char = {CType(vbCr, Char), CType(vbLf, Char)}
pogresnarijec.Text = doc.Range().Text.Trim(chars)
doc.Close(SaveChanges:=False)
wordapp.Quit()

End If
End Sub

Private Sub pogresnarijec_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pogresnarijec.TextChanged

End Sub
End Class
11.Načiniti program koji prikazuje kalendar.
KOD:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MonthCalendar1.SetDate(TextBox1.Text)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub
End Class

12.Načiniti program koji predstavlja mazewall igricu.

KOD:
Public Class Form1
Public Sub New()

' This call is required by the designer.
InitializeComponent()
movetostart()

' Add any initialization after the InitializeComponent() call.

End Sub
Private Sub Cilj_mouseenter(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Cilj.Click
'Prikazi poruka koja cestita na zavrsetku, a onda zatvara formu.'
MessageBox.Show("Cestitamo")
Close()
End Sub
Private Sub movetostart()
Dim startingpoint = Panel1.Location()
startingpoint.Offset(10, 10)
Cursor.Position = PointToScreen(startingpoint)

End Sub

Private Sub Wall_mouseenter(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.MouseEnter
movetostart()

End Sub

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

End Sub
End Class

13.Načiniti program koji prikazuje podjelu nagrada za ljetovanje kod
ćerke I sina.

KOD:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles izracunaj.Click
Dim i, c, s As Integer
c = 0
s = 0
For i = 1 To 50
If i Mod 2 = 1 Then
c = c + i
Else : s = s + i
End If
Next i
txtsin.Text = Str(s)
txtcerka.Text = Str(c)
End Sub

Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label3.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label1.Click

End Sub
End Class

14.Načiniti program koji prikazuje određivanje većeg broja u textboxu.

KOD:
Public Class Form1
Dim a As Integer
Dim b As Integer

Private Sub Ucitajpodatke()
a = Val(txta.Text)
b = Val(txtb.Text)
End Sub
Private Function VeciBroj(ByVal x As Integer, ByVal y As Integer) As String
Dim p As String = ""
If x > y Then
p = "Veći je broj " + Str(x) + "."
Else
p = "Veći je broj " + Str(y) + "."
End If
Return p
End Function

Private Sub PrikaziRjesenje(ByVal r As String)
txtporuka.Text = r

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Provjeri.Click
Ucitajpodatke()
Dim poruka As String = VeciBroj(a, b)
PrikaziRjesenje(poruka)
End Sub
End Class

15.Načiniti program koji prikazuje određivanje minimalnog elementa
cjelobrojnog niza.

KOD:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim n(10) As Integer
Dim i, min As Integer
For i = 1 To 10
n(i) = Int(InputBox("Unesi" + Str(i) + ".element niza:"))
Lista.Items.Add(n(i))
Next i
min = n(1)
For i = 2 To 10
If n(i) < min Then
min = n(i)
End If
Next i
txtMin.text = Str(min)
End Sub
End Class

16.Načiniti program koji predstavlja povrsinu I obim pravouganika.
KOD:
Public Class Form1

Private Sub btnpovrsina_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnpovrsina.Click
box3.Text = Val(Box1.Text) * Val(Box2.Text)
lblrjesenje.Text = "Povrsina je:"
End Sub

Private Sub btnobim_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnobim.Click
box3.Text = 2 * Val(Box1.Text) + 2 * Val(Box2.Text)
lblrjesenje.Text = "Obim je:"

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub
End Class
17.Načiniti program koji predstavlja upotrebu CPU u procentima.

KOD:
Public Class Upotreba

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Progresbar.Value = PerformanceCounter1.NextValue.ToString
Label1.Text = "Upotreba CPU " + Progresbar.Value.ToString + " %"
End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label1.Click

End Sub
End Class
18.Načiniti program pomoću kojeg je moguće slati email poruke.

KOD:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ProgressBar1.Value = 5
Dim message As System.Net.Mail.MailMessage
ProgressBar1.Value = 10
Dim smtp As New System.Net.Mail.SmtpClient(TextBox3.Text, 587)
ProgressBar1.Value = 24
message = New System.Net.Mail.MailMessage(TextBox1.Text, TextBox4.Text,
TextBox5.Text, TextBox6.Text)
ProgressBar1.Value = 43
smtp.Credentials = New System.Net.NetworkCredential(TextBox1.Text,
TextBox2.Text)
ProgressBar1.Value = 70
ProgressBar1.Value = 80
Try
smtp.Send(message)
ProgressBar1.Value = 100
MessageBox.Show("Poruka uspjesno poslana", "Poslano",
MessageBoxButtons.OK, MessageBoxIcon.Information)
ProgressBar1.Value = 0
Catch ex As Exception
MessageBox.Show("Greska, pokusajte ponovo", "Greska",
MessageBoxButtons.OK, MessageBoxIcon.Information)
MessageBox.Show("Pokusajte ponovo unijeti sifru ili mozda niste
konektovani na internet", "Greska", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
If CheckBox1.Checked = True Then
My.Settings.username = TextBox1.Text
My.Settings.Save()
My.Settings.Reload()
End If
If CheckBox2.Checked = True Then
My.Settings.password = TextBox2.Text
My.Settings.Save()
My.Settings.Reload()
End If
End Sub

Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CheckBox3.CheckedChanged
My.Settings.password = ""
My.Settings.username = ""
My.Settings.Save()
My.Settings.Reload()
TextBox1.Text = ""
TextBox2.Text = ""
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub
End Class
19.Načiniti program koji predstavlja alarm.

KOD:
Public Class Form1

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer2.Tick
Vrijeme1.Text = TimeOfDay
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If TimeOfDay = Vrijeme2.Text Then
MsgBox("Budjenje!", MsgBoxStyle.Critical)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles nastimaj.Click
Vrijeme2.Text = TextBox1.Text
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pocni.Click
Timer1.Start()
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Handles TextBox1.GotFocus
TextBox1.Text = "00:00:00"
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub
End Class

20.Načiniti program koji predstavlja notepad, to jest tekstualnu
aplikaciju.

KOD:
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Text1.text = ""
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub
End Class