当前位置: 代码迷 >> VB Dotnet >> VB.NET 判断光驱盘符,该怎么解决
  详细解决方案

VB.NET 判断光驱盘符,该怎么解决

热度:1113   发布时间:2016-04-25 02:25:48.0
VB.NET 判断光驱盘符


初学VB.NET
以上代码是今天从网上看到,想测试一下看不行。

问题:
1、If FsoDrive.DriveType = CDRom Then   显示未声明CDRom,想咨询一下怎么办?
2、Function不是需要Return返回值吗?此程序没有怎么返回?

针对以上问题
自己修改了一下,笔记本运行,笔记本带有光驱,但是结果还是显示“无CDRom”,代码如下:

Function GetCDROM()
     Dim Fanhui as string =""                   ’用于返回值
     Dim Fso As New Scripting.FileSystemObject  
     Dim FsoDrive As Scripting.Drive, FsoDrives As Scripting.Drives 
        FsoDrives = Fso.Drives
        For Each FsoDrive In FsoDrives              
            If FsoDrive.DriveType = 4 Then     ‘查询网上,4代表光驱      
                Fanhui = FsoDrive.DriveLetter           
            Else
                Fanhui = "无CDRom"
            End If
        Next
        Return Fanhui
        Fso = Nothing
        FsoDrive = Nothing
        FsoDrives = Nothing
    End Function

请各位大侠帮帮忙

------解决方案--------------------
先引用filesystem组件
.net下应该有更方便的方法
DriveInfo.DriveType 
------解决方案--------------------
请这样写:
Imports System.IO
Public Class RECDRom
    Public Function GetCDROM() As String
        Dim str1 As String = ""
        For Each hh In DriveInfo.GetDrives
            If hh.DriveType = IO.DriveType.CDRom Then
                str1 = hh.Name
                Exit For
            End If
        Next
        Return str1         '返回空时,没有光驱,否则返回光驱盘符。
    End Function
end class

------解决方案--------------------
网页你也只能获取服务器的.又不能获取本地的..写了也没什么用.
  相关解决方案