Friday, September 22, 2017

ການໃຊ້ Timer ໃນ Visual Basic 6 (VB6 Lesso 18)

ການໃຊ້ Timer ໃນ Visual Basic 6 ເພື່ອສະແດງເຖິງການກຳນົດເວລາໃນໂປຣແກຣມ
ມີຕົວຢ່າງດັ່ງນີ້
ເພີ່ມ Timer Control ໃນຟອມ
ໂຄ້ດ:

Option Explicit
' Add a Timer control to your project.  It will be Timer1
' It looks like a stop watch in the IDE.
Dim OldTime As Date
Dim newTime As Date
Dim diff As Date
Private Sub Form_Load()
  OldTime = Time
  Timer1.Interval = 1000
  Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
  Static x As Long
  Static zz$, ss$
  x = x + 1
  newTime = Time
  diff = DateDiff("s", OldTime, newTime)
  Form1.Caption = (diff  3600) & ":" & Format((diff  60 Mod 60), "00") & ":" & _
        Format((diff - ((diff  60) * 60)), "00")
'  Debug.Print (diff  3600) & ":" & Format((diff  60 Mod 60), "00") & ":" & _
        Format((diff - ((diff  60) * 60)), "00")
  If newTime = DateAdd("s", 360, OldTime) Then ' Add 360 seconds
    Timer1.Enabled = False
    ' You time is UP!  Do something!
    Beep
  End If
End Sub

[Read more…]

ການກວດຈັບຊ່ອງ USB (VB6 Lesson 17)

ເປັນໂປຣແກຣມ ກວດຈັບ ຫາ ຊ່ອງ USB ເມື່ອ ເຮົາສຽບ USB ເຂົ້າໃສ່ຄອມ
Image does not exist: https://www.planet-source-code.com/Upload_PSC/ScreenShots/PIC200721912582850.GIF
ມີໂຄ້ດ ດັ່ງນີ້:
ສຳລັບໄຟລໂມດູນ
Module1.bas ແມ່ນປະກາດ API Function ໄວ້

Option Explicit
Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

[Read more…]

Thursday, September 21, 2017

ການເຮັດວຽກກັບໄຟລ ແລະ ໂຟນເດີ (VB6 Lesson 16)

ສຳລົບບົດນີ້ແມ່ນຮຽນກັບກັບ ການຈັດການກັບໄຟລ ແລະ ໂຟນເດີ ໃນພາສາໂປຣແກຣມ Visual Basic 6

1. ການສຳເນົາໄຟລ
ໂຄ້ດ:

FileCopy(SourceFile, DestinationFile)

- SourceFile ແມ່ນໄຟລຕົ້ນທາງ
- DestinationFile ແມ່ນໄຟລປາຍທາງ

2. ການຍ້າຍໄຟລ
ໂຄ້ດ:

Name "c:/test1.txt" as "d:/temp/blabla.txt"

3. ການລົບໄຟລ
ໂຄ້ດ:

Kill "ຊື່ໄຟລ"

4. ການສ້າງໂຟນເດີ
ໂຄ້ດ:

Mkdir "ຊື່ໂຟນເດີ"

5. ການລົບໂຟນເດີ
ໂຄ້ດ:

RmDir "ຊື່ໂຟນເດີ"

ແລະ

6. ການສັ່ງເປີດໄຟລ ໂປຣແກຣມ
ໂຄ້ດ:

Shell(pathname[,windowstyle])

ຕົວຢ່າງ:

' Specifying 1 as the second argument opens the application in 
' normal size and gives it the focus.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)   ' Run Calculator.

Wednesday, September 20, 2017

ການຄວບຄຸມ Keyboard (VB6 Lesson 15)

ບົດນີ້ ເປັນການຂຽນໂປຣແກຣມ ການຄວບຄຸມ Keyboard ໃນ Visual Basic 6
1. ຕາຕະລາງ ຄ່າຂອງ Ascii

ASCII
Chr
ASCII
Chr
ASCII
Chr
8 Backspace 61 = 98 b
13 Carriage Return or Enter key 62 > 99 c
32 Space 63 ? 100 d
33 ! 64 @ 101 e
34 65 A 102 f
35 # 66 B 103 g
36 $ 67 C 104 h
37 % 68 D 105 i
38 & 69 E 106 j
39 70 F 107 k
40 ( 71 G 108 l
41 ) 72 H 109 m
42 * 73 I 110 n
43 + 74 J 111 o
44 , 75 K 112 p
45 - 76 L 113 q
46 . 77 M 114 r
47 / 78 N 115 s
48 0 79 O 116 t
49 1 80 P 117 u
50 2 81 Q 118 v
51 3 82 R 119 w
52 4 83 S 120 x
53 5 84 T 121 y
54 6 85 U 122 z
55 7 86 V 123 {
56 8 87 W 124 |
57 9 88 X 125 }
58 : 89 Y 126 ~
59 ; 90 Z 127 DEL
60 < 97 a    

[Read more…]

ການເຮັດວຽກກັບລະບົບໄຟລ (VB6 Lesson 14)

ໃນບົດຮຽນນີ້ ເຮົາຈະຮຽນກ່ຽວກັບ ການສ້າງໄຟລ ແລະ ບັນທຶກໄຟລ ລົງໄປໃນ ຮາດດິດ ແລ້ວ ອ່ານໄຟລ ໃນໂປຣແກຣມ ທີ່ສ້າງຈາກ Visual Basic 6
1. ການສ້າງໄຟລ
ໂຄ້ດ:

Open "fileName" For Output  As #fileNumber

ຕົວຢ່າງ

Open "c:\My Documents\sample.txt" For Output As #1

ຕົວຢ່າງ ການສ້າງໄຟລ

Private Sub create_Click() 
Dim intMsg As String
Dim StudentName	As String
Open "c:\My Documents\sample.txt" For Output As #1 
intMsg = MsgBox("File sample.txt opened")
StudentName = InputBox("Enter the student Name")
Print #1, StudentName 
intMsg = MsgBox("Writing a" & StudentName & "to sample.txt")
Close #1 
intMsg = MsgBox("File sample.txt closed")
End Sub

[Read more…]

ການນຳໃຊ້ Arrays (VB6 Lesson 13)

ດ້ວຍການກຳນົດ ແລ້ວ Array ເປັນຕົວປ່ຽນໜື່ງ ທີ່ມີຊື່ດຽວ ແຕ່ມັນສະແດງເຖິງຫລາຍຄ່າທີ່ຕ່າງກັນ ເມື່ອເຮົາທຳງານກັບ ໜື່ງລາຍການ ເຮົາສາມາດໃຊ້ໄດ້ໜື່ງຕົວປ່ຽນ ເຖິງຢ່າງໄດ ກໍ່ຕາມ ຖ້າເຮົາມີຫລາຍລາຍການ ເຮົາຕ້ອງປະກາດຕົວປ່ຽນເປັນ ແບບ Array ແທນ

1. Array ໜຶ່ງມິຕີ

Student Name Name(1) Name(2) Name(3) Name(4)

2. Array ສອງມິຕີ

Name(1,1) Name(1,2) Name(1,3) Name(1,4)
Name(2,1) Name(2,2) Name(2,3) Name(2,4)
Name(3,1) Name(3,2) Name(3,3) Name(3,4)

3. ການປະກາດ Array ໜຶ່ງມິຕີ
ແບບໂຄ້ດ:

Dim arrayName(subscript) as dataType 

ຕົວຢ່າງ:

Dim CusName(10) as String
CusName(1) CusName(2) CusName(3) CusName(4) CusName(5)
CusName(6) CusName(7) CusName(8) CusName(9) CusName(10)

[Read more…]

Sunday, September 17, 2017

ການສ້າງ Function ແລະ Sub Procedure (VB6 Lesson 12)

ໃນການຂຽນ Function ແລະ Sub Procedure ໃນ Visual Basic 6 ມີແບບຂຽນຄື:
1. ການສ້າງ Function
ແບບໂຄ້ງສ້າງ:

    Public  Function functionName (Arg As dataType,..........) As dataType
    ຫລື
    Private  Function functionName (Arg As dataType,..........) As dataType

Public ແມ່ນຕົວຊີ້ບອກໃຫ້ Function ນັ້ນ ສາມາດເອີ້ນໃຊ້ໄດ້ໃນ Project ນັ້ນ
ຕົວຢ່າງໂປຣແກຣມ ໃຊ້ Function

Public Function FV(PV As Variant, i As Variant, n As Variant) As Variant
'Formula to calculate Future Value(FV)
'PV denotes Present Value 
FV = PV * (1 + i / 100) ^ n
End Function 
Private Sub compute_Click()
'This procedure will calculate Future Value 
Dim FutureVal As Variant
Dim PresentVal As Variant
Dim interest As Variant
Dim period As Variant
PresentVal = PV.Text
interest = rate.Text
period = years.Text 
'calling the function
FutureVal = FV(PresentVal, interest, period)
MsgBox ("The Future Value is" & FutureVal)
End Sub 

[Read more…]

Subscribe

  • RSS Atom

ອອນລາຍ: 1 | ມື້ນີ້: 14 | ວານນີ້: 25 | ທິດນີ້: 94 | ເດືອນນີ້: 873 | ປີນີ້: 11833 | ລວມ: 78936