You are on page 1of 39

IT

RAD



VISUAL BASIC 6.0


. . , ...

,
Index . 0045-06/

, 2009.
1



VB
GUI


Visual Basic
Graphic User Interface


Grafika korisnika meuveza

BASIC - Begginer's All purpose Symbolic Instruction Code


. 1964. Dartmouth College,
John G. Kemeny,
(engl. chairman of Department of Mathematics) Thomas Kurtz
(engl. time-share) SAD (Dartmouth TimeSharing System). BASIC

(engl. mainframe) General Electric GE-225.


BASIC :
GW BASIC 80- ,
QBASIC 9. ,
VISUAL BASIC-
BASIC

, .
VISUAL BASIC-a,
,
.

1. VISUAL BASIC
VISUAL BASIC 1997. MS
Office 97(Visual Basic for Aplications-VBA).
. ,
Windows Microsoft Office . VBA Excel,
Access, Power Point.
.
Properties Events
( , ...) . Visual Basic-
, .

2. VISUAL BASIC-
VISUAL BASIC Start-, Microsoft Visual Basic
2008 Express Edition, .1.

Microsoft Visual Basic 2008 Express Edition 9.0 New


Project (Windows Forms Application), . 2.

OK , Visual Basic .
Visual Basic-a
.

3. VISUAL BASIC-
Visual Basic-a (Main Window).
(Title Bar)
Visual Basic-a. (Main Menu) VB.
(Toolbar)
Visual Basic- . (Form)
, . 3.

Main Menu ( )

Title Bar ( )

Project ( )

Toolbar Controls
( )
Form ( )

Properties ( )
3

Project
.

Form Code

( Basic )

Project. Project

, View Project
Explorer,
R
7

Ctrl.

()

( , ,
, ,
.).
, , .

Properties (
)

.
(drop-down list)
.

.
:
.

4. VB 9.0
BASIC-a :
1) ;
2) ;
3)
4) .
VB ,
. VB Design ().
. VB
: .vbp
. frm.
, . bas
. exe.
9

VB .
: SUBROUTINE, SUB =
FUNCTION, FUNCTION = .
( ) .
:
1) ,
2) ,
3) , .
,
() .
() :
-

;
;
;
( ).

SUBROUTINE:
: Sub ,
Private ,
Private Sub () , ( )
...
- ( , )
...
-
...
Call - (FUNCTION SUB)
End Sub
- .

FUNCTION:
-




Public Function ( ) -
...
=

End Function

10

VB
VISUAL BASIC- 6 :
1) ;
2) ;
3) () , ;
4) ;
5) (.exe );
6) ( ).

5. VB
, .
.
.
VB Stop,
Design. Close .
Visual Basic-a File Exit.

6.
, .
() . :
1)
Design,
Basic ;
2)

;
3)
, .

11

7. VB 9.0
1. : VB
N .
:
) VB :
VB 9.0
Windows ,
() Properties Caption
.
2
1
3
3 .

1) Caption: IZRAUNAJ N faktorijel =


Private Sub IzracunajButton1_Click
:
12

Private , ();
Sub subroutine, ;
IzracunajButton1_Click - ( );
Click()- ( ).
:

Dim - promjenjiva I, fakt, n kao broj


I=1
Fakt = 1
n = prirodanBrojTextBox1.Text ( )
Radnja se izvrava sve dok je I <= n , fakt = fakt * I , I = I + 1
loop

RezultatLabel3.Text = fakt ,
End Sub

( )

(
)
End kraj dogaaja
Private Sub KrajButton1_Click

End Sub -

(
)
prirodanBrojTextBox1.Text = "" (
)
RezultatLabel3.Text = "" ( )
End Sub -
Private Sub PonovoRacunajButton1_Click

End Class .

2. : VB .
:
a) :

) 2.

) :

13

:
SAT Menu Editor
.
toolstrip manu sub menu-a (),
, VrijemeToolStripMenuItem DatumToolStripMenuItem.
toolstrip manu ,
, ,
, .
3. : VB
1 100, , 1 100,
1 100, For petlje i Do
Loop While petlje.

14


Public Class Form1
Private Sub IzlistajButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles IzlistajButton1.Click
Dim i As Integer
ListaListBox1.Items.Clear()
For i = 1 To 100
ListaListBox1.Items.Add(i)
Next
MsgBox("Brojevi do 100 su izlistani.", MsgBoxStyle.Information)
End Sub
Private Sub IzlistajNeparneButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles IzlistajNeparneButton.Click
Dim i As Integer
ListaListBox1.Items.Clear()
For i = 1 To 100 Step 2
ListaListBox1.Items.Add(i)
Next
MsgBox("Neparni brojevi do 100 su izlistani.", MsgBoxStyle.Information)
End Sub

15

Private Sub IlistajParneButton_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles IlistajParneButton.Click
Dim i As Integer
ListaListBox1.Items.Clear()
For i = 2 To 100 Step 2
ListaListBox1.Items.Add(i)
Next
MsgBox("Parni brojevi do 100 su izlistani.", MsgBoxStyle.Information)
End Sub
Private Sub PredjiNaDruguFormuButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles PredjiNaDruguFormuButton.Click
Form2.Show()
End Sub
Private Sub KrajButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton.Click
End
End Sub
End Class


Public Class Form2
Private Sub IzlistajForm2Button_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles IzlistajForm2Button.Click
Dim i As Integer
i = 1
ListaForm2ListBox.Items.Clear()
Do
ListaForm2ListBox.Items.Add(i)
i = i + 1
Loop While i <= 100
End Sub
Private Sub ListaForm2ListBox_MouseClick(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles ListaForm2ListBox.MouseClick
IzabranoTextBox.Text = ListaForm2ListBox.SelectedItem
End Sub
Private Sub PrebaciButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PrebaciButton.Click
PadajucaListaComboBox.Items.Add(IzabranoTextBox.Text)
End Sub
Private Sub VratiSeNaPrvuFormuButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles VratiSeNaPrvuFormuButton.Click
Me.Close()
Form1.Show()
End Sub
End Class

16

4.

: VB
, , , ,
.


Public Class Form1
Private Sub GoreButton3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles GoreButton3.Click
PokretnaLabelaLabel1.Top -= 20
End Sub
Private Sub DoleButton4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles DoleButton4.Click
PokretnaLabelaLabel1.Top += 20
End Sub
Private Sub LevoButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LevoButton2.Click
PokretnaLabelaLabel1.Left -= 20
End Sub
Private Sub DesnoButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles DesnoButton1.Click
PokretnaLabelaLabel1.Left += 20
End Sub
Private Sub btnBoja_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBoja.Click
Select Case txtBoja.Text
Case "crna"
PokretnaLabelaLabel1.ForeColor = Color.Black

17

Case "crvena"
PokretnaLabelaLabel1.ForeColor
Case "plava"
PokretnaLabelaLabel1.ForeColor
Case "zuta"
PokretnaLabelaLabel1.ForeColor
Case "zelena"
PokretnaLabelaLabel1.ForeColor
Case Else
PokretnaLabelaLabel1.ForeColor
End Select
End Sub

= Color.Red
= Color.Blue
= Color.Yellow
= Color.Green
= Color.White

Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles bPlava.CheckedChanged
Me.BackColor = Color.Blue
End Sub
Private Sub bBela_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bBela.CheckedChanged
Me.BackColor = Color.White
End Sub
Private Sub bCrvena_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bCrvena.CheckedChanged
Me.BackColor = Color.Red
End Sub
Private Sub bZuta_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bZuta.CheckedChanged
Me.BackColor = Color.Yellow
End Sub
Private Sub bZelena_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bZelena.CheckedChanged
Me.BackColor = Color.Green
End Sub
Private Sub bSiva_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bSiva.CheckedChanged
Me.BackColor = Color.LightGray
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
End Class
5.

: VB :
x y :

18

-5,

x<0

x+2, 0<=x<1
y=
3x-1, 1<=x<5
2x,

x>=5


Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub IzracunajButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles IzracunajButton1.Click
Dim x, y As Integer
x = UnesiCijeliBrojTextBox1.Text
If x < 0 Then
y = -5
ElseIf (x >= 0 And x < 1) Then
y = x + 2
ElseIf (x >= 1 And x < 5) Then
y = 3 * x - 1
Else : y = 2 * x
End If
RezultatTextBox2.Text = y
End Sub
Private Sub NoviUnosButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NoviUnosButton2.Click
UnesiCijeliBrojTextBox1.Text = ""
RezultatTextBox2.Text = ""
End Sub
Private Sub KrajButton3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton3.Click
End
End Sub

19

End Class
6.

: VB :
y :

2x,
3x-1,
1/x,

y=

-2<x<2
5<=x=<7


Public Class jednacina
Private Sub IzracunajButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles IzracunajButton1.Click
Dim x, y As Single
x = BrojXTextBox1.Text
If (x > -2 And x < 2) Then
y = 2 * x
ElseIf (x >= 5 And x <= 7) Then
y = 3 * x - 1
Else
y = 1 / x
End If
bROJyTextBox2.Text = y
End Sub
Private Sub NoviUnosButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NoviUnosButton2.Click
BrojXTextBox1.Text = ""
bROJyTextBox2.Text = ""
End Sub

20

Private Sub KrajButton3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles KrajButton3.Click
End
End Sub
End Class
7.

: VB
mini Windows word-a .

:
Public Class Form1

Private Sub formatTekst(ByVal menuItemText As String)


Dim fontOfSelectedText As Font = Me.EditorRichTextBox1.SelectionFont
Dim styleApplied As FontStyle
Select Case (menuItemText)
Case "masna"
If Me.EditorRichTextBox1.SelectionFont.Bold = True Then
styleApplied = FontStyle.Regular
Else
styleApplied = FontStyle.Bold
End If
Exit Select
Case "iskosena"
If Me.EditorRichTextBox1.SelectionFont.Italic = True Then

21

styleApplied = FontStyle.Regular

Else

styleApplied = FontStyle.Italic
End If
Exit Select
Case Else
If Me.EditorRichTextBox1.SelectionFont.Underline = True Then
styleApplied = FontStyle.Regular
Else
styleApplied = FontStyle.Underline
End If
End Select
Dim FontToApply As New Font(fontOfSelectedText, styleApplied)
Me.EditorRichTextBox1.SelectionFont = FontToApply
End Sub
Private Sub manipulisanjeFilom(ByVal menuItemText As String)
Select Case menuItemText
Case "Novi"
' Simulate creating a new document by merely clearing the
existing text.
EditorRichTextBox1.Text = ""
EditorRichTextBox1.Focus()
Exit Select
Case "Otvori"
If Me.openFileDialog.ShowDialog() = DialogResult.OK Then
MessageBox.Show("DUGME ZA OTVARANJE SAUVANIH FAJLOVA FAJLA
JE KLIKNUTO I SLUI SAMO SA ILUSTRUJE PRIMER " + _
vbCrLf + "the " + Me.openFileDialog.FileName + " file is
not opened.", "Sample Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Exit Select
Case "Sacuvaj"
If Me.saveFileDialog.ShowDialog() = DialogResult.OK Then
MessageBox.Show(" DUGME ZA UVANJE FAJLA JE KLIKNUTO I SLUI
SAMO SA ILUSTRUJE PRIMER " + _
vbCrLf + "the " + Me.saveFileDialog.FileName + " file
does not save.", "Sample Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Exit Select
Case Else
Me.Close()
Me.Dispose()
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
EditorRichTextBox1.Rtf = "{\rtf1\ansi \b
\ul RichTextBox\ul0. \i Pokuaj\i0 da formatira
na vie naina i u novom fajlu.}"
End Sub

22

ovaj objekat - kontrola\b0 je


\b otkucani tekst\b0! Probaj

Private Sub formatToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles masnaStripMenuItem.Click,
iskosenaToolStripMenuItem.Click, podvucenaToolStripMenuItem.Click
formatTekst(CType(sender, ToolStripItem).Text)
End Sub
Private Sub formatToolStrip2_ItemClicked(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles
formatToolStrip2.ItemClicked
formatTekst(CType(e.ClickedItem, ToolStripItem).Text)
End Sub
Private Sub fajlToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles
fajlToolStrip1.ItemClicked
manipulisanjeFilom(CType(e.ClickedItem, ToolStripItem).Text)
End Sub
Private Sub FajlToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles NoviToolStripMenuItem.Click,
OtvoriToolStripMenuItem.Click, SacuvajToolStripMenuItem.Click,
IzadjiToolStripMenuItem.Click
manipulisanjeFilom(CType(sender, ToolStripItem).Text)
End Sub
End Class

8. : : VB
.

:
23

Public Class Form1


Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MnozenjeRadioButton3.CheckedChanged
End Sub
Private Sub IzracunajButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles IzracunajButton2.Click
Dim prvi, drugi As Object
prvi = Val(PrvaPromjenjivaTextBox1.Text)
drugi = Val(DrugaPromjenjivaTextBox2.Text)
If SabiranjeRadioButton1.Checked = True Then
RezultatTextBox3.Text = prvi + drugi
ElseIf OduzimanjeRadioButton2.Checked = True Then
RezultatTextBox3.Text = prvi - drugi
ElseIf MnozenjeRadioButton3.Checked = True Then
RezultatTextBox3.Text = prvi * drugi
ElseIf DjeljenjeRadioButton4.Checked = True Then
RezultatTextBox3.Text = prvi / drugi
End If
End Sub
Private Sub KrajButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton1.Click
End
End Sub
Private Sub NoviUnosButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NoviUnosButton1.Click
PrvaPromjenjivaTextBox1.Text = ""
RezultatTextBox3.Text = ""
DrugaPromjenjivaTextBox2.Text = ""
End Sub
End Class

9.

: : VB .

24

:
Public Class Form1
Private Sub unesiTextTextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles unesiTextTextBox1.TextChanged
prikazitextLabel1.Text = unesiTextTextBox1.Text
End Sub
Private Sub obrisitextButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles obrisitextButton1.Click
unesiTextTextBox1.Text = ""
End Sub
End Class
10.

:
Public Class Minimum
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x, y, z As Integer
Dim min As Integer
x = PrviBrTextBox1.Text
y = DrugiBrTextBox2.Text
z = TreciBrojTextBox3.Text
min = x
If y < min Then min = y
If z < min Then min = z

25

NajmanjiBrJeTextBox4.Text = min
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
PrviBrTextBox1.Text = ""
DrugiBrTextBox2.Text = ""
TreciBrojTextBox3.Text = ""
NajmanjiBrJeTextBox4.Text = ""
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
End
End Sub
End Class
11.

:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
PictureBox1.Visible = False
Label1.Text = Int(Rnd() * 10)
Label2.Text = Int(Rnd() * 10)
Label3.Text = Int(Rnd() * 10)
If (Label1.Text = 7) Or (Label2.Text = 7) Or (Label3.Text = 7) Then
PictureBox1.Visible = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End
End Sub

26

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Randomize()
End Sub
End Class
12.

.

:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ispisiTextLabel1.Text = "DOBRO JUTRO"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ispisiTextLabel1.Text = "DOBAR DAN"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
ispisiTextLabel1.Text = "DOBRO VEE"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
End
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox1.Click
End Sub

27

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
PictureBox1.Visible = True
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
PictureBox1.Visible = False
End Sub
End Class
13.

:
Public Class Form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label1.Click
End Sub
Private Sub NoviUnosButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NoviUnosButton2.Click
BrojMesecaTextBox1.Text = ""
BrojDanaTextBox2.Text = ""

End Sub

28

Private Sub ObradaButton1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ObradaButton1.Click
Dim mesec As Integer
mesec = BrojMesecaTextBox1.Text
If (mesec < 1) Or (mesec > 12) Then
MsgBox("Broj meseca je nekorektan", 0, "Poruka o greski")
Else
Select Case mesec
Case 1, 3, 5, 7, 8, 10, 12
BrojDanaTextBox2.Text = "31"
Case 4, 6, 9, 11
BrojDanaTextBox2.Text = "30"
Case Is = 2
If MsgBox("Da li je godina prestupna?", 4, "Prestupna godina
DA/NE") = MsgBoxResult.Yes Then
BrojDanaTextBox2.Text = "29"
Else
BrojDanaTextBox2.Text = "28"
End If
End Select
End If
End Sub
Private Sub KrajButton3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton3.Click
End
End Sub
End Class
14.

Public Class Form1

29

Private Sub IzracunajButton1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles IzracunajButton1.Click
Dim x, y As Integer
x = BrojXTextBox1.Text
y = 2 * x ^ 2 + 3 * x - 4
vRIJEDNOSTbRyTextBox2.Text = y
End Sub
Private Sub NoviUnosButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NoviUnosButton2.Click
BrojXTextBox1.Text = ""
vRIJEDNOSTbRyTextBox2.Text = ""
End Sub
Private Sub KrajButton3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton3.Click
End
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox1.Click
End Sub
End Class
15.

,
100,
,

.

30

:
1
Public Class frmPrvaForma
Private Sub btnProvera_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnProvera.Click
If txtUnos.Text = "" Then
MsgBox("Niste unijeli ni jedan broj!")
ElseIf txtUnos.Text > 100 Then
MsgBox("Broj je vei od 100.")
ElseIf txtUnos.Text < 100 Then
MsgBox("Broj je manji od 100.")
ElseIf txtUnos.Text = 100 Then
MsgBox("Broj je jednak 100.")
End If
End Sub
Private Sub btnPrelazak_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrelazak.Click
Dim Poruka As String
Poruka = MsgBox("Da li elite da preeta na drugu formu?",
MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Pitanje")
If Poruka = MsgBoxResult.Yes Then

31

frmDrugaForma.Show()
End If
End Sub

End Class
2

Public Class frmDrugaForma


Private Sub btnDrugaProvera_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDrugaProvera.Click
If Opcija1.Checked = False And Opcija2.Checked = False Then
MsgBox("Nije ekirana ni jedna opcija.", MsgBoxStyle.Information)
ElseIf Opcija1.Checked = True And Opcija2.Checked = True Then
MsgBox("Obe opcije su ekirane.", MsgBoxStyle.Information)
ElseIf Opcija1.Checked = True And Opcija2.Checked = False Then
MsgBox("ekirana je Opcija 1.", MsgBoxStyle.Information)
ElseIf Opcija1.Checked = False And Opcija2.Checked = True Then
MsgBox("ekirana je Opcija 2.", MsgBoxStyle.Information)
End If
End Sub
End Class
16.


, .
.

:
Public Class Form1
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
TimTajmer.Enabled = True
End Sub

32

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnStop.Click
TimTajmer.Enabled = False
End Sub
Private Sub TimTajmer_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TimTajmer.Tick
lblNaslov.Text = Val(lblNaslov.Text) + 1
End Sub
Private Sub lblVreme_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblVreme.Click
lblVreme.Text = TimeOfDay
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TimVreme_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TimVreme.Tick
lblVreme.Text = TimeOfDay
End Sub
End Class

17.

: n S=1!+2!+3!+...+n!

:
Public Class Form1
Private Sub IzracunajButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles IzracunajButton1.Click
Dim S, fakt, n As Integer
S = 0
fakt = 1
n = PrirodanBrojTextBox1.Text

33

For i = 1 To n
fakt = fakt * i
S = S + fakt
Next
SumaTextBox2.Text = S
End Sub
Private Sub NoviUnosButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NoviUnosButton2.Click
PrirodanBrojTextBox1.Text = ""
SumaTextBox2.Text = ""
End Sub
Private Sub KrajButton3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton3.Click
End
End Sub
End Class
18.

,

.

:
Public Class Form1
Private Sub IzracunajButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles IzracunajButton1.Click
Dim suma, broj As Integer
broj = TextBox1.Text

34

suma = 0
Do
suma = suma + broj Mod 10
broj = broj \ 10
Loop Until broj = 0
RezultatLabel3.Text = suma
End Sub
Private Sub KrajButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton1.Click
End
End Sub
End Class
19.

:
Public Class Form1
Private Sub DodajUProdajuButton1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DodajUProdajuButton1.Click
Dim PozicijaUprodaji As String
dodajime("prodaja", PozicijaUprodaji)
ProdajaTextBox1.Text = ProdajaTextBox1.Text & PozicijaUprodaji
End Sub
Private Sub DodajUMarketingButton2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles DodajUMarketingButton2.Click

35

Dim pozicijaUmarketingu As String


dodajime("marketing", pozicijaUmarketingu)
MarketingTextBox2.Text = MarketingTextBox2.Text & pozicijaUmarketingu
End Sub
Private Sub KrajButton3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KrajButton3.Click
End
End Sub
End Class
20.

,
.
,
.


Public Class FrmMjesec
Private Sub dgmMjesec_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dgmMjesec.Click
Dim a As Integer
a = Val(txtMjesec.Text)
If a >= 1 And a <= 12 Then
Select Case a
Case 12
MsgBox("DECEMBAR")
Case 11
MsgBox("NOVEMBAR")
Case 10
MsgBox("OKTOBAR")
Case 9
MsgBox("SEPTEMBAR")
Case 8
MsgBox("AVGUST")
Case 7
MsgBox("JUL")
Case 6
MsgBox("JUN")

36

Case 5
MsgBox("MAJ")
Case 4
MsgBox("APRIL")
Case 3
MsgBox("MART")
Case 2
MsgBox("FEBRUAR")
Case 1
MsgBox("JANUAR")
End Select
Else
End If
End Sub
End Class

MsgBox("Broj mora biti izmeu 1 i 12")

37


Visual Basic-a, ,
. VB
, .
Visual Basic
, .

38


1.

Visual Basic 6
Peter Norton
Sams Publishing
ISBN broj: 86-7310-038-0

2.

39

You might also like