Solved

switch to DOS mode

Posted on 2002-06-02
6
180 Views
Last Modified: 2010-05-02
what is the easy way to switch to DOS mode from VB , I want to
copy a file from one directory to floppy disk  as zipfile .
0
Comment
Question by:jeddha
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7049624
In Windows 9x, Me:
Shell "command.com"

In Windows NT, 2000, XP:
Shell "cmd.exe"

Anthony
0
 

Accepted Solution

by:
dhavaljariwala earned 50 total points
ID: 7050507
' you can do this by sending keystrokes to dos programs running.

Option Explicit

Private mvarDestination As Long 'local copy
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SHIFT = &H10

Private Declare Function OemKeyScan Lib "user32" (ByVal wsOemchar As Integer) As Long
Private Declare Function CharToOem Lib "user32" Alias "CharToOemA" (ByVal lpszSrc As String, ByVal lpszDst As String) As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub SendAKey(ByVal sKeys As String)

   Dim vk            As Integer
   Dim nShiftScan    As Integer
   Dim nScan         As Integer
   Dim sOemchar      As String
   Dim nShiftKey     As Integer
   
   ' *** Get the virtual key code for this character
   vk = VkKeyScan(Asc(sKeys)) And &HFF
   ' *** See if shift key needs to be pressed
   nShiftKey = VkKeyScan(Asc(sKeys)) And 256
   sOemchar = " " ' 2 character buffer
   ' *** Get the OEM character - preinitialize the buffer
   CharToOem Left$(sKeys, 1), sOemchar
   ' *** Get the nScan code for this key
   nScan = OemKeyScan(Asc(sOemchar)) And &HFF
   ' *** Send the key down

   If nShiftKey = 256 Then
      ' *** if shift key needs to be pressed
      nShiftScan = MapVirtualKey(VK_SHIFT, 0)
      ' *** press down the shift key
      keybd_event VK_SHIFT, nShiftScan, 0, 0
   End If

   ' *** press key to be sent
   keybd_event vk, nScan, 0, 0
   ' *** Send the key up

   If nShiftKey = 256 Then
      ' *** keyup for shift key
      keybd_event VK_SHIFT, nShiftScan, KEYEVENTF_KEYUP, 0
   End If

   ' ***keyup for key sent
   keybd_event vk, nScan, KEYEVENTF_KEYUP, 0
   
End Sub

Public Sub SendKeys(ByVal sKeys As String)

   Dim X          As Integer
   
   ' *** loop thru string to send one key at a time
   For X = 1 To Len(sKeys)
      ' ***activate target application
      AppActivate (mvarDestination)
      ' ***send one key to target
      SendAKey Mid$(sKeys, X, 1)
   Next

End Sub

Public Property Let Destination(ByVal vData As Long)
   'used when assigning a value to the property, on the left si
   '     de of an assignment.
   
   ' ***Syntax: X.Destination = 5
   mvarDestination = vData
   
End Property

Public Property Get Destination() As Long
   
   'used when retrieving value of a property, on the right side
   '      of an assignment.
   ' ***Syntax: Debug.Print X.Destination
   Destination = mvarDestination
   
End Property
0
 

Author Comment

by:jeddha
ID: 7053604
I want to copy a file from one loaction to another
  shell "command.com /c " & "copy c:\test.txt a:\"
here its not working
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7053827
That is odd.  It worked fine for me.  Did you put the disk in A drive?

Anthony
0
 

Expert Comment

by:jonnyfunfun
ID: 7054018
Why don't you just use a FileSystemObject to copy the file?  It would probably be a lot easier.

Just add a reference to the Scripting Library in your project and use the following code:


Dim fso
Set fso=CreateObject("Scripting.FileSystemObject")
fso.CopyFile filesource, filedestination, overwrite


Just replace the filesource with your source file and the filedestination with your destination file.  The overwrite is an optional boolean which will force the file to be copied if it set to true (by default it is False).  I think the above code is correct.
0
 

Author Comment

by:jeddha
ID: 7066407
I mean DOS mode printing is very fast compared to others
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now