Solved

Replace string character with vbcrlf and print to file

Posted on 2003-11-03
6
1,239 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
[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
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
Technology Partners: 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!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

717 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