Professional Documents
Culture Documents
RAD
VISUAL BASIC 6.0
. . , ...
,
Index . 0045-06/
, 2009.
1
VB
GUI
Visual Basic
Graphic User Interface
Grafika korisnika meuveza
, .
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.
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 .
Private , ();
Sub subroutine, ;
IzracunajButton1_Click - ( );
Click()- ( ).
:
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
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
: 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
: VB
mini Windows word-a .
:
Public Class Form1
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
8. : : VB
.
:
23
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
:
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
:
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
29
,
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 Form1
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
TimTajmer.Enabled = True
End Sub
32
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
,
.
,
.
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
37
Visual Basic-a, ,
. VB
, .
Visual Basic
, .
38
1.
Visual Basic 6
Peter Norton
Sams Publishing
ISBN broj: 86-7310-038-0
2.
39