Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

..................................................................................................................................

4
Visual Basic........................................................................... 5
............................................................................................................................................5
VB 2008 ..............................................................................................5
3. ........................................................................................................................................... 16

(Procedural) (Non-...................... 16
(Labels), (Text Boxes) (Command
Buttons) ................................................................................................................................. 17
................................................................................................................. 17
(Functions) (Methods) ............................................. 18
(Variables) (Constants) ....................................................... 19
(VARIABLE)......................................................................... 19
(CONSTANT)........................................................................... 20
.................................................................................................. 22
(PROPERTIES)..................................................................................................... 22
(Option Buttons)... (Formats)............................... 23
(OPTION BUTTONS) ............................................................................. 24
(CHECK BOXES) ................................................................................... 24
(IMAGES) ................................................................................................................ 24
(SHAPES) .............................................................................................................. 24
(LINES) .................................................................................................................. 25
(Focus) ................................................................................... 25
(Strings) ...................................................................... 25
(Formats) .................................................................................................. 25
(Input Boxes), (Message) (List
Boxes) .................................................................................................................................... 26
Form Load.............................................................................................................................. 27
................................................................................ 27
............................................................................................ 27
...................................................................................... 28
......................................................................................................................... 28
ListIndex................................................................................................................ 29
Sorted:................................................................................................................... 29
Clear: ..................................................................................................................... 29
RemoveItem......................................................................................................... 30
(Sub Procedures), (Random Numbers) ............... 30
: ................................................................................................... 30
: .............................................................................................................. 30
- .......................................................................... 31
WITH ....................................................................................................................... 32
(COMMON DIALOG CONTROL)......................... 32
(DIALOG CONTROL) ................... 32
( ) ......... 33
(FONTS) ....................................................................... 33
..................................................................................................... 33
................................................................................................................ 34
INT() ................................................................................................................ 34
, (Combo Boxes) (QB Color) .................... 34
................................................................................................................ 35
(COMBO BOXES) ............................................................................... 36
List Box Combo Box ....................................................... 36
, (LIST
PROPERTY) ............................................................................................................................ 36

,
(ADDITEM).......................................................................................................... 36
(ItemData ARRAY).... 36
........................................................................................... 37
(TEXT PROPERTY):............................................................................. 37
QB COLOR.............................................................................................................................. 38
(Control Arrays), (Scroll Bars)
RGB (Red-Blue-Green RGB Function) ......................................................... 38
(CONTROL ARRAY):.......................... 39
,
(CONTROL ARRAYS): .......................................................................... 40
(Scroll Bars) RGB (RGB Function) .......................... 40
(SCROLL BAR)............................................................... 40
................................................................................................ 41
.......................................................................................... 41
RGB (RGB FUNCTION).................................................................................... 42
(Multiple Forms), ME (ME Keyword)
.......................................................................................................................... 42
ME () .......................................................................................................... 43


Visual Basic
Microsoft Windows.
Visual Basic (VB)
Windows. Visual Basic
(menus), (text boxes),
, , (list boxes)
(scroll bars).
Visual Basic.
.
, Crystal Reports
500 .
,
. :
IF / THEN / ELSE, FOR / NEXT .
Basic QBasic,
.

Visual Basic

Visual Basic 2008 Express


Edition (VB) DVD . To DVD
Visual Studio Express, Microsoft
. Visual Basic
DVD .
VB Internet
(download) .
:
http://www.microsoft.com/express/vb/
Visual Basic, Windows Update
( windows)
.
DVD UDF .
UDF, Nero, Deamon Tools .
DVD.
VB
.

VB 2008
1.

DVD DVD .
. ,
drive DVD setup.exe.
, DC drive D,
d:\setup.hta .

2.

, Visual Basic 2008


Express Edition. Visual Basic

VB.

3.

Visual Basic
.

, ,
Microsoft .
, Yes checkbox.
Microsoft
,
Data Collection Policy.
Next ().

4.


(License Terms).

Microsoft .

VB
. Next () ,
I have read and accept the license terms (
) .

.
, Internet
Visual Basic
.
.


Internet Microsoft
.
.

5.


Microsoft SQL Server 2008 Express Edition.



, .
Microsoft SQL Server 2008 Express Edition
Visual Basic,
.

6.



VB.

VB
.
,
, .
Browse ()
Install
()

7.

.
Visual Basic.


, .

.
,
.

-
.
, Visual Basic
Microsoft. Visual
Basic .

3.
o
.
, 4
(RSS )

(Procedural) (NonProcedural)
-
. ,
.

.

FORTRAN

COBOL

BASIC


PASCAL
...
- (Object-Oriented)
, .

,
,
.
, .
:

Visual Basic

C++

DELPHI

JAVA

(Labels), (Text Boxes)


(Command Buttons)
(Label) - .
.
,
. lbl
.
:

lblName

lblAddress

lblCity
(Text Box)
. (focus),
Visual Basic.
txt.
:

txtSponge

txtBob

txtNum1
(Command Buttons)
.
, (
.). cmd.


-
Visual Basic (VB).
. VB
.
(Run-Time) -
.
. : ,
. VB ,
,
.

(Logical Error) -
, .
, .
( ).
: 3 3,
.

(Functions) (Methods)
VAL - (string) .
(string).
, , VAL
,
. , VAL
.
PrintForm - .
.
FORMAT - .
, ..
7.1500 7.15.
:
< var > = FORMAT( < var > ," < type of format > ")

:
lblTotal = Format(lblTotal,"Currency") 'Formats number w ith a $
lblArea = Format(lblTotal,"Fixed") ' Formats number as decimal w
LblPctTotal = Format(lblPctTotal,"Percent") 'Formats number as

FormatCurrency -
$ . ,

.
lblSum = FormatCurrency(NumToFormat)
lblTotalAmount = FormatCurrency(curTotal)

FormatNumber -
. ,
.

lblTotal = FormatNumber(NumToFormat, NumOfDecimalPlaces)


lblSum = FormatNumber(Sum, 2)

FormatPercent -
100
(%) . ,
.
( )

lblTotalPct = FormatPercent(NumToFormatAsPercent)
lblSumPct = FormatPercent(NumToFormatAsPercent, NumOfPlaces)
lblCurrInterest = FormatPercent(CurrentInterest)

FormatDate and Time - (string)


, .
.
/

.
.. 21/02/81 21 1981 .

lblCurrentDate = FormatDateTime(StartingDate, vbShortDate)


lblCurrentDate = FormatDateTime(EndingDate, vbLongDate)
lblCurrentTime = FormatDateTime(StartingTime, vbShortTime)
lblCurrentTime = FormatDateTime(StartingTime, vbLongTime)

(Variables) (Constants)
(Option) (Explicit) -
.
,
.

(VARIABLE)

, VB
. ,
.
:

( abc 1abc)
, ( .. abc1_2)
(.. ab c, ab.c)
1 255 ( ,
a, b, a1, b1, 255 )
( .. VAL IF
VB)

: ,
.
DIM VB.
DIM:
DIM < > as < >
:
inNum1, Integer ()
strName, String ()
curTotalAmount, Currency ()

DIM inNum1 as Integer


DIM strName as String
DIM curTotalAmount as Currency

(CONSTANT)
- CONST.
, .
, .
.
.
:
DIM < > as < > = < >
:

DIM sngPI as Single = 3.14


DIM curTaxRate as Currency = .08

(NAMED CONSTANTS) -
- CONST.
(numeric) (string) .
(NUMERIC CONSTANTS)
.
(STRING CONSTANTS) -
, , #$%^&*.
.
(INSTRINCT CONSTANTS)
VB.
:

vbRed

vbGreen

vbBlue

Checked

vbYellow

UnChecked


(Scope)
.
(Lifetime)
.

3
(Global Variable) ,
(project).
(Module-Level)
.

.

(PROPERTIES)
Default -
<ENTER>. ,
DEFAULT TRUE. Default
TRUE. , .
Cancel <ESC>
. ,
CANCEL TRUE.
.
TabStop
. TabStop TRUE,
. FALSE, .

.
.

TabIndex <TAB>.
Name () - ,
.
Caption () -
, .
BackColor

ForeColor ( ) -
.
Text () .
Alignment () (Label)
(Text Box)


0 - Left

1 - Right

2 - Center
MultiLine
.
Font ( )
.
Visible .

lblTotal.Visible = True 'label w ill be displayed on the form.


lblTotal.Visible = False 'label w ill not be displayed on the form.

FillStyle ,
. .

0 - Solid -

1 - Transparent -

2 - Horizontal Line

3 - Vertical Line -

4 - Upward Diagonal

5 - Downward Diagonal

6 - Cross -

7 - Diagonal Cross
:
Square.FillStyle = 0
Square.FillStyle = 8

(Option Buttons)... (Formats)


Option Buttons
.
Check Boxes -
.
Frame
.
Image ().
Shape , ,
.

(OPTION BUTTONS)
VALUE TRUE ,
, FALSE. CAPTION ()
.
, opt.
,
.

(CHECK BOXES)
.
VALUE CHECKED ,
, UNCHECKED .
VALUE 0, 1 2.

0 - UnChecked

1 - Checked -

2 - Grayed - -
CAPTION
. ,
chk.
click .

(IMAGES)
PICTURE
.
, .
STRECH TRUE,
.
img.

(SHAPES)
:

0 - Rectangle -

1 - Square -

2 - Oval ,

3 - Circle -

4 - Rounded Rectangle

5 - Rounded Square -
shp.

(LINES)
.

. lin.

(Focus)
Focus - .
| , ,
.
, .
SetFocus
. (SetFocus)
, ,
.
setFocus:
txtNum1.setFocus 'w ill place cursor in the text box.
cmdCalc.setFocus 'w ill hilight this command button.
optBlue.setFocus 'w ill put dotted lines around this opt button.

(Strings)
(Concatenation) -
(string). VB,
+ & .
:
StrFirstName + " " + strMiddleInitial + ". " + StrLastName
StrFirstName & " " + strMiddleInitial & ". " + StrLastName

(Formats)
:
( FORM LOAD (
)
)

< > .Top = (Screen.Height - < > .Height)/2


< > .Left = (Screen.Width - < > .Width)/2
< > - ,
.
"myForm"
myForm :

myForm.Top = (Screen.Height - myForm.Height)/2


myForm.Left = (Screen.Height - myForm.Width)/2

(Input Boxes), (Message)


(List Boxes)
Input Box ( )
.
.
(prompt)
.
, (
CANCEL - ). ,
,
=.
.
.
VariableName = InputBox("Prompt","Title")
:
StrName = InputBox("Enter your name", "bs0d")
StrCareer = InputBox("Enter your w orkplace", "AllSyntax.com")

().

. ,
.
:

Form_Load

(CheckBox)

Form Load
Form_Load .
, VB
FORM_LOAD. Form_Load.
FORM_LOAD
VB, :


FORM_LOAD,
.
:
Private Sub Form_Load()
< Place Code Here >
End Sub
FORM_LOAD:
Private Sub Form_Load()
InputBoxes.Top = Screen.Height - InputBoxes.Height)/2
InputBoxes.Left = Screen.Width - InputBoxes.Width)/2
StrName = InputBox("Enter your name", " Title Bar Text.")
LblName = StrName


/ VB,
.
MsgBox.
:


.
:
MsgBox < " " > , < / > , < "" >

MsgBox "AllSyntax.com is a great site!",vbInformation, "AllSyntax.com"

.
/
().
.


(=).
,
( ).
= MsgBox( < " " > , < / > , <
"" > )

IntRes = MsgBox("Are my fingers tired?", vbYesNo + vbQuestion,"My Question")

Private Sub cmdCheck_Click()


If val(txtNum1) > val(txtNum2) Then
MsgBox "First Number is greater than second", vbInformation, "Comparing Numbers"
ElseIf val(txtNum2) > val(txtNum1) Then
MsgBox "Second Number is greater than the first", vbInformation, "Comparing Numbers"
Else
MsgBox "The tw o numbers are equal", vbInformation, "Comparing Numbers"
End If
End Sub


,
.
lst.

.
LIST .
AddItem.
< _ > .AddItem < >
,
. ,
. / 0, 1 .
:

lstSchools.AddItem "Harvard"
lstSchools.Additem "Yale"
lstSchools.Additem "Princeton"
lstSchools.Additem "Brow n"
lstSchools.Additem "Cornell"
lstSchools.ListIndex = 3

Brown. Harvard
/ 0, Yale / 1 ...

ListIndex
ListIndex
.
. :
< > .ListIndex = 3 ' 4 .

lstSchools.ListIndex = 3 'This w ill highlight the 4th school in lstSchools.

Sorted:
SORTED (TRUE),
.
, . ListIndex
.

Clear:
.

< > .Clear

lstSchools.Clear

RemoveItem
.
.
< > .RemoveItem < >

LstSchools.RemoveItem 3

3,
( ).
ListCount ListCount
. ListCount
.

(Sub Procedures), (Random Numbers)


Procedure () -
.


.
(debug)


.

:
- (Sub Procedure)
.

(Function Procedure) -
.
,
.

-
1.
2.
3.
4.
5.
6.
7.


ADD PROCEDURE TOOLS ""

PRIVATE ( scope)
OK
.
, .

-:

Private Sub AddNumbers()


Sum = val(txtNum1) + val(txtNum2)
LblSum = Sum
End Sub

-:
Private Sub cmdCalculate_Click()
AddNumbers
End Sub

Private Function AddNumbers()


AddNumbers = val(txtNum1) + val(txtNum2)
End Function

Private Sub cmdCalculate_Click()


LblSum = AddNumbers()
End Sub

WITH
WITH
.
WITH:
With < control >
.< 1> = < 1 >
.< 2> = < 2 >
.< 3> = < 3 >
End With
WITH:
lblEmployee.Font.Name = dlgCommon.FontName
lblEmployee.Font.Bold = dlgCommon.FontBold
lblEmployee.Font.Italic = dlgCommon.FontItalic

WITH:
With lblEmployee.Font
.Name = dlgCommon.FontName
.Bold = dlgCommon.FontBold
.Italic = dlgCommon.FontItalic
End With

(COMMON DIALOG CONTROL)



Windows ,
, .

(DIALOG CONTROL)


.
(Dialog controls)
.ocx
(Dialog controls),
dlg
.

.

(
)
1.
2.
3.
4.
5.
6.

Project
Components
Microsoft Common Dialog Control 6.0

OK
Dialog Control .

(FONTS)
:
With dlgCommon ( )
.Flags = cdlCFScreenFonts
.ShowFont
End With

With txtName.Font
.Bold = dlgCommon.FontBold
.Italic = dlgCommon.FontItalic
.Name = dlgCommon.FontName
.Size = dlgCommon.FontSize
End With


:
dlgCommon.Show Color 'Brings up the color box
txtName.ForeColor = dlgCommon.Color 'Applies it to the font


Rnd 0 1.
Randomize VB rnd.
randomize, rnd
, .
1 10:
Num = Int((10 - 1 + 1)* rnd + 1)

1 100:
Num = Int((100 - 10 + 1)* rnd + 1)

INT()
(floating point value)
. INT(4.656)
4.

, (Combo Boxes) (QB Color)



, .
Windows VB, (menu bar)
(menu names), ,
.
, .
(controls)
(events) . (Name
property) , .
, Visual Basic,
< CTRL > + E
.


Caption () - .
Name () -
. ,
"mnu". , file, ,
"mnuFile".
(SUBMENU) -
, ( ). ,
.
(Menu List Box) -
, .
, , ,
.
(Separator Bars)
. , (-)
.
, .
,
(mnuSep1, mnuSep2, ... .).
(Shortcut Keys) -
.
, .

, .
Checked () -
, .
.
Enabled () -
, . , .
, .
(mnuStar.Enabled = False).
Visible () - .
, .
, .
(mnuStar.Visible = True).
Insert () - ,
. .
.
Delete () - .
, OK
.

(COMBO BOXES)
Combo Box -
, .

List Box Combo Box

List Box, ,

. Combo Box, ,

.

Combo
Box. List Box, .

List Boxes, Combo Box


...

List property ( )
AddItem ( )

,
(LIST PROPERTY)
1.
2.
3.
4.
5.

LIST
,
< CTRL > < ENTER >
3

< ENTER > list box


.

,
(ADDITEM)

FORM_LOAD
, :
< > .AddItem " < > "

(ItemData
ARRAY)
< object_name > .AddItem " < Value > "
< object_name > .ItemData(< object_name > .NewIndex) = < Value >


, Combo Box:
cboSchool.AddItem "Harvard"
cboSchool.AddItem "Yale"
cboSchool.AddItem "Princeton"
cboSchool.AddItem "Brow n"
cboSchool.AddItem "Cornell"

Harvard 0, Yale 1 .
ItemData Combo Box...

cboOffice.AddItem "Paper"
cboOffice.ItemData(cboOffice.New Index)
cboOffice.AddItem "Cartrige"
cboOffice.ItemData(cboOffice.New Index)
cboOffice.AddItem "Folders"
cboOffice.ItemData(cboOffice.New Index)
cboOffice.AddItem "Binder"
cboOffice.ItemData(cboOffice.New Index)

= 300
= 3200
= 250
= 400

(TEXT PROPERTY):
(Text property)
.
< label > = < control > .Text
lblFood = cboFood.Text

ListIndex List Boxes. NewIndex, ItemData, Sorted,


Clear, RemoveItem, ListCout... .
Combo Boxes, , "cbo".
, combo box School, ,
cboSchool.

QB COLOR
QBCOLOR - VB 15
. QBCOLOR ,
. 0 15.
:

-Index0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

-ColorBlack
Blue
Green
Cyan
Red
Magenta
Yellow
White
Gray
Light Blue
Light Green
Light Cyan
Light Red
Light Magenta
Light Yellow
Bright White

:
ShpRectangle.FillColor = QBColor(1) Will be show n in blue
ShpCircle.FillColor = QBColor(6) Will be show n in yellow

(Control Arrays), (Scroll


Bars) RGB (Red-Blue-Green RGB Function)
(Array) - .
(Control Array) -
.
(Index)
.

:

(Text Boxes)

(Option Buttons)

(Check Boxes)

(Labels)

(Command Buttons)

(CONTROL ARRAY):

.
.


.
"Yes"
(control array).
, , .
,
. 0,
1, 2 ..

(Control Array)
(Select Case):

Rounded Square
.
Private Sub optColors_Click(Index As Integer)
Select Case Index
Case 0: shpRoundSquare.FillColor = vbBlack
Case 1: shpRoundSquare.FillColor = vbBlue
Case 2: shpRoundSquare.FillColor = vbYellow
Case 3: shpRoundSquare.FillColor = vbGreen
Case 4: shpRoundSquare.FillColor = vbRed
Case 5: shpRoundSquare.FillColor = vbMagenta
End Select
End Sub

,
(CONTROL ARRAYS):
control array.
.

'Calculating Sum and Average


Private Sub cmdCalculate_Click()
For X = 0 to 9
Sum = Sum + val(txtTest(X))
Next X
Average = Sum / 10
End Sub
'Clearing text boxes and totals
Private Sub cmdClear_Click()
For Z = 0 to 9
TxtTest(Z) = ""
Next Z
LblSum = ""
LblAvg = ""
Sum = 0
Average = 0
End Sub

(Scroll Bars) RGB (RGB Function)


(Scroll Bar)
. ,
.
VB .
, ,
.
(Scroll Box) ,
. (scroll box)
. (Scroll Box)
Thumb.

(SCROLL BAR)

Min
Max
Small Change , .
Large Change ,
.
Value ()
.

"vsb"
"hsb"


Change ( )
.
Scroll ( ) scroll box.
,
. ,
(Change Event),
(Scroll event).
, :
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
Hscroll.Top = (Screen.Height - Hscroll.Height)/2
Hscroll.Left = (Screen.Width - Hscroll.Width)/2
End Sub
Private Sub hsbScroll_Change()
LblValue = hsbScroll.Value
End Sub
Private Sub hsbScroll_Scroll()
LblValue = hsbScroll.Value
End Sub

, :

Private Sub cmdExit_Click()


End
End Sub
Private Sub Form_Load()
Vscroll.Top = (Screen.Height - Vscroll.Height)/2
Vscroll.Left = (Screen.Width - Vscroll.Width)/2
End Sub
Private Sub vsbScroll_Change()
LblValue = vsbScroll.Value
End Sub
Private Sub vsbScroll_Scroll()
LblValue = vsbScroll.Value
End Sub

RGB (RGB FUNCTION)


RGB ,
. 0 255, 0
255 .
, ,
. RGB,

.
= RGB(RedValue, GreenValue, BlueValue)
:
RGB(0,0,0) 'w ould be BLACK
RGB(255,255,255) 'w ould be WHITE
RGB(255,0,0) 'w ould be RED
RGB(0,255,0) 'w ould be GREEN
RGB(0,0,255) 'w ould be BLUE

(Multiple Forms), ME (ME Keyword)

VB .
, ,
. .
,
.
StartUp , .
Load () (
).

Load < form_name >


Unload () - . ,
, ,
.
Unload < form_name >
Show () .
< form_name > .Show
Hide () . .
.
< form_name > .Hide

ME ()

ME. ME .
ME ,
.
:
Unload Me 'Unloads the current form that is executing code
Me.Hide 'Hides the form currently executing code
Me.Show 'Show s the form currently executing code

99 & , 142 35 .
. 210.2719100, Fax : 210-2718133
www.sdc.gr

You might also like