Create a form named frmMain with the ShowModal property called False asshown in Figure 3and add the following objects:
- TextBox txtTopic with WordWrap attribute is True
- TextBox txtDescriptions with WordWrap attribute is True
- 4 command buttons with names: cmdStart, cmdStop, cmdSetTime, cmdClose, with Caption properties in turn: Start learning, Stop learning, Timing, Close ( see Figure 2 )
And now enter the code 2 for the frmMain form.
As a final step, go back to the Excel editing screen.
Show the Visual Basic toolbar (View-> Toolbars-> Control Toolbox), select Command Button (Figure 3) and place the Data Sheet (asshown in Figure 4), name it cmdHoc with the Caption attribute as Learn.Then double-click the command button to enter the following code:
Private Sub cmdHoc_Click ()
frmMain.Show
End Sub
Now go back to the Excel editing screen and turn off Design mode (click on the size icon and pen), and try clicking the command button to create it. A simple vocabulary learning tool, right?
Hopefully this article is useful for you.
CODE 1
Public Declare Function SetTimer Lib "user32" (ByVal HWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Public TimerID As Long
Public TimerSeconds As Single
Public BLDefaul As Boolean
Public StrTopic As String
Public StrDes As String
Public IntCount As Integer
Public BLHaveStartTimer As Boolean
Sub StartTimer ()
If BLDefaul = Then False
TimerSeconds = 3 'The default is 1 second
End If
TimerID = SetTimer (0 &, 0 &, TimerSeconds * 1000 &, AddressOf TimerProc)
End Sub
Sub SetTime ()
Dim VTime As Single
Dim VAns As String
BLDefaul = False
VAns = InputBox ("Please enter time (seconds) for timer", "Timing")
If Len (VAns) = 0 Then
BLDefaul = False
Else
VTime = CSng (VAns)
TimerSeconds = VTime
BLDefaul = True
End If
End Sub
Sub EndTimer ()
On Error Resume Next
KillTimer 0 &, TimerID
End Sub
Sub TimerProc (ByVal HWnd As Long, ByVal As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
'
'Procedure is được xác định bởi Windows. Put your
'timer-related code here.
'
On Error GoTo Thongbao1
If IntCount = 0 Then IntCount = 2
MsgBox "Your data is not available!", VbOKOnly, "Vocabulary learning tool"
Sub Exit
End If
Else
IntCount = IntCount + 1
End If
frmMain.txtTopic.Text = StrTopic
frmMain.txtDescriptions.Text = StrDes
DoEvents
Sub Exit
Thongbao1:
Call EndTimer
End Sub
CODE 2
Private Sub cmdClose_Click ()
If BLHaveStartTimer = True Then
Call cmdStop_Click
End If
End
End Sub
'To make sure if you have called the Timer, you will not call
Private Sub cmdSetTime_Click ()
Call SetTime
Call cmdStop_Click
Call cmdStart_Click
End Sub
Private Sub cmdStart_Click ()
If BLHaveStartTimer = Then False
Call StartTimer
BLHaveStartTimer = True
End If
End Sub
Private Sub cmdStop_Click ()
Call EndTimer
BLHaveStartTimer = False
End Sub
Private Sub UserForm_
QueryClose (Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please close with the CLOSE button", vbOKOnly, "Vocabulary learning tool"
End If
End Sub
StrTopic = Application.Workbooks ("Timer").
Sheets ("Data"). Cells (IntCount, 1)
StrDes = Application.Workbooks ("Timer").
Sheets ("Data"). Cells (IntCount, 2)
If Len (Trim (StrTopic)) = 0 Then
IntCount = 2
StrTopic = Application.Workbooks ("Timer").
Sheets ("Data"). Cells (IntCount, 1)
StrDes = Application.
Workbooks ("Timer"). Sheets ("Data").
Cells (IntCount, 2)
If Len (Trim (StrTopic)) = 0 Then
BLHaveStartTimer = False
Call EndTimer
CHECK THE SOFT BACK
A reader who introduced "a former disc researcher" had some good advice on emergency boot floppy disks and rescue discs for Windows and other programs: "Don't believe them good ".Floppy disks for long periods of time can damage sectors.To confirm they are still working, you must check them every few months - by booting the PC from that floppy, or evaluating with the disk scanning tool: In Windows 98 and Me, select Start, Programs. Accessories.System Tools.ScanDisk.In Windows 2000 and XP, select Start, My Computer, right-click the floppy, select Properties, and click Tools, Check Now.
Le Van Duyet