Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert floppy disk

Status
Not open for further replies.

TipGiver

Programmer
Sep 1, 2005
1,863
Hello.

dim sr as streamReader = nothing
try
sr= new streamReader(a:\bla.txt)
catch ex as exception

end try


I want to catch and display my error message, if the disk is Not inserted, .. and not show the standard "No disk" error.
Is it possible ?

Tnx
 
I've found that something like this has worked in the past:

Code:
		Dim sr As streamReader = Nothing
		Try
			sr = New StreamReader("a:\bla.txt")
		Catch ex As Exception
			Select Case System.Runtime.InteropServices.Marshal.GetLastWin32Error
				Case 2
					MessageBox.Show(ex.Message + ": File not found")
				Case 21
					MessageBox.Show(ex.Message + ": There does not appear to be a disk in the drive")
				Case Else
					MessageBox.Show(ex.Message)
			End Select
		End Try

Also have a look here for a useful list of DOS error codes



Hope this helps.

[vampire][bat]
 
Hi,

i want not to show the default windows messagebox (Title: Windows - No Disk , Message: There is no disk in the drive. Please inserrt a disk into drive , Buttons: Cance, Try again and Continue).

After pressing Continue, the "Case 21" is executed. Can i Not show the windows msgbox ?
 
When I tested this, before posting, it showed ONLY my messagebox - not the Windows default. So I don't know what else to suggest.

I created a new application, put a button on Form1 and typed the code above into the click handler, and it worked as expected (both inside the IDE and by running the .exe after compilation)


Hope this helps.

[vampire][bat]
 
Er.. can i disable by code the win32 messages?
 
I have no idea, but as I said earlier, the code I posted is exactly what I used (copy/paste) and I don't get the messages. Project properties are basic defaults (except Options Explicit and Strict are both ON and Compare is Binary).

[vampire][bat]
 
Hi,

I finally have found something that is currently working.
In case that someone could have the same problem:

Code:
        Dim fso As New Scripting.FileSystemObject()
        Dim drv As Scripting.Drive
        Dim string_builder As New System.Text.StringBuilder()

        For Each drv In fso.Drives
            string_builder.Append( _
                drv.DriveLetter & ":" & vbCrLf & _
                "  Type:            " & drv.DriveType.ToString() & vbCrLf)
            [b]If drv.IsReady Then[/b]
                string_builder.Append( _
                    "  File System:     " & drv.FileSystem & vbCrLf & _
                    "  Free Space:      " & drv.FreeSpace & vbCrLf & _
                    "  Total Size:      " & drv.TotalSize & vbCrLf & _
                    "  Volume Name:     " & drv.VolumeName & vbCrLf & _
                    "  Serial Number:   " & drv.SerialNumber & vbCrLf & _
                    "--------------------" & vbCrLf)
            Else
                string_builder.Append( _
                    "  Not ready" & vbCrLf & _
                    "--------------------" & vbCrLf)
            End If
        Next drv

        txtDrives.Text = string_builder.ToString()
        txtDrives.Select(0, 0)

This is a general example. Note the bold line, which is what i needed.

Merry Christmas.
 
Virtually everything you have above is available through managed classes - ie no need to use the FSO:

Code:
		With RichTextBox1
			.Clear()
			.AcceptsTab = True
			.AppendText("Drives:" + newline)
			For Each di As DriveInfo In DriveInfo.GetDrives
				Dim s As String = di.Name
				If s.EndsWith("\") Then s = s.Remove(s.Length - 1, 1)
				.AppendText(tab + s + newline)
				s = Nothing
				.AppendText(tab2 + "Drive Ready: " + di.IsReady.ToString + newline)
				.AppendText(tab2 + "Drive Type: " + di.DriveType.ToString + newline)
				If di.IsReady Then
					.AppendText(tab3 + "Drive Format: " + di.DriveFormat + newline)
					.AppendText(tab3 + "Available Free Space: " + di.AvailableFreeSpace.ToString("#,###") + newline)
					.AppendText(tab3 + "Total Free Space: " + di.TotalFreeSpace.ToString("#,###") + newline)
					.AppendText(tab3 + "Total Size: " + di.TotalSize.ToString("#,###") + newline)
					.AppendText(tab3 + "Volume Label: " + di.VolumeLabel.ToString + newline)
				End If
			Next
		End With

Some variables used to save typing:

[tt]
Private tab As String = Chr(9)
Private tab2 As String = tab + tab
Private tab3 As String = tab2 + tab
Private newline As String = Environment.NewLine
[/tt]

Hope this helps.

[vampire][bat]
 
Hi earthand fire.

Yes, i do prefere your way, but the DriveInfo class exists in .NET 2.0 :(
Wouldn't it be better if there was created a new forum for the .NET framework 2.0 ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top