?
Solved

Deleting everything after a space in a string

Posted on 2003-02-26
2
Medium Priority
?
162 Views
Last Modified: 2010-04-07
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
Comment
Question by:wpelle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 8024406
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
 
LVL 5

Accepted Solution

by:
Julian_K earned 200 total points
ID: 8024430
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question