การเปลี่ยนข้อความในคอมโพเนน label1 ต้องกำหนดค่า properties ใด

��Ѻ��úѭ (Back to Content)

��������� (Program Language) # ��� �Ըա���ҵðҹ㹡�������������Ѻ�ʴ��������ѧ���������� �����������˹����ҡó���С�õդ������¨ҡ�������������������¹��� ����������������������������ö�к����ҧ�Ѵਹ�֧�����ŷ�����������зӧҹ ����Ըա�÷�����������л����żŢ���������ҹ��
������Ԥ (Basic Language) ��� ���Ҥ�����������Ѳ���¨��� ������ (John Kemeny) ��� ����� ��õ�� (Thomas Kurtz) ����Է����´�������� (Dartmouth College) 㹻դ.�. 1963
�Ԫ����ԡ (Visual Basic) ��� ���Ҥ�������������Ѻ���ҧ���������ء�� (Application) �����ҹ�����ҧ��ҡ���º��к���Ժѵԡ���Թ��� �������ö���¡���ѵ�ط����������������������ԡ�� Programming :: VB :: VB.NET :: ASP.NET :: GWBasic :: ASP ::
�͹��� 1 :�� general component ����к��������������á
Download : chap001.zip
����� 1 : ���ҧ form ��л��� close
������������ ������¹�ͧ���ҧ��������� � ��� 1 ����� ������ҧ������� 1 ���� �»���������Ҩҡ General componets, Command button �ҡ������ Double click �˹�ͻ��� Command button ����������ǹ code ������������� Unload me ����繤���觻Դ������Ѩ�غѹ �ҡ�����觨Ѵ�纨������ chap001.vbp ����Ѻ�����ҧ�ԧ��������� ��ǹ chap001.frm �����¶֧����������� code �����������㹿���� ������ҧ���������Ӥѭ��§ 2 ����ѧ���ҧ��ҹ��
    ����觤�÷�Һ
    unload me
Ẻ�֡�Ѵ
? ���ҧ����� ������������Դ������ա����˹��
? ���ҧ command button ������������� msgbox("x")
? ���ҧ command button ������������� x = InputBox("abc", "def")

Download : chap002.zip
����� 2 : �����Ǻ����ǡ ���ź�ͧ textbox
���ҧ���� 2 ���� ���ͤǺ�������ʴ���� text box �»������� text box �����Ѻ��� ����ǹ�˭� ��㹷����������Ѻ����ʴ��ŷ���Դ�ҡ��á����� �ǡ ����ź �·�����Ҩӹǹ����¹�ŧ�
    ����觤�÷�Һ
    Text1 = Text1 + 1
Ẻ�֡�Ѵ
? ���ҧ�����ٳ�ͧ
? ���ҧ�����ǡ�ͧ
? ���ҧ text box �ա 1 ��з�����úǡ ź �� text box ������������

Download : chap003.zip
����� 3 : ����¹�س���ѵԢͧ shape ���ٻ�ç��ҧ �
��˹��ٻ��ҧ���Ѻ Shape ����� general component ˹�� �¤�Ңͧ shape �� 0 = rectangle, 1 = square, 2 = oval, 3 = circle, 4 = rounded rectangle, 5 rounded square �¡�����͡�ҡ���� Option button ����������Ѻ frame �з��������ö���͡������� 1 ����
    ����觤�÷�Һ
    Shape1.Shape = 1
    Shape1.Shape = 2
Ẻ�֡�Ѵ
? ������� frame ���������͡��˹� backcolor ���� bordercolor ���� fillcolor
? ���������ͧ ����Ѻ��˹���Ҵ width ��� height �ͧ shape

Download : chap004.zip
����� 4 : ����� menu editor ���ҧ menu bar ��ǹ���
Right click ����鹿���� ���յ�����͡ Menu editor ������͡�������ҧ�к� menu Ẻ Ẻ pulldown menu ���§��� �ҡ��������������ա���� ����� click ��������͡������ö������觷���ͧ������Ѻ������͡�� ������ҧ�������͡������͡��������¹��Ҵ�ͧ Label �������㹿����
    ����觤�÷�Һ
    Label1.FontSize = 10
Ẻ�֡�Ѵ
? ���� label �������¹��Ҵ�� 2 label ������ѹ
? ����������͡ ������ msgbox

Download : chap005.zip
����� 5 : ���ҧ���� form �������Դ�Դ�����ͧ���
���ҧ����� 3 �������� project ��� ���п�����ջ������Դ��������� ��������� 3 �Դ���ͧ��п������� 2 ���Դ����� 1 ����� ����Ѻ code �ͧ���п������������㹿������� � �����¡�纵�ҧ�ҡ
    ����觤�÷�Һ
    Unload Me
    Unload Form2
    Form1.Show
Ẻ�֡�Ѵ
? ���ҧ�������� 4 ��� ���ջ�������Դ�Դ��������
? ���ҧ�������� 5 ����դ���� msgbox ��Шӻ���

Download : chap006.zip
����� 6 : �Ǻ��� visible �ͧ���� object
���ҧ frame ��л����Ǻ�������Դ�Դ ���� frame �»������� frame ����ö��è� component ���ҡ��� �������ʴ�������� ���繡���Ǻ件֧ component ������� frame ��鹴���
    ����觤�÷�Һ
    Frame1.Visible = False
    Frame1.Visible = True
Ẻ�֡�Ѵ
? ���ҧ frame ���� ��л��������繻�������
? ���ҧ frame ���� �������ջ�������� frame ���

Download : chap007.zip
����� 7 : �����Ţ ���ͷ��ͺ��äǺ��� list box
�����Ţ����� list box 20 �ӹǹ �������ҧ���� clear ��ҷ����� ����ź�ҧ��� �� text ����ʴ���һѨ�غѹ cursor ����� list ��÷Ѵ������� ����դ���
    ����觤�÷�Һ
    Randomize (Timer)
    For i = 1 To 20
    List1.AddItem Int(Rnd * 100)
    Next

    List1.Clear

    List1.RemoveItem (Text2)

    Text1 = List1
    Text2 = List1.ListIndex

Ẻ�֡�Ѵ
? ����Ẻ�����ӹ�������
? ��������Ţ�ҡ���� 20 �ӹǹ ����դ���ҡ���� 2 ��ѡ

Download : chap008.zip
����� 8 : �����Ţ ����� list box �������� combo box �ա����
�����ҡ����� 7 ������ö�Ѵ�͡��Ҩҡ list box ����� combo box ������Ѻ�ӹǹ� combo box ����Ѻ�����
    ����觤�÷�Һ
    List1.SetFocus
    List1.ListIndex = 5

    Combo1.AddItem List1
    Text1 = Combo1.ListCount

Ẻ�֡�Ѵ
? ���ҧ combo box ���Ѻ����ա���˹�� ���ѹ�Ѻ�ͧ���
? �Ҽ�����ͧ�ء���� combo box �ʴ�������ӹǹ

Download : chap009.zip
����� 9 : �����Ţ�ӹǹ�ҡ ����� list box, combo box ��е�Ǩ�����
List box �Ѻ�ӹǹ���٧�ش 32736 �ӹǹ ���к�÷Ѵ���ͧ��Ҥ�蹴��� , �ҡ��鹹ӷ�� 2 ���������ѹ �������¤����ѧ combo box �ҡ������º��º��ҷ����������Ţ���(Even) �����Ţ���(Odd) �����ʴ���
    ����觤�÷�Һ
    y = Split(List1, ",", -1, vbTextCompare)
    z = Int(y(0)) + Int(y(1))
    Combo1.AddItem z
    Combo1.Text = z
    List1.RemoveItem List1.ListIndex
    Text2 = "Even"
    If z Mod 2 = 1 Then Text2 = "Odd"
    Text1 = Combo1.ListCount
    List1.SetFocus
    List1.ListIndex = z
Ẻ�֡�Ѵ
? ����Ҽ���� 2 ������������ �������¹�繼Ťٳ
? ����� 2 ��� ����к�÷Ѵ ��������� 3

Download : chap010.zip
����� 10 : ���� ź ��䢨ҡ list box �¤�� visible ��� enabled
���ͧ��÷ӧҹ�ͧ��� ���ջ��� ���ҧ�����������ҧ ���� ź ������ �����л����ӧҹ�Ǻ���Ѻ�������ʴ� text box �����ҧ������� ����Ѻʹ
    ����觤�÷�Һ
Ẻ�֡�Ѵ
? �������ࢵ������
? �������¹��������

Download : chap011.zip
����� 11 : ������ǹ˹����ǹ㴢ͧ����¹����
���ͧ��÷ӧҹ�ͧ����蹡ѹ ���ʴ���÷ӧҹ੾����ǹ�ͧ filter �������͡�����ŷ���ͧ��� �ҡ�ش㴡����ͧ��������¹ �����ʴ�����¹������ѡ�õ������ͧ��ú�è�����
    ����觤�÷�Һ
    List1.ListIndex = -1
    For i = 1 To List1.ListCount
    List1.ListIndex = List1.ListIndex + 1
    If InStr(1, List1, Text1, vbTextCompare) > 0 Then
    List2.AddItem List1
    End If
    Next
Ẻ�֡�Ѵ
? ����ࢵ������
? ������� ź ��� ��ҡѺ��������

Download : chap012.zip
����� 12 : ���Ң�����Ẻ���͡�ҡ���� ��е�� primary key
���ͧ��÷ӧҹ�ͧ����蹡ѹ ���繡�ä�����ա 2 �Ը� ������͡����¹����պҧࢵ�������դ�Ҩӹǹ�ҡ���ҷ���˹� �������͡�ʴ����ࢵ�����ŷ���� primary key
    ����觤�÷�Һ
    For i = 1 To List1.ListCount
    List1.ListIndex = List1.ListIndex + 1
    y = Split(List1, ",", -1, vbTextCompare)
    If y(0) = Val(Text2) Then
    Text3 = y(1)
    Text4 = y(2)
    End If
    Next

    List1.ListIndex = -1
    For i = 1 To List1.ListCount
    List1.ListIndex = List1.ListIndex + 1
    y = Split(List1, ",", -1, vbTextCompare)
    If y(2) > Val(Text1) Then
    List2.AddItem List1
    End If
    Next

Ẻ�֡�Ѵ
? ����ࢵ������
? ������ա�ä������� 3 Ẻ
? ������� ���� ź ���

Download : chap013.zip
����� 13 : �Դ�Դ����� ����Ҿ㹨ش��ҧ �
�ʴ�����Դ�Դ��������� form1.show ���� form1.visible = true ��С������Ҿ� picture �ͧ��� ���� ��� image ����Ѻ�������Ҿ㹻�����ͧ��˹���� style ��Ẻ graphic �֧�����Ҿ�͡㹻��� ��ǹ�Ҿ��鹨е�ͧ���Ҿ��Ẻ�����ҧ��ҷ���ͧ��á�͹��
    ����觤�÷�Һ
    form2.visible = true
    '
    form2.show
    '
    end
    '
    unload form1
Ẻ�֡�Ѵ
? ��Ẻ������ ������¹�Ҿ
? �� game �Ѻ�Դ�Ҿ����͹ ��Ҷ١�֧�Դ form ����

����������� �����繵�ͧ Download
������ʴ����ԡ� �Թ���ǵ����ͧ��� ����ö��任���ء��Ѻ�������ҧ � �� ���� Timer component ���¨Ѵ��ô�ҹ���� ��觷���ͧ�� ��ͻ�Ѻ properties �ͧ timer ���ǹ�ͧ interval ����� 1000 ��� 1 �Թҷ�
    ����觤�÷�Һ
    Private Sub Timer1_Timer()
    Text1 = Format(Time, "long time")
    End Sub
Ẻ�֡�Ѵ
? ��Ẻ������ ��Ѻ�ٻẺ�����§��
? ���������ҧ � ��й�任���ء�������ҹ�����ͧ���

Download : photoword.zip | photoword.exe
�繡�äǺ��� object ��ҧ � ����Դ�Դ�س���ѵ� �����ͧ��� �繡����¹������ ���ҡ㹡���ҧἹ ��С�����Ҿ �س���ѵԷ������Ǣ�ͧ�� enabled visible transparent width height backstyle caption windowstate
    Source code �����ҹ
Ẻ�֡�Ѵ
? ��Ẻ������ ��Ѻ�ٻ�Ҿ���Ҿ���
? ��价�����ҹ���ҡ���
? ��任���ء������Ѻ�Դ�Ҿ

Download : ballrun.exe
�������Ǩ�ͺ���˹觢ͧ�ѵ�ط�����㹨��Ҿ ����� width �Ѻ height �����ҡ ���ͤ�����ͧ������֡�� ��͡�����¹����äǺ����ѵ�� �������¹�ŧ���˹� ������ªԹ�Ѻ��äǺ��� width height left top ��С���ʴ���
    Source code �����ҹ
Ẻ�֡�Ѵ
? ��Ẻ������ ��Ѻ��Ҵ�ٻ ��������¹�� image
? ���� object 㹡�����
? ������ء�� ������¹�Ҿ ��������� ��� object ���ٴբ��

Download : dif.zip | dif.exe

������ҧ���������ǡѺ���� �����ʹ�
Text1 = Time - CDate(Form2.Text1)
Text1 = Format(Text1, "long time")
���������ʴ���äǺ����ѵ�� �Ӻ���� 15 �һ�Ѻ��ا ����������������������¿���� �ա���觤�������ҧ����� ��������� end ��ش����� ��觷���ҡ㹡����¹���������� ������Ҿ�����ʹ� �����ҧ�繵�����͡ ��ǹ��������鹡�äǺ����ѵ�� ��С���觤�������ҧ���������ѡ
    Source code �����ҹ
Ẻ�֡�Ѵ
? ��Ẻ������ ����¹ image ��л�Ѻ���ٴ��ҡ���
? ���� level �����������������ҡ��� ᷹��������§ 3
? ������ء�� ���͡Ẻ����ҧ � �������ͧ

Download : numtxt.exe
����� 18 : ����¹�ӹǹ�Թ�繵���ѡ��
��������� source code �Ҩҡ��红ͧ �.���� ��Ե�ѭ����ԭ thanom.net �¹ӵ���Ţ�ҡ text1 ���ŧ�繵���ѡ�� ������ŧ text2 �������������¹����Ţ�ѹ����������¹ ������س���ѵ� on change ������¹����ö��任���ء��Ѻ�к��ҧ��áԨ��ѹ�� �����������á�����ʴ������¹ function �����ҹ ����ҧ仨ҡ sub ���� function ���Ф�ͤ�Ҩҡ��û����ż�
    Source code �����ҹ
Ẻ�֡�Ѵ
? ��Ẻ������ ����¹�ٻẺ ��������س���ѵ� on change ���� command_click ᷹
? �ͧ����������Ѻ object ��ҧ � �����ջ���ª����
? ������ء�� �����ҧ�ó��֡�һ�Сͺ����� function ���

Download : slide.exe
����� 19 : ��Ŵ� ���ʹ͢����ž�����Ҿ
�������������͹ slide ��ͧ������ next ���� previous ������ա���� ������ �ͧ image1 ��������ҧ image1 ������� copy image1 �������ҧ array �ա 3 object ��ǹ text1 ��������������¹�س���ѵ� multiline ��������͡����� readonly �֧��ͧ����¹Ẻ manual ��ǹ�Ҿ ���ͧ��¹������觪����Ҿ��Ҥس���ѵ� picture ��������Ѻ ���� msgbox �٤س���ѵ� ��ҡ�����繵���Ţ ������Һ���������� �Ҿ���������� image ��
    Source code �����ҹ
Ẻ�֡�Ѵ
? ��Ẻ������ �������ӹǹ slide ����¹�Ҿ �������¹�����ŴٹФ�Ѻ
? �ͧ���������� slide ����͹�ͧ��
? �ͧ���� slide � 1 form ������Ѻ ���������仴��� ����բ����������ٻẺ

����� 20 : ����ͧ�Դ�Ţ���ҧ������੾�л��� +
���ҧ 1 textbox �Ѻ command1 Ẻ array 0 �֧ 13 ������ 10 ��� + ���� 11 ��� = ���� 12 ��� C ���� 13 ��� Backspace �¹ѡ�֡�ҵ�ͧ���������� Caption ���µ��ͧ�Ф�Ѻ ���ǡ�Ѵ���˹������§�� ���ж���� code �Ѵ�����ͧ��鹷�� source code �ҡ��鹡��� source code �������� �դ�������ö�����������͹����ͧ�Դ�Ţ� windows �ء��С�� .. (੾�л����������ҧ�Ф�Ѻ)
    Source code �����ҹ
Ẻ�֡�Ѵ
? ��Ẻ������ �ջ��� + ��������
? ��������ź �ٳ ���
? ���������ŧ�Ţ�ҹ

�Ҩҡ������ҧ 18 ����¹�ӹǹ�Թ�繵���ѡ�� ���������§��ҹ����ѡ������
    Source code �����ҹ
Ẻ�֡�Ѵ
? ��Ẻ������ �ջ��� + ��������
? ����¹�繹Ѻ�Ţ����͹ Bank

�͹��� 2 :�к��ҹ���������� Data Control
Download : chap101.zip
����� 101 : �� Data control �����Ѻ Text box
���������� Data control(Data component) �֧�����Ũҡ Microsoft Access ���� ������� Textbox �Ѻ�����Ũҡ Data control �ա����˹�� �Ըչ������ö��䢢��������� Microsoft access ���µç .. ������ҧ�������ա�����¡�� component ��������� ������ҧ��������� ��������ͧ��ҹ����� Nwind.mdb ������������ѡ�Դ����Ҿ���� Visual Basic
    ��鹵͹
    1. �Դ VB6.0 �������͡ Standard EXE ���� Open
    2. click Textbox �ҡ Toolbox
    3. ����͹ mouse 价�� form ���� click ��ҧ��� ������ҡ价ҧ��Ң�Ҵ������������
    4. �ӵ����� 3 ���ҧ text2 ��� text3 ���������ʴ�������
    5. click Data ���� Data control �ҡ Toolbox ���ǷӤ���¢�� 3
    6. ��ػ���� form1 ���� Object ���� 4 Object �Ф�Ѻ
    7. ��˹��س���ѵ� ���� Properties ���Ѻ Data1 3 ���ҧ�ѧ�����Ŵ�ҹ��ҧ
    8. ��˹��س���ѵ� ���� Properties ���Ѻ Text1 2 ���ҧ�ѧ�����Ŵ�ҹ��ҧ
    9. ��˹��س���ѵ� ���� Properties ���Ѻ Text2 2 ���ҧ�ѧ�����Ŵ�ҹ��ҧ
    10. ��˹��س���ѵ� ���� Properties ���Ѻ Text3 2 ���ҧ�ѧ�����Ŵ�ҹ��ҧ
    11. ���ǡ� save Project ����ͧ�����������¹ .. �������¡���ա��������
    12. �š�èѴ�纨��� 2 ���Ǥ�� .vbp ��� .frm ��� save ���ǡ��ͧ�Դ VB
    13. �ͧ�Դ VB ����Դ��� .vbp ���������٤�Ѻ
    14. ����ջѭ�ҡ�÷ӵ�� ���仴ٺ���� 107 ����������������� �������ҧ��������Ѻ

    ��͡�˹�� Properties
    Data1 Properties
    Databasename = C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb
    RecordType = Table
    RecordSource = Categories
    Text1 Properties
    Datasource = Data1
    Datafield = CategoryID
    Text2 Properties
    Datasource = Data1
    Datafield = CategoryName
    Text3 Properties
    Datasource = Data1
    Datafield = Description
Ẻ�֡�Ѵ
? �������¹�� table ��� �� Customers ���� Employees �繵�
? ������ҧ��� .mdb ���ͧ ������¡ table �ͧ���ͧ

Download : chap102.zip
����� 102 : �� Data control �����Ѻ DBGrid
���� Toolbox ����� DBGrid ��顴���� Ctrl-T ���Ƿ�����ͧ���¶١˹�Ҥ���� Microsoft Data Bound Grid Control 5.0(SP3) (c:\windows\system\dbgrid32.ocx) ���ǡ����� apply �з������ Control ����������� Toolbox �ա 1 Object ������� DBGrid ���͡ DBGrid �ҡ Toolbox ���� click �ҡ��Ҵ����ҳ 80% �ͧ������ form1 ����Ѻ˹�ҷ��ͧ DBGrid ���͹Ӣ����Ũҡ Data control ��ʴ����ҧ�����ҧ���� ����ѧ����ö��䢢�����㹵��ҧ��ѹ�� 㹺�������������Ǣ�ͧ 3 ��� ��� .vbp ��� .frm ������繻��� ����� .frx �Դ��� ���С���� DBGrid �ҡź������ DBGrid �����������㹿����������仴���
    ��͡�˹�� Properties
    ��ǹ�ͧ Data control ��˹�����͹ 101
    DBGrid1 Properties
    DataSource = Data1
Ẻ�֡�Ѵ
? �������¹�� table ���
? ������ҧ��� .mdb ���ͧ ������¡ table �ͧ���ͧ

Download : chap103.zip
����� 103 : ���� record ������� Data control ��ФǺ��� visible + enabled
�����������鹡�˹���� object ��ҧ � visible=false ��ѧ������ addnew �֧���ʴ� object �Ţͧ��á����� add ���ѧ����� record �Դ��� �����Ҩ���� update ��ѧ update �ء���ҧ��Ѻ�����ش����������� �������Ѻʹ��Ң�й���ͧ������ ��е��ҧ categories ��˹���ҵ�ͧ�բ������ category name ��ҷ�ҹ������ update �»�͹������ ���Դ error �֧��ͧ��ͧ�ѹ�ش������ ���¤���� if
    ��͡�˹�� Properties
    ��ǹ�ͧ Data control ��˹�����͹ 101

    ����觤�÷�Һ


    Data1.Recordset.AddNew

    If Len(Trim((Text2)) > 0 Then

    Data1.Recordset.Update
    Else Data1.Recordset.CancelUpdate Msgbox "����ա�û�Ѻ��ا���"
    End If
Ẻ�֡�Ѵ
? �������¹�� table ���
? ������ҧ��� .mdb ���ͧ ������¡ table �ͧ���ͧ

Download : chap104.zip
����� 104 : ź record ���¡�ä��Ҩ��� ���Ǩ֧ update ���� cancel
��������Ѻ�Ţ ���Ǥ���(Seek) ��� CategoryId �ҡ�͡���ʴ���Ңͧ record ��� �������顴���� update ����ź��ԧ
- Data1.Recordset.Bookmark = �纵��˹觷����� Data control
- Data1.Recordset.Index = ��˹������ Primary key ���зӧҹ�Ѻ seek
- Data1.Recordset.Seek = ��������觼���� Nomatch ��Ҩ�ԧ������
- Data1.Recordset.NoMatch = �Ѻ�Ũҡ��� seek
    ����觤�÷�Һ
    Bookmark = Data1.Recordset.Bookmark
    Data1.Recordset.Index = "PrimaryKey"
    Data1.Recordset.Seek "=", Val(Text4)
    If Data1.Recordset.NoMatch Then
      Data1.Recordset.Bookmark = Bookmark
    Else
      Command2.Enabled = True
      Text1.Visible = True
      Text2.Visible = True
      Text3.Visible = True
    End If

    If MsgBox("Are you sure to delete?", vbYesNo) = vbYes Then
      Data1.Recordset.Delete
      Data1.Refresh
    Else
      MsgBox "����ա�û�Ѻ��ا���"
    End If

Ẻ�֡�Ѵ
? �������¹�� table ���
? ������ҧ��� .mdb ���ͧ ������¡ table �ͧ���ͧ

Download : chap105.zip
����� 105 : ��䢢����� ����ö���͡��� DBGrid, Data bar ��� Seek
������� Data control ��ҹ text box ᷺����ͧ������ ���ǹ�ͧ��� update ���С�ä������ǹ����ʴ� �ҡ�ա����� �зӡ�� update ���㹷ѹ���������� ����ͧ�դ���� update �ա ���ä������к� PK ��§���ҧ������ҹ������ҡ �֧���� DBGrid ��������͡����¢�� ����Ѻ��ͤ�����ѧ㹡���� seek �����Ѻ Data control ��͵�ͧ��˹� Recordsettype �� table ���蹹�鹨��Դ error 㹡����� index ��С�á�˹� Index ����Ѻ Primarykey �С�˹����� field ����� ��Һ����ͧ���ҡ����� "C:\Program Files\Microsoft Visual Studio\VB98\VISDATA.EXE" ��Ǩ�ͺ��� �֧��Һ��ҵ�ͧ���������
    ����觤�÷�Һ
    ��� Properties of DBGrid,Datasource = data1
    ��� Properties of DBGrid,AllowUpdate = false
    Bookmark = Data1.Recordset.Bookmark
    Data1.Recordset.Index = "PrimaryKey"
    Data1.Recordset.Seek "=", Val(Text4)
    If Data1.Recordset.NoMatch Then
      Data1.Recordset.Bookmark = Bookmark
    Else
      Text1.Visible = True
      Text2.Visible = True
      Text3.Visible = True
    End If

    Private Sub DBGrid1_click()
    Text4 = DBGrid1.columns(0)
    Text4.Refresh
    End Sub

Ẻ�֡�Ѵ
? �������¹�� table ���
? ������ҧ��� .mdb ���ͧ ������¡ table �ͧ���ͧ

Download : chap106.zip
����� 106 : DBGrid ������� ź ��� ��С�ä��Ҩҡ Index
�͹ right click �ͧ DBGrid �����͡ retrieve fields �����س���ѵԷ�Һ���� field �ѵ��ѵ� ���㹤س���ѵԼ������͡ AllowAddNew ��� AllowDelete ���������ö�Ѵ��áѺ�����ż�ҹ DBGrid �����ҧ����ó� ���ǹ�ͧ Layout ����ö��˹� width ������� column ���§��� ����ʴ���ä��ҵ�� CategoryID ���� CategoryName ����������˹������ 2 Field ����� Index ��������
    ����觤�÷�Һ
    Private Sub Command1_Click()
    Bookmark = Data1.Recordset.Bookmark
    Data1.Recordset.Index = "PrimaryKey"
    Data1.Recordset.Seek "=", Val(InputBox("Get categoryid"))
    If Data1.Recordset.NoMatch Then
      MsgBox ("Not found")
      Data1.Recordset.Bookmark = Bookmark
    End If
    End Sub

    Private Sub Command2_Click()
    Bookmark = Data1.Recordset.Bookmark
    Data1.Recordset.Index = "CategoryName"
    Data1.Recordset.Seek "=", InputBox("Get categoryname")
    If Data1.Recordset.NoMatch Then
      MsgBox ("Not found")
      Data1.Recordset.Bookmark = Bookmark
    End If
    End Sub

Ẻ�֡�Ѵ
? �������¹�� table ���
? ������ҧ��� .mdb ���ͧ ������¡ table �ͧ���ͧ

Download : chap107.zip
����� 107 : �� Data form wizard �Ѻ ADO data control ���ҧ form ���ҧ����
��鹵͹������ҧ Data form wizard
1. ���͡ Add-Ins �ҡ menu bar �������͡ Add-In manager, VB 6 Data Form Wizard ���� Click ��� Loaded/Unloaded ���ǡ����� OK
2. ���͡ Data form wizard ���¡�� Click ��� Add-Ins, Data Form Wizard..., Next, ���͡ Access ���ǡ����� Next, "C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb", Next, Single record ��� ADO Data control, Next, 㹪�ͧ Record source ���͡ Categories, ���͡ 3 fields �á�Ҵ�ҹ���, next, finish ���� form ��������� project �ͧ��� �ҡ�����ҡ���֡���»��� �����ͧ�֡���� source code �ҡ�����˹����ա�����˹�� ��觼��ͧ���¨ҡ������ҧ������� form1 ������ҡ����
    ��ͤ�÷�Һ
    ���������������¹ code ���
    �����¡���ҧ���� ������Դ��Ҵ�� ok ����

    Source code ��� Wizard ���ҧ���

Ẻ�֡�Ѵ
? �������¹�� table ���
? ������ҧ��� .mdb ���ͧ ������¡ table �ͧ���ͧ

����� 111 : ���ҧ DSN ���� nwind
���ҧ Data Source Name ���� nwind ���ͨй����� VB �� DSN ������ҧ��� ����ö�������������ҧ � ���ҡ��� ������� PHP ��� ASP ������ ��� nwind.mdb ���ҡѺ Microsoft Access �֧�Ӱҹ�����Ź����͸Ժ�� �����͡Ẻ�к���觫����Թ��� ���������繵�����ҧ㹡��͸Ժ���к��ҹ����� ��������ҧ nwind � ODBC ���� ������Ըա���������͢�����Ẻ Microsoft ADO Data Control 6.0 (OLE DB) ����� Component ����ҹ��ͧ��������� toolbox ���µ��ͧ �š������ component ���з��� icon ���� Adodc ���������

����� 112 : ���¡�� Adodc ����ջ�������͹�����¹��ҧ˹��
    ��鹵͹
    - ������� products �ͧ nwind.mdb �� 10 fields ���ͧ�� 3 fields
    - ���ҧ 5 control �ѧ�Ҿ ��� 3 textbox, command ��� adodc
    - ���͡ ADODC properties ���¡�� Right click �ҡ adodc bar � form : ��ǹ General : ���͡ Use ODBC Data Source Name ������� nwind �ҡ list : ��ǹ RecordSource : ���͡ SQL ���Ǿ���� select * from products
    - �س���ѵԢͧ text1 ��� DataSource=Adodc1 ��� DataField=ProductID
    - �س���ѵԢͧ text2 ��� DataSource=Adodc1 ��� DataField=ProductName
    - �س���ѵԢͧ text3 ��� DataSource=Adodc1 ��� DataField=UnitPrice Source code � command1 Private Sub Command1_Click() Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveFirst End If End Sub
Ẻ�֡�Ѵ
? ���ҧ command2 �繻������͡�Ң�ҧ˹�� ���¤���� moveprevious
? ���ҧ command3 ��� 4 �繻��� movefirst ��� movelast
? ����¹���ҧ�ҡ products ����� � (���ҧ�˹����)

�͹��� 3 :�к��ҹ�����Ŵ��� DAO
Download : chap201.zip
����� 201 : ���¡����¹�á ��С����������ʴ�����¹�Ѵ仴��� DAO + JET
����������� ��Ч��� ���е�ͧ��÷�Һ�ӹǹ����¹㹰ҹ������ �֧����Դ���ҧẺ DAO �����ʴ�����������¹�á� Text1 �ҡ����������� �������͹�����¹���� 㹡����¹������ҡ��С�ȵ����Ẻ workspace ��� database �����ջѭ�� �ʴ������������¡ DAO library ����� �����͡ Project �ҡ menu bar �������͡ References �ҡ��鹷�����ͧ�������͡ Microsoft DAO 3.51 Object Library ��з�������¡���������ǡѺ�ҹ������������ ��������������¡���������ʴ���������¹ �ҡ����������ʴ������������¹���仢����
    ��鹵͹
    1. click Project, References.. �ҡ menu bar
    �������� Microsoft DAO 3.51 Object Library ���¡�÷�����ͧ���¶١� check box
    2. ���ҧ Textbox ���� Text1
    3. ���ҧ CommandButton ���� Command1
    4. Copy source code ��ҹ��ҧ �������ǹ�ͧ View code window
    5. Run ����¤�Ѻ

    Source code �����ҹ

Ẻ�֡�Ѵ
? �Ѩ�غѹ�ѧ�����������������ռ� ��䧨֧�������
? ���Ѻ�ӹǹ����¹㹵��ҧ��� � �ٺ�ҧ
? ������ҧ����� field �����ͧ������ 2 ���� 3 �Ԥ�Ѻ

����� 202 : ��������¹�����ͷ���Ẻ DAO recordset ����ʴ�� msgbox
��Ѻ��ا�Ҩҡ����� 201 ��¹�������Ѻ��͹ �ա�õԴ���Ẻ DAO ����� ���ա�õ�Ǩ�ͺ�����١��ͧ�ͧ�������ҡ��� �� ��ͧ�ѹ��þ������ͫ�� ������������¹�ѵ��ѵ� ������ҧ��������� loadlast ����ҹ ���е�ͧ���¡�� 2 �ش ���ͻ���ª��㹡�õ�Ǩ�ͺ �֧��ҹ��������ʴ�� msgbox �����繼Ţͧ�������������
    ��鹵͹
    1. click Project, References.. �ҡ menu bar
    �������� Microsoft DAO 3.51 Object Library ���¡�÷�����ͧ���¶١� check box
    2. ���ҧ Textbox ���� Text1��� Text2
    3. ���ҧ CommandButton ���� Command1 ��� Command2
    4. Copy source code ��ҹ��ҧ �������ǹ�ͧ View code window
    5. Run ����¤�Ѻ

    Source code �����ҹ

Ẻ�֡�Ѵ
? ����¹�ҡ���ҧ categories �繵��ҧ���
? ����¹����ʴ�������� msgbox ��� form ����
? ����¹ �������� ˹�ҷ��ҡ addnew �� edit ���� delete

Download : vbnwind.zip

Program screen

Database screen

����� 203 : ��������¹�����ͷ���Ẻ Data control + DAO recordset
vbnwind.exe ������ download �Ф��� zip ŧ��ͧ c:\program files\vbnwind ����ö���¡ vbnwind.vbp �ҷ��ͺ�� ���� form ������ 10 ����� �����������ʹ㨤�� add_cat.frm ��ǹ������ա 8 ����� �� wizard ���ҧ��������ҧ���� � ��ǹ main ���Ѻ��ا����բ�Ҵ��� 800 * 600
    Source code ������ add_cat.frm
Ẻ�֡�Ѵ
? ����¹�ҡ���ҧ categories �繵��ҧ���
? �����������Ѻ��ا������

�͹��� 4 :�� API �ͧ�к� Windows ������ҧ��ô��Ըջ�С�� API �������¡��� VB
��ͧ�Դ��� WIN32API.TXT ����Ѻ����Դ�����á
Download : chap301.zip
����� 301 : �� GetFreeSpaceA �ͧ kernel32
���ͧ�ҡ��� c:\windows\system\kernel32.dll �տѧ��ѹ��ҧ � ���١��������������¡�� VB ����ö���¡�ѧ��ѹ������ ������ҧ��ҧ��ҧ������¡ GetDiskFreeSpaceA ���� (���Ϳѧ��ѹ��ͧ�˭���硵������˹�) ����пѧ��ѹ�յ���÷��й������� �ҡ����Һ����տѧ��ѹ���� ����ö���¡����� API Text Viewer �ͧ Microsoft Visual Basic ����Ǩ�ͺ�����ҧ � ����պ�ԡ�����ú�ҧ ��������¡��� File, Load Text File... �������͡��� win32api.txt ��������ʴ� Item ������͡ ���������Ѳ�ҤѴ�͡���
������ҧ��ҧ��ҧ���: �����¡�ѧ��ѹ���ӧҹ ������ա�á����� command1 �����觤�����Ѻ text1 �ʴ��ŵ���
    ������ҧ 1 : �ء���ҧ㹿����
    Private Declare Function getdiskfreespacea _
    Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal _
      iprootpathname As String, _
      ipsectorspercluster As Long, _
      ipbytespersector As Long, _
      ipnumberoffreeclusters As Long, _
      iptotalnumberofclusters As Long _
    ) As Long

    Private Sub Command1_Click()
    result =

    getdiskfreespacea("c:\", sectors, bytes, freecluster, totcluster)
    Text1 = Format(sectors * bytes * freecluster, "##,###") & " Bytes"
    Text1 = Text1 & "(" & sectors & "*" & bytes & "*" & freecluster & ")"
    msgbox app.path
    End Sub

    ������ҧ 2 : �¡��С�������� ���㹿����


    ' in module1 (if in form will be error)
    Public Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer
    End Type
    Public Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

    ' in form1
    Private Sub Command1_Click()

    Dim x As SYSTEMTIME GetSystemTime x MsgBox x.wMilliseconds
    End Sub
Ẻ�֡�Ѵ
? �������¹�� drive ��� ���лѨ�غѹ�ѡ������ Drive �ѹ����
? ������¡ GetSystemInfo �ҡ kernel32
? �ʴ� Current Directory ���� app.path � text box
? �ͧ���¡�� API �����蹴��Ԥ�Ѻ

Download : chap302.zip ��� tping.exe
����� 302 : �� icmp.dll ���� ping ���͵�Ǩ�ͺ host ����͢��� class C
���ͧ�ҡ��� c:\windows\system\icmp.dll �տѧ��ѹ��ҧ � ���١��������������¡�� VB ����ö���¡�ѧ��ѹ������ ������ҧ��ҧ��ҧ��� ���͵�Ǩ�ͺ�Ţ IP ����͢��� ������� option ����ͧ��������㹪�ͧ speed �ҵ�ͧ���������Ǣ���������¹ 1000 �� 100 ��ж���������¹��ͧ IP ending �� ping ��§�Ţ���Ǥ���Ţ����˹� ������ IP ending �е�ͧ������Ţ�٧��� ����������� ping ������Ţ����˹�件֧�Ţ����к� �ҡ�����ʴ��˹�ҵ�ҧ��ҹ�� �Ţ�����辺 ���ʴ��˹�ҵ�ҧ��ҹ��ҧ �����ʴ��Ţͧ������ѧ�ջѭ�������ҧ ����������ͧ�˭�֧������Ѻ code �ա����
    ����觤�÷�Һ List2.Clear List3.Clear If List1.ListCount > 255 Then j = List1.ListCount - 255 Else j = 1 For i = List1.ListCount To j Step -1 List1.ListIndex = i - 1 If (Mid(List1, 1, 1) = "[") Then List2.AddItem List1 Else List3.AddItem List1 End if Next . . If Command1.Caption = "START &PING" Then checkip Timer1.Interval = Text6 Command1.Caption = "STOP &PING" Else Command1.Caption = "START &PING" Timer1.Interval = 0 End If
Ẻ�֡�Ѵ
? ��ҹ����о��ѭ�� �����ѭ������ͧ����ʴ���
? ����Ѻ�������˹� IP �״�����ҡ��� ������ͧ�����˭� ? ��ҹ���㨵�����ҧ code ��ҧ��ҧ���������ҧ��  Dim buff As String  Open "c:\test.txt" For Input As #1  filestr = ""   Do Until EOF(1)   Line Input #1, TempStr   filestr = filestr & TempStr & Chr$(13) & Chr$(10)   Loop  Close #1  Text1.Text = filestr  ' Open App.Path & "\output.txt" For Output As #2  ' Print #2, s_Student, s_Grade  

����� 303 : ���������ʧ ����������͡Ѻ server ��ҹ Hidden IE
�����������Ҩҡ //juicystudio.com ��§�� code ������� form �������� transparent form �����ҧ�����ѡ����˹�� ����������� unload me 㹻��� �����繻�����������ҧ���� � (�������� cmdExit) ��������� background ���繢�ͨӡѴ䧤�Ѻ �繡���� api ��� windows ������������� ����ҡ������������������ǹ�ͧ Microsoft Internet Control ��������Դ��� ����觤�Ҽ�ҹ URL �������Ţ Address �ͧ����ͧ Server ���ǡ��红����š���Դ����ͧ����͢������͹���������� ��оѲ�Һ�ԡ�����բ�� ���ǹ�ͧ form_load �����ǹ��������ҡ��ë�͹�������Ѻ
    Source code �����ҹ
    ������ҧ open.php <? $f = fopen("log.txt","a"); fputs($f, $_GET["q"].",".$_GET["n"]."\n"); fclose($f); ?> ������ҧ list.php <? $ar = file("log.txt"); foreach ($ar as $v) echo $v."<br>"; ?>
Ẻ�֡�Ѵ
? ��Ẻ������ �����š� ������������᷺�����繼�
? ���ҧ���� close form �� 1 ����
? �� ball �������� ���Ҩҡ����� 16 �����
? ������ open.php ��� list.php �ӧҹ�����Ѻ .MDB ���� MySQL

กระทู้ที่เกี่ยวข้อง

Toplist

โพสต์ล่าสุด

แท็ก