Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Deleting everything after a space in a string

Ok here's the problem.

I have loaded a filelist from a textfile into a listbox and then I use this code to parse the selections into a textbox and then using a shell command to use the filenames in an external program.

Private Sub Command2_Click()
 Dim sText As String
   Dim lListLoop As Long
   With List1
       
       For lListLoop = 0 To .ListCount - 1
           If .Selected(lListLoop) = True Then
               
               sText = sText & " " & .List(lListLoop)
               
           End If
           
       Next lListLoop
     
       Text1.Text = sText
       Shell "program.exe " Text1
    End With
End Sub

This works fine, but now when I added file sizes to the list I have a little problem.

The list looks like this.  

File01 1073739776
File02 1073739776
File03 1073739776
etc

The thing is, when parsing this to the Textbox the filesizes is added too, and that won't work when the shell command is executed since the program only accepts filenames and not sizes.

So I would like to use a command that deletes the filesizes when moving the list to a textbox.

Thanks in advance.

0
wpelle
Asked:
wpelle
1 Solution
 
deightonCommented:
Dim sText As String
  Dim lListLoop As Long
  With List1
     
      For lListLoop = 0 To .ListCount - 1
          If .Selected(lListLoop) = True Then
             
              sText = sText & " " & .List(lListLoop)
             
          End If
         
      Next lListLoop
      '**************************
      if instr(stext," ") > 0 then
         stext=left(stext,instr(stext," ")-1)
      end if

     
      Text1.Text = sText
      Shell "program.exe " Text1
   End With
End Sub
0
 
Julian_KCommented:
Hi, wpelle.

instead
  sText = sText & " " & .List(lListLoop)
use
  sText = sText & " " & left$(.List(lListLoop),instr(1,.list(lListLoop)," ")-1)

The expression left$(.List(lListLoop),instr(1,.list(lListLoop)," ")-1) will return the part to the left of the space.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now