Solved

Replace string character with vbcrlf and print to file

Posted on 2003-11-03
6
1,233 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
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
Comment Utility
hi
try to use chr(13) in place of vbcrlf
0
 
LVL 4

Expert Comment

by:JNSTAUB
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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 …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now