There is no easy way to format a floppy disk in Windows 3.1. The following solution is not elegant, but it seems the only way to go unless you use a specially written DLL . Microsoft should have given developers access to this kind of function through the File Manager. Oh, well...
The best way to format a disk is to use DOS (our old friend). Here are some tips.
Make sure that the disk is a floppy (removable) disk!
To make things faster, use the Quick Format option available from DOS 5.0 and above.
Declare The Following
Declare Function WinExec Lib "Kernel" (ByVal lpCmdLine _
As String, ByVal nCmdShow As Integer) As Integer
Declare Function GetNumTasks Lib "Kernel" () As Integer
Declare Function GetDriveType Lib "Kernel" (ByVal nDrive As Integer) As Integer
Declare Function GetTempFileName Lib "Kernel" _
(ByVal cDriveLetter As Integer, ByVal lpPrefixString _
As String, ByVal wUnique As Integer, ByVal _
lptempfilename As String) As Integer
Declare Function GetVersion Lib "Kernel" () As Long
Use the following Function
Function iFormatFloppyDisk (sDriveLetter As String, _
sVolumeName As String) As Integer
Dim sCommand As String
Dim sTempFile As String
Dim iFileNum As Integer
Dim iReturn As Integer
Dim iActiveApps As Integer
Dim sQuickFormat As String
Dim X As Integer
Const SW_HIDE = 0
'MakeSure that the drive if removable
If GetDriveType(Asc(Left(sDriveLetter, 1)) - 65) _
<> 2 Then
FormatFloppyDisk = False
Exit Function
End If
'Format Driveletter
sDriveLetter = Left$(sDriveLetter, 1) & ":"
'If 5.0 or Higher Use Quick Format
If Val(sGetDosVer()) >= 5 Then
sQuickFormat = "/Q"
Else
sQuickFormat = ""
End If
'Get Temp File Name
sTempFile = sGetTempFile("FFD")
'Create Input File (for hands-off operation)
sCommand = Chr(13) & Chr(10) & Chr(13) & Chr(10) & "N" _
& Chr(13) & Chr(10)
iFileNum = FreeFile
Open sTempFile For Output As #iFileNum
Print #iFileNum, sCommand
Close #iFileNum
'Format Disk
iActiveApps = GetNumTasks()
iReturn = WinExec("doswin.pif /c c:dosformat " & _
sDriveLetter & " /v:" & sVolumeName & sQuickFormat _
& "/u <" & sTempFile, SW_HIDE)
Do While GetNumTasks() <> iActiveApps
X = DoEvents()
Loop
'Get Rid Of The Temp File
Kill sTempFile
'Return WinExec Value (any value above 32
‘means success!)
iFormatFloppyDisk = iReturn
End Function
Function sGetTempFile (sPrefix As String) As String
Dim sTempFileName As String
Dim R As Integer
sTempFileName = Space$(144)
R = GetTempFileName(ByVal 0, ByVal sPrefix, _
ByVal 0, ByVal sTempFileName)
sGetTempFile = Mid$(sTempFileName, 1, _
Len(Trim$(sTempFileName)) - 1)
End Function
Function sGetDosVer () As String
Dim lVer As Long
Dim lDosVer As Long
lVer = GetVersion()
lDosVer = CInt(lVer / &H10000)
sGetDosVer = Format$(lDosVer / 256) + "." _
+ Format$(lDosVer And &HFF)
End Function
If this Function returns a value greater than 32, then everything went well. If you don’t want your users to see the DOS screen while the formatting takes place, create a PIF file called DOSWIN.PIF and set Display Usage set to Windowed.
|