在 Powerbuilder 中编写此 Visual Basic 代码
Write this Visual Basic code in Powerbuilder
如何在PB中编写如下VB代码?
Dim fso As New Scripting.FileSystemObject()
For Each str As Scripting.Drive In fso.Drives
If str.IsReady Then
TextBox1.Text += "Volume Name : " & str.VolumeName
End If
Next
您需要为此类功能声明和使用 Windows API。可能是 GetLogicalDrives 或类似的。您可能希望查看 Topwiz Software 的 Roland Smith 的 Filesys 应用程序(www.topwizprogramming.com 在免费代码下)。此示例应用程序编码了许多系统信息/操作方法。
试试这个:
OLEObject ole_wsh
string ls_values, ls_message
ole_wsh = CREATE OLEObject
ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
ole_wsh.Language = "vbscript"
ole_wsh.AddCode('Function retDrives()~r~n' &
+ 'Set fso = CreateObject("Scripting.fileSystemObject")~r~n' &
+ 'drivesVolume = ""~r~n' &
+ 'For Each str In fso.Drives ~r~n' &
+ ' If str.IsReady Then ~r~n' &
+ ' drivesVolume = drivesVolume + "[" + str.VolumeName + "]" ~r~n' &
+ ' End If ~r~n' &
+ 'Next~r~n' &
+ 'retDrives=drivesVolume~r~n' &
+ 'End Function')
ls_values = ole_wsh.Eval("retDrives")
ole_wsh.DisconnectObject()
DESTROY ole_wsh
ls_message = "VOLUMES(s): " + ls_values
MessageBox("DRIVES",ls_message)
如何在PB中编写如下VB代码?
Dim fso As New Scripting.FileSystemObject()
For Each str As Scripting.Drive In fso.Drives
If str.IsReady Then
TextBox1.Text += "Volume Name : " & str.VolumeName
End If
Next
您需要为此类功能声明和使用 Windows API。可能是 GetLogicalDrives 或类似的。您可能希望查看 Topwiz Software 的 Roland Smith 的 Filesys 应用程序(www.topwizprogramming.com 在免费代码下)。此示例应用程序编码了许多系统信息/操作方法。
试试这个:
OLEObject ole_wsh
string ls_values, ls_message
ole_wsh = CREATE OLEObject
ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
ole_wsh.Language = "vbscript"
ole_wsh.AddCode('Function retDrives()~r~n' &
+ 'Set fso = CreateObject("Scripting.fileSystemObject")~r~n' &
+ 'drivesVolume = ""~r~n' &
+ 'For Each str In fso.Drives ~r~n' &
+ ' If str.IsReady Then ~r~n' &
+ ' drivesVolume = drivesVolume + "[" + str.VolumeName + "]" ~r~n' &
+ ' End If ~r~n' &
+ 'Next~r~n' &
+ 'retDrives=drivesVolume~r~n' &
+ 'End Function')
ls_values = ole_wsh.Eval("retDrives")
ole_wsh.DisconnectObject()
DESTROY ole_wsh
ls_message = "VOLUMES(s): " + ls_values
MessageBox("DRIVES",ls_message)