Professional Documents
Culture Documents
Visual Basic Qstart
Visual Basic Qstart
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
VB 2008
1.
DVD DVD .
. ,
drive DVD setup.exe.
, DC drive D,
d:\setup.hta .
2.
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
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 -
. ,
.
FormatPercent -
100
(%) . ,
.
( )
lblTotalPct = FormatPercent(NumToFormatAsPercent)
lblSumPct = FormatPercent(NumToFormatAsPercent, NumOfPlaces)
lblCurrInterest = FormatPercent(CurrentInterest)
.
.. 21/02/81 21 1981 .
(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 ()
(CONSTANT)
- CONST.
, .
, .
.
.
:
DIM < > as < > = < >
:
(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 .
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)
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 (
)
)
().
. ,
.
:
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( < " " > , < / > , <
"" > )
,
.
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 .
Sorted:
SORTED (TRUE),
.
, . ListIndex
.
Clear:
.
lstSchools.Clear
RemoveItem
.
.
< > .RemoveItem < >
LstSchools.RemoveItem 3
3,
( ).
ListCount ListCount
. ListCount
.
.
(debug)
.
:
- (Sub Procedure)
.
(Function Procedure) -
.
,
.
-
1.
2.
3.
4.
5.
6.
7.
ADD PROCEDURE TOOLS ""
PRIVATE ( scope)
OK
.
, .
-:
-:
Private Sub cmdCalculate_Click()
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
(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.
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, ,
.
Combo
Box. List Box, .
List property ( )
AddItem ( )
,
(LIST PROPERTY)
1.
2.
3.
4.
5.
LIST
,
< CTRL > < ENTER >
3
,
(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
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
(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.
.
(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
, :
VB .
, ,
. .
,
.
StartUp , .
Load () (
).
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