[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Replace string character with vbcrlf and print to file

Posted on 2003-11-03
6
Medium Priority
?
1,243 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 750 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

830 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