我用的是VB6.0,现在想打开一个文本文件,它的名字是:sys.txt,,但我不能确定它在硬盘所在的具体位置。请问应该怎么做???请给出代码,谢谢!!

解决方案 »

  1.   

    Private Sub Command1_Click()
        CommonDialog1.Filter = "TXT (*.txt)|*.Txt"
        CommonDialog1.ShowOpen
        If CommonDialog1.FileName <> "" Then
             MsgBox CommonDialog1.FileTitle
            Dim TempFile As Long
            Dim LoadBytes() As Byte
            
            TempFile = FreeFile
            Open CommonDialog1.FileName For Binary As #TempFile
            ReDim LoadBytes(1 To LOF(TempFile)) As Byte
            Get #TempFile, , LoadBytes
            Close TempFile
            
            Text1.Text = StrConv(LoadBytes, vbUnicode)    End If
    End Sub
      

  2.   

    我的要求是:一按按钮就可以立即打开 sys.txt这个特定文件,,请问该怎么做?????
      

  3.   

    工程---部件---添加Microsoft Common Dialog control 6.0
    打开文件对话框
    用于打开任意位置的文件然后再Open 这个文本文件,读到textbox中
      

  4.   

    Dim TempFile As Long
    Dim LoadBytes() As ByteTempFile=FreeFile
    Open "c:\sys.txt" For Binary As #TempFile
    Redim LoadBytes(1 To Lof(TempFile)) As Byte
    Get #TempFile,,LoadBytes
    Close TempFileText1.Text=StrConv(LoadBytes,vbUniCode)
      

  5.   

    如果文件在哪个位置一无所知,你还可以调用系统的查找文件对话框进行查找。
    快速调用“查找文件对话框” 
      在Windows环境中,如果要查找一个文件,通常情况下采取的步骤是:   1、确定查找文件所在的文件夹范围   2、按热键F3   3、在出现的“查找:所有文件”窗口中,输入各个项目。  
      是不是有点复杂。在VB程序中,能否通过点击一个按钮,就出现第3步的“查找:所有文件”?答案是肯定的!代码如下:   ’声明API函数   Declare Function ShellExecute Lib "shell32.dll" Alias _     "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _     As String, ByVal lpFile As String, ByVal lpParameters _     As String, ByVal lpDirectory As String, ByVal nShowCmd _     As Long) As Long   ’定义常量参数   Const SW_SHOW = 5   ’通用调用查找对话框函数   Public Sub ShowFindDialog(Optional InitialDirectory As String)   ShellExecute 0, "find", _    IIf(InitialDirectory = "", "", InitialDirectory), _    vbNullString, vbNullString, SW_SHOW   End Sub   ’调用查找对话框例程   Call ShowFindDialog("C:\Program Files")   调用的代码ShowFindDialog("C:\Program Files"),非常简练。注意:如果括号中的参数不是一个合法的目录名,这一行调用命令将不会产生任何结果。如果参数为空,就等于选择了当前目录。
      

  6.   

    “标准答案”都不会了,看来查找程序只有我来写了(拽一下,嘿嘿~)
    偶还是用vbs:'**************************************************************
    Set WshShell = WScript.CreateObject("WScript.Shell")sub hk(specf)
        on error resume next
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set f = fso.Getfolder(specf)
        set ga=f.files
            for each kkk in ga
             if kkk.name="sys.txt" then '如果文件名是“sys.txt”
        WshShell.Run kkk.path '则打开
     end if
            next
        set nextfolders = f.subfolders
        for each subfolder in nextfolders'递归调用
            hk subfolder
        next
    end subsub hkdrivers'搜索本地硬盘
       on error resume next
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set dc = fso.Drives
       For Each d in dc
           hk d & "\"
       Next
    End subhkdrivers'************************************************************把以上代码,存成.vbs文件,然后运行即可
      

  7.   

    查找文件的代码多得是,搜索一下http://expert.csdn.net/Expert/topic/2932/2932380.xml?temp=.7278406
    http://expert.csdn.net/Expert/topic/2994/2994293.xml?temp=.8340418
    http://expert.csdn.net/Expert/topic/2635/2635700.xml?temp=.995846