Solved

Replace string character with vbcrlf and print to file

Posted on 2003-11-03
6
1,234 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

919 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