Solved

Replace string character with vbcrlf and print to file

Posted on 2003-11-03
6
1,235 Views
Last Modified: 2013-12-25
I'm trying to pass my vb app a comma delineated string via the command line such as:

1.jpg,2.jpg,3.jpg

I want my vb app to replace every comma with vbcrlf and print it to a text file so that when viewed it looks like this:

1.jpg
2.jpg
3.jpg

I've tried using the Replace command but it doesn't seem to be working.
0
Comment
Question by:Strobelight
6 Comments
 
LVL 9

Accepted Solution

by:
dancebert earned 250 total points
ID: 9672953
works for me.  Perhaps replace is doing exactly what it's supposed to do and your error is in creating the print file.

Private Sub Form_Load()
    Dim s As String
    s = "1.jpg,2.jpg,3.jpg"
    Dim s2 as string
    s2 = Replace(s, ",", vbCrLf)
    MsgBox s2
End Sub
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9673050
you can also use the Split Function to split the original command string into its components:

Private Sub Form_Load()
    Dim s As String
    Dim Parms() as Variant
    s = Command$
    Parms = Split(s,",")
    Dim iString as Integer
    if UBound(Parms) > 0 then
       for iString = 1 to UBound(Parms)
          MsgBox Parms(iString)
       Next
    end if
End Sub

AW
0
 
LVL 1

Expert Comment

by:ib_setiawan
ID: 9673179
Public Sub WriteLineToFile()
       Dim myStr As String = "1.jpg,2.jpg,3.jpg"
        Dim myLineStr As String = Replace(myStr, ",", ControlChars.CrLf)
        Dim sb As New System.IO.FileStream("c:\MyFileStr.txt", _
               System.IO.FileMode.OpenOrCreate)
        Dim sw As New System.IO.StreamWriter(sb)
        sw.Write(myLineStr)
        sw.Close()
End Sub
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 5

Expert Comment

by:fantasy1001
ID: 9676488
Should be like this:
Private Sub Command1_Click()
    Dim str As String
    str = Command
    str = Replace(str, ",", vbCrLf)
    Open "c:\output.txt" For Output As #1
        Print #1, str
    Close #1
End Sub

~ fantasy ~
0
 
LVL 1

Expert Comment

by:rashmitodkar
ID: 9676623
hi
try to use chr(13) in place of vbcrlf
0
 
LVL 4

Expert Comment

by:JNSTAUB
ID: 9677430
i remenber that arguments are comma separate so you have to do

for i=0 to argcount-1
print arg(i)
next
i don't remenber the true typo  to retrieve command ligne argument (see app)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now