Search code examples
powerbuilder

Write this Visual Basic code in Powerbuilder


How to write the following VB code in PB?

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

Solution

  • Try this :

    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)