2008-09-30 71 views

回答

10

这并不似乎是为这件事了“开箱即用”的解决方案。

The Old Joel On Software Forums

不管怎么说采取..把这个话题休息.. 以下是我的VB6解决办法:我 在我的VB项目中定义2个符号 “MPDEBUG”和“MPRELEASE”和在我的应用程序入口点 函数中调用 以下函数作为第一个 操作。我发现,工作

Public Sub ChangeDirToApp() 
#If MPDEBUG = 0 And MPRELEASE = 1 Then 
    ' assume that in final release builds the current dir will be the location 
    ' of where the .exe was installed; paths are relative to the install dir 
    ChDrive App.path 
    ChDir App.path 
#Else 
    ' in all debug/IDE related builds, we need to switch to the "bin" dir 
    ChDrive App.path 
    ChDir App.path & BackSlash(App.path) & "..\bin" 
#End If 
End Sub 
2

Will this work?

'Declaration 
Private Declare Function SetCurrentDirectory Lib "kernel32" _ 
Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long 

'syntax to set current dir 
SetCurrentDirectory App.Path 
+1

但使用本机VB6命令`ChDrive App.Path:ChDir App.Path`更简单 – MarkJ 2011-12-15 16:11:15

6

解决方案使用Sub Main,并检查程序在IDE中运行。

Dim gISIDE as Boolean 

Sub Main() 
    If IsIDE Then 
     ChDrive App.Path 
     ChDir App.Path 
    End If 

    ' The rest of the code goes here... 

End Sub 

Public Function IsIDE() As Boolean ' 
     IsIDE = False 
     'This line is only executed if running in the IDE and then returns True 
     Debug.Assert CheckIDE 
     If gISIDE Then 
      IsIDE = True 
     End If 
End Function 

Private Function CheckIDE() As Boolean ' this is a helper function for Public Function IsIDE() 
     gISIDE = True 'set global flag 
     CheckIDE = True 
End Function 
6

“当前目录似乎是VB6的目录”只有当你打开使用文件 - 打开一个项目。

在IDE关闭时双击.vbp文件打开它。

1

可以在快捷方式的属性中更改任何程序的当前目录(包括vb6)。我已经将它更改为我的源代码树的根目录,它使得使用File-Open更快。

相关问题