Visual Basic Tip: 12/04/95

Position Cursor, Using "Enter" in Place of "Tab", File Copying.

Position Cursor.  

In the example below, the cursor is positioned over a
button (Command1) on form_load.  This a good example of
something you might want to implement for an About box.
Note that the position is in pixel coordinates.


  x As Integer
  y As Integer
 End Type

 Declare Sub SetCursorPos Lib "User" (ByVal X As Integer, ByVal Y As Integer)
 Declare Sub ClientToScreen Lib "User" (ByVal hWnd As Integer, lpPoint As POINTAPI)


 Sub Form_Load ()
  Savemode% = ScaleMode
  ScaleMode = 3
  P.x = Command1.Left + (Command1.Width / 2)
  P.y = Command1.Top + (Command1.Height / 2)
  ClientToScreen hWnd, P
  SetCursorPos P.x, P.y
  ScaleMode = Savemode%
 End Sub

Using "Enter" in Place of "Tab".

 Sub Text1_KeyPress(KeyAscii As Integer)
   If KeyAscii = 13 Then
     KeyAscii = 0            ' Avoid the beep
     SendKeys "{Tab}"        ' Simulate pressing the Tab key
   End If
 End Sub


File Copying.

 Open "FileIn" For Binary As #1
 whole = LOF(1) \ 32000           'number of whole 32768 byte chunks
 part = LOF(1) Mod 32000          'remaining bytes at end of file
 buffer$ = String$(32000, 0)
 start& = 1
 Open "FileOut" For Binary As #2
 For x = 1 To whole               'this for-next loop will copy 32,000
   Get #1, start&, buffer$        'byte chunks at a time. If there is
   Put #2, start&, buffer$        'less than 32,000 bytes in the file,
   start& = start& + 32000        'whole = 0  and the loop is bypassed.
 buffer$ = String$(part, 0)
 Get #1, start&, buffer$          'copy the remaining bytes at the end
 Put #2, start&, buffer$          'of the file.

Return to Phil's Web Page

Created by: Philip