Download - Σημειώσεις Visual Basic-2012-13-νεο

Transcript
  • 7/23/2019 Visual Basic-2012-13-

    1/26

  • 7/23/2019 Visual Basic-2012-13-

    2/26

    4, 811 00 22510-46222 www.platonos.gr2 / 26

    1. 41.1 41.2 Visual Basic 5.0 81.3 91.4 ANTIKEIMENO Label 91.5 Text (Text Box) 101.6 OptionButton & Frame 101.7 CheckBox 111.8 CommandButton 111.9 ListBox 121.10 ComboBox 121.11 Timer 131.12 Image 131.13 Picture 131.14 (Control Arrays) 142. (EVENTS) 142.1 DragDrop 142.2 MouseDown 142.3 keyPress ASCII 153. 163.1 163.2 Fontsize 163.3 163.4 rnd 163.5 randomize timer 163.6 if 163.7 case 17

  • 7/23/2019 Visual Basic-2012-13-

    3/26

    4, 811 00 22510-46222 www.platonos.gr3 / 26

    3.8 (Loop) For .... Next 183.9 While Wend 193.10 Do .Loop until 193.11 Do .Loop while 203.12 msgbox() 203.13 InputBox 213.14 LEN() 223.15 Mid() 223.16 val() 223.17 instr() 223.18 IsNumeric() 233.19 Visual Basic 233.19.1 ScaleWidth ScaleHeight 233.19.2 233.19.3 Line 233.19.4 ForeColor 24

    3.19.5 Circle 243.19.6 Line Circle 243.19.7 DrawWidth 253.19.8. 253.20 253.21 ASCII 25

  • 7/23/2019 Visual Basic-2012-13-

    4/26

    4, 811 00 22510-46222 www.platonos.gr4 / 26

    1.

    1.1 ,

    . compiler (

    ) ,

    ,

    . , ,

    . ,

    .

    (compiler) .

    , ,

    / 1000 .

    Pascal

    Basic

    C++

    Program demo1;Var I:integer;

    BEGINFor I:=1 to 100 do

    BeginWriteln( );

    End;END.

    For I=1 to 1000Print

    Next I

    #include using namespace std;

    int main(){int i;

    for(i=1;i

  • 7/23/2019 Visual Basic-2012-13-

    5/26

    4, 811 00 22510-46222 www.platonos.gr5 / 26

    /,

    RAM.

    () , , . ,

    , .

    4 . :

    ) A (integer) : ( )

    ( ), 19.

    ) (real) : (

    ), 19,3.

    ) (string) : ,

    ) (Boolean): .

    true false.

    .

    .

    _. .

    (

    ).

    :

    : George, Maria, 300, _300, _123, k2

    : George 1 ( ), for( ,

    )

    =

    = .

    Integer.

    :

    =15

    =18

    =23+3

    . .

    . 15, 18

    26. ,, 26.

  • 7/23/2019 Visual Basic-2012-13-

    6/26

    4, 811 00 22510-46222 www.platonos.gr6 / 26

    (

    ( ) =

    . =+1.

    1 ( )

    ( Integer )

    =3

    = 4

    = +

    7.

    :

    = 10

    = +

    () +

    .

    :

    = =38.9 =true

    Visual Basic, ,

    . .

    =12, integer

    =Maria 12, string

    =12.4 real

    =false, boolean

    .

    :

    +-*/^ ( )

    A=10B=20C=A+B

    C 30

    \ ( )

    mod( )

    A=19B=6C=A\BD=A mod B

    C 3 D 1

    = () ()>= ( )

  • 7/23/2019 Visual Basic-2012-13-

    7/26

    4, 811 00 22510-46222 www.platonos.gr7 / 26

    AndOrNot

    A=10B=20C=15A>20 and B>10

    A>20 or B>10

    Not (A>20)

    H false( )

    H true( )

    ( >20 )

  • 7/23/2019 Visual Basic-2012-13-

    8/26

    4, 811 00 22510-46222 www.platonos.gr8 / 26

    1.2 Visual Basic 5.0H Visual Basic 5.0

    ,

    Windows.

    ,

    ( .

    object oriented programming.

    Visual basic

    Visual Basic 12.

    Visual Basic 5, () sites .

    , Form1

    . (

    ) :

    .

    .

    Label

    label.

    /.

    .

    .

    ()

    (properties) .

    . .

    .

    :

    view Properties Window ToolBox.

  • 7/23/2019 Visual Basic-2012-13-

    9/26

    4, 811 00 22510-46222 www.platonos.gr9 / 26

    1.3

    .

    :

    BorderStyle Caption ( ) .

    ext, Caption TextBackColor ForeColor CaptionFont captionAlignment CaptionDragmode 1 DragIcon Visible true , ToolTipText '

    .Top

    ( )

    Left (

    )Height Width Enabled

    Tag .

    .

    (Properties Window) . :

    . =

    Caption Label1 :

    Label1.Caption=

    1.4 ANTIKEIMENO Label

    ( ,

    ) . .

  • 7/23/2019 Visual Basic-2012-13-

    10/26

    4, 811 00 22510-46222 www.platonos.gr10 / 26

    1.5 Text (Text Box)

    .

    . .

    Text : text . . .

    . text text1. , ( ) text1.text.

    text1.text=.. Text1.Text="...........",

    .txt

    open "" for input as #1text1.text = input$(LOF(1),1)close #1

    TextBox!!!

    1.6 OptionButton & Frame

    ( multiple choice). Option1, Option2, Option3, Option1(0), Option1(1), Option1(2),. ( control array, )

    OptionButton

    OptionButton OptionButton. 4 OptionButton . OptionButton.

    optionButton

  • 7/23/2019 Visual Basic-2012-13-

    11/26

    4, 811 00 22510-46222 www.platonos.gr11 / 26

    frames .

    Value true (1) false (0).Style Standard ( -

    ) Graphical ( , )

    Picture Style Graphical

    1.7 CheckBox

    Check1, Check1, Check1, Check1(0),Check1(1), Check1(2),.

    CheckBox

    Value true (1) false (0).

    : 1 true option buttons

    Style Standard ( - ) Graphical ( , )

    Picture Style Graphical

    1.8 CommandButton

    . O . , ,

    CommandButton, .

    Style Graphical picture

  • 7/23/2019 Visual Basic-2012-13-

    12/26

    4, 811 00 22510-46222 www.platonos.gr12 / 26

    Picture .

    1.9 ListBox

    ( ) .

    .

    .addItem

    list1

    dogcatbox

    List1.additem "dog"List1.additem "cat"List1.additem "box"

    , .

    . ,

    .

    Y listindex .

    "cat" listindex 1 (

    0). listcount. List List1, list1.listcount,

    1.10 ComboBox

    ListBox .

    .addItem

    Combo1

    ComboBox dogcat

    box

  • 7/23/2019 Visual Basic-2012-13-

    13/26

    4, 811 00 22510-46222 www.platonos.gr13 / 26

    Combo1.additem "dog"Combo1.additem "cat"Combo1.additem "box"

    listindex listcount list boxes

    1.11 Timer

    .

    Timer . Timer ( interval, ! 1000 Interval 1

    .

    Timer

    enabled interval (

    0, 200)

    1.12 Image

    Picture ImageStretch true (

    ) Image

    1.13 Picture

    Picture PictureAutosize true (

    )

  • 7/23/2019 Visual Basic-2012-13-

    14/26

    4, 811 00 22510-46222 www.platonos.gr14 / 26

    1.14 (Control Arrays)

    .

    26 command buttons caption ( Z). 26 command buttons, command1, command2, .Command26, command buttons. command button command1. , control array . commandbuttons . command1(0), command1(1), ., 26 command1(25). (index). caption A,B,Z buttons

    for ( : 3.8).For i=0 to 25

    Command1(i).Caption=chr(i+65)Next i

    command buttons . index. command button control array

    Private Sub Command1_Click(Index As Integer)Msgbox( command1(index).caption )

    End Sub

    command1 button.

    2. (Events)

    . ,

    .

    ( ).

    2.1 DragDrop

    . , source.

    2.2 MouseDown

    ' ( ).

    To chr() Ascii. chr(65) .

    ASCII , . (2.3)

  • 7/23/2019 Visual Basic-2012-13-

    15/26

    4, 811 00 22510-46222 www.platonos.gr15 / 26

    2.3 keyPress ASCII

    textboxes. scii () KeyAscii. KeyAscii

    . text1, .

    PrivateSub Text1_KeyPress(KeyAscii As Integer)If KeyAscii < 48 Or KeyAscii > 57 Then

    KeyAscii = 8EndIf

    EndSub

    ( Ascii 0 48, 1 49 Ascii 9 57. Ascii 8 Backspace). , text1 (.. !) backspace . ,

    !!! : ,

    Msgbox() :

    PrivateSub Text1_KeyPress(KeyAscii As Integer)MsgBox(KeyAscii)

    EndSub

    ASCII

    ASCII

    0..9 48..57

    backspace 8

    space 32

    Esc 27Enter 13

    A..Z 65.. 90

    a..z 97..122

    ..() 193..209..() 211..217. 210

    .. ( ) 225..249

  • 7/23/2019 Visual Basic-2012-13-

    16/26

    4, 811 00 22510-46222 www.platonos.gr16 / 26

    3.

    3.1 ()

    , , .

    .

    3.2 Fontsize

    .Fontsize=15 .Fontsize-13 .Fontsize=21

    3.3 .FontBold [= true false] .FontItalic [= true false] .FontStrikethru [= true false] .FontUnderline [= true false]

    3.4 rnd rnd*10 0 9.

    rnd*64 0 63,999

    rnd*128 0 127,999rnd*50 0 49,999rnd*10 0 9,999 int(rnd*50) 0 49, int integer=, . 1+int(rnd*50) 1 50 1+int(rnd*10) 1 10 5+int(rnd*10) 5 14 5+int(rnd*11) 5 15 5+int(rnd*(15+1-5)) 5 15

    a=5 b=15 b b, a+int(rnd*(b+1-a))

    3.5 randomize timer randomize timer.

    3.6 if

    ( truefalse)

  • 7/23/2019 Visual Basic-2012-13-

    17/26

    4, 811 00 22510-46222 www.platonos.gr17 / 26

    if

    (true)else

    (false)

    end if

    . ifi> 18 thenprint ""

    elseprint ""

    end if

    2 . else 1 endif. :

    If i> 18 then

    print ""end if

    m , label1.caption , ( 1 12) .

    If m= 31 or m=1 or m=2 thenLabel1.caption=

    Elseifm= 3 or m=4 or m=5 thenLabel1.caption=

    Elseifm= 6 or m=7 or m=8 thenLabel1.caption=

    Elseifm= 9 or m=10 or m=11 thenLabel1.caption=

    ElseLabel1.caption=

    End if

    3.7 case

    select case case

    case B

    case C

    caseelse

    endselect. a

    label1 , 1, 2

  • 7/23/2019 Visual Basic-2012-13-

    18/26

    4, 811 00 22510-46222 www.platonos.gr18 / 26

    select case acase 1

    print ""case 2

    print ""

    case 3print ""

    case 12

    print ""caseelse

    print " !!!"endselect

    3.8 (Loop) For .... Next

    ( ) print

    for i=1 to 20print print 20

    next i

    i 1 20, 1( 1 ). 20 (i

  • 7/23/2019 Visual Basic-2012-13-

    19/26

    4, 811 00 22510-46222 www.platonos.gr19 / 26

    3.9 While Wend

    .

    While

    . .

    Wend

    a=26b=2while a>0 do

    a = a-b

    wend

    a . 0, . ( ), . , , , .

    3.10 Do .Loop until

    . , .

    Do

    . .

    LoopUntil

    a=26b=2

    do

    a = a-bloopuntil a

  • 7/23/2019 Visual Basic-2012-13-

    20/26

    4, 811 00 22510-46222 www.platonos.gr20 / 26

    3.11 Do .Loop while

    Do .Loop until, ,

    . , . ,

    .

    Do

    . .

    Loop While

    a=26b=2do

    a = a-bloop while a>0

    a . 0, . ( ),

    . , ,

    , .

    3.12 msgbox()

    . .

    msgbox( , , )

    . , .

    =msgbox( , , )

    :A=msgbox( ,4 , E )

    :

  • 7/23/2019 Visual Basic-2012-13-

    21/26

    4, 811 00 22510-46222 www.platonos.gr21 / 26

    ( buttons) .

    : Buttons

    vbOKOnly 0 OK button.vbOKCancel 1 OK and Cancel buttons.vbAbortRetryIgnore 2 Abort, Retry, Ignore buttons.vbYesNoCancel 3 Yes, No, Cancel buttons.vbYesNo 4 Yes No buttons.vbRetryCancel 5 Retry Cancel buttons.

    vbCritical 16 Critical Message icon.vbQuestion 32 Warning Query icon.vbExclamation 48 Warning Message icon.vbInformation 64 Information Message icon.

    vbDefaultButton1 0 button vbDefaultButton2 256 button vbDefaultButton3 512 button vbDefaultButton4 768 button

    . .

    260 ( 4 :

    256+4=260) button

    :

    1 OK2 Cancel3 Abort4 Retry5 Ignore6 Yes7 No

    WINDOWS buttons .

    3.13 InputBox

    . ,

    .

    OK .

    =InputBox, y - )

    =InputBox (, ,

    (),

    X,Y - -

    ())

  • 7/23/2019 Visual Basic-2012-13-

    22/26

    4, 811 00 22510-46222 www.platonos.gr22 / 26

    a=inputbox( , )

    3.14 LEN()

    . .text .caption .

    G , Len(G) , 11.

    text1.text , Label1.Caption=LEN(text1.text) 15 Label1.Caption.

    3.15 Mid() .

    G , mid(g,3,4) .

    3.16 val() . 0 ().

    Val( )

    a Val(a)

    12 12

    15 152 34 2 0

    3.17 instr() , .

    Instr( , , )

    a :

  • 7/23/2019 Visual Basic-2012-13-

    23/26

    4, 811 00 22510-46222 www.platonos.gr23 / 26

    Instr(1,a,) 6Instr(8,a,o) 11Instr(1,a,) 0 ( )

    3.18 IsNumeric() , . true false.

    :IsNumeric( )

    : text1.text IfIsNumeric(Text1.text) then

    MsgBox( )endif

    3.19 Visual Basic

    pixels ( , ...).

    / . Visual Basic twips (1440 twips=1 ). . scalemode = .

    . .. scalemode=3, pixels.

    ScaleMode1 = twips 1 twip=1/1440 !2 = points (72 points / inch3 = pixels4 = character (120 twips/char 240 )5 = inches6 = mm7 = cm

    3.19.1 ScaleWidth ScaleHeight 2 () .

    scalemode =3 800*600,

    scalewidth 800 scaleheight 600. cx = scalewidth/2 cy = scaleheight/2, (cx ,cy ) .

    3.19.2 2 . 2 .

    3.19.3 Line .

    Line (a , b )-(c , d ),

  • 7/23/2019 Visual Basic-2012-13-

    24/26

    4, 811 00 22510-46222 www.platonos.gr24 / 26

    ( a , b ) = ( c , d ) = = . (

    (ForeColor) ).

    , ( a , b ) ( c , d ) . ,F .

    :Line (0 ,0)- (Scalewidth, Scaleheight)

    .

    3.19.4 ForeColor

    ForeColor = QBcolor (x) x = 0 15

    ForeColor = QBcolor (rnd* 15)

    3.19.5 Circle , ( ), Circle ( a , b ), , , ,

    (a , b) = r =

    = (360 2* ).

    .

    Circle ( a , b ), r.. Circle ( cx , cy ), 100. 100

    3.19.6 Line Circle

    FOR:for i = 0 to scalewidth step 2

    forecolor = QBcolor ( i mod 15 )line(cx, scaleheight)- (i,0 )

    next i

    for i =0 to cx step 5circle(cx ,cy ), i

    next i

  • 7/23/2019 Visual Basic-2012-13-

    25/26

    4, 811 00 22510-46222 www.platonos.gr25 / 26

    3.19.7 DrawWidth drawWidth=4 ( 1)

    3.19.8. . Line Shape . .

    3.20

    . :

    . module

    Public Declare Function mciSendStringA Lib "WinMM" _

    (ByVal MCIcommand As String, ByVal returnStr As String, _

    ByVal returnLength As Integer, ByVal callBack As Integer) As Long

    Public Sub hearmusic(ff As String)

    kk = "play " & ff

    a = mciSendStringA(kk, returnStr, 255, 0)

    If a 0 Then

    MsgBox ("Error in calling the file....")

    End If

    End Sub

    , :

    hearmusic (" ") ,hearmusic ("c:\visbasic\drum1.wav")

    3.21 ASCII

    ASCII. command button :nooftrials = 0

    Const maxlines = 1000

    choosefile:

    On Error GoTo filenotchosen

    CommonDialog1.Filter = " ASCII txt|*.txt"CommonDialog1.ShowOpen

    Open (CommonDialog1.filename) For Input As #1

    ' (array)

    i% = 0 ' ..!

    Dim arr(maxlines) As String ' !

    While Not EOF(1) And i% < maxlines

    i% = i% + 1

  • 7/23/2019 Visual Basic-2012-13-

    26/26

    Line Input #1, arr(i%)

    Wend

    a = MsgBox(" " & i% & " ", , "")

    Close #1

    Exit sub

    filenotchosen:

    nooftrials = nooftrials + 1

    If nooftrials < 4 Then

    a = MsgBox(" ", , " ")Resume choosefile

    Else

    a = MsgBox(". ..", , " ")End

    End If

    .

    . 4

    . .

    Visual Basic 5.0 .

    , , , .