VB 6.0 String question

With the help of some experts I figured out how to launch an email programme with subject line and body message.

The body message can be set as a string for example

Dm bodymessage as String

Now my problem:
I would like to write a message over several lines in the body section of the Email with predefined Line changes.

for example:
Dear sirs    [linechange]
text text....   [linechange]

Regards       [linechange]

How do I invoke the Linechange or Carriage return in a string variable?
themrocAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
You just need to add something like this:

bodymessage = "Dear Sirs" & vbCR & "text text" & vbCR & "Regards" & vbCR

Or use the Linefeed character vbLF or the combination code vbCRLf

Just try it out with one or more of these and determine which gives you the best results.
0
daffyduck14milCommented:
Hi,

First off, it's not worth the points you are willing to give.

Second, the answer to your question is the string concatenation operator (&) and the constant vbLf or vbCrLf.

Thus, it makes.
Dim BodyMessage as string

BodyMessage = "Dear sirs," & vbCrLf
BodyMessage = BodyMessage & "Text...text..." & vbCrLf
BodyMessage = BodyMessage & "Regards," & vbCrLf

The vbLf means a LineFeed, vbCr means Carriage Return, and vbCrLf means a LineFeed and a Carriage return.

Grtz.©

D.

P.s. 1 or 2 points will do nicely.. not 100 ;p
0
sazhagianambiCommented:
Hi friend,

I Think U want to add LineChar after Some Number of Characters.

Assume Every Line Having 50 Char, Use Following,

Dim Temp as string
For i=50 to Len(BodyMessage) step 50
   Temp=Temp+ Mid(Str, i, 2)+ vbcrlf
Next
BodyMessage=Temp


I Hope this will be Useful

Nambi

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

dmangCommented:
I think that with the last code offered (Nambi) that you have the potential for having words unnaturally split from one line to the next in the text body.
Try the function below with a block of text as messagein and your linelength specified as parameters.
The result is a text block with lines ending with full words

Function BuildMessage(MessageIn As String, _
                      iLineLength As Integer) As String

    Dim l As Integer
    Dim iPos As Integer
    Dim iStart As Integer
    Dim MessageOut As String
    Dim WorkingLine As String
   
    l = Len(MessageIn)
    iStart = 1
    While iStart + iLineLength < Len(MessageIn)
       
        If Mid$(MessageIn, iStart + iLineLength - 1, 1) = " " Or _
            Mid$(MessageIn, iStart + iLineLength, 1) = " " Then
                WorkingLine = Trim(Mid$(MessageIn, iStart, iLineLength))
                MessageOut = MessageOut & WorkingLine & vbCrLf
                iStart = iStart + Len(WorkingLine) + 1
        Else
            WorkingLine = Mid$(MessageIn, iStart, iLineLength)
            For i = iLineLength To 1 Step -1
                If Mid$(WorkingLine, i, 1) = " " Then
                    WorkingLine = Left(WorkingLine, i - 1)
                    MessageOut = MessageOut & WorkingLine & vbCrLf
                    iStart = iStart + Len(WorkingLine) + 1
                    Exit For
                End If
            Next i
        End If
       
        If (l - iStart) < iLineLength Then
           iLineLength = l - iStart
        End If
    Wend
    MessageOut = MessageOut & Mid$(MessageIn, iStart, iLineLength + 2)
    BuildMessage = MessageOut
 
End Function

 
0
sazhagianambiCommented:
Hi Dmang ,


There is a some indifinite loop in While Loop. Also thi code Works Lovely until the Empty Space Reaches. After that it split every Char as a Text. Kindly check it This.I can able to Make correct that indifinte Loop, But Not on later Part.


Regards,
Nambi
0
sazhagianambiCommented:
Hi Friend,

I Hope this Sholu Give Output as u Expect. I Did som Minor changes in DMang's Code(I Hope he doesn't mind it).


Function BuildMessage(MessageIn As String, _
                     iLineLength As Integer) As String

   Dim l As Integer
   Dim iPos As Integer
   Dim iStart As Integer
   Dim MessageOut As String
   Dim WorkingLine As String
   
   l = Len(MessageIn)
   iStart = 1
   While iStart + iLineLength <= Len(MessageIn)
        'MsgBox Mid$(MessageIn, iStart + iLineLength - 1, 1)
       If Mid$(MessageIn, iStart + iLineLength - 1, 1) = " " Or _
           Mid$(MessageIn, iStart + iLineLength, 1) = " " Then
               WorkingLine = Trim(Mid$(MessageIn, iStart, iLineLength))
               MessageOut = MessageOut & WorkingLine & vbCrLf
               iStart = iStart + Len(WorkingLine) + 1
       Else
           WorkingLine = Mid$(MessageIn, iStart, iLineLength)
           Dim i
           For i = iLineLength To 1 Step -1
               If Mid$(WorkingLine, i, 1) = " " Then
                   WorkingLine = Left(WorkingLine, i - 1)
                   MessageOut = MessageOut & WorkingLine & vbCrLf
                   iStart = iStart + Len(WorkingLine)
                   Exit For
               End If
           Next i
           iStart = iStart + iLineLength
           MessageOut = MessageOut & WorkingLine & vbCrLf
           'MsgBox MessageOut
       End If
       If (l - iStart) <= iLineLength Then
          iLineLength = l - iStart
          If iStart = l Then
            iStart = iStart + 1
          End If
       End If
   Wend
   MessageOut = MessageOut & Mid$(MessageIn, iStart - 1, iLineLength + 2)
   BuildMessage = MessageOut

'Consider "Nambi How Are U?" as Input String
' 2 is the Count to Make Line break
'Output is
' Na
' Mb
' i
' Ho
' W
' Ar
' e
' U?

regards,
Nambi
0
themrocAuthor Commented:
Apparently it is not so easy as expected, at least I did not get an working answer!

From TimCottee I got the code how to launch an Email programme from a VB application, Question:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20516835.html

It all works fine, the solution was to create the following subroutine:
__________________
Public Sub MailMessage(ByVal MailTo As String, ByVal Subject As String, ByVal Body As String)
   ShellExecute Me.hwnd, vbNullString, "mailto:" & MailTo & "?Subject=" & Subject & "&Body=" & Body, vbNullString, "C:\", SW_SHOWNORMAL
End Sub
_______________

Where body is the textstring I would like to manipulate
Even if I use the vbCR or vbCRlf command nothing happend  the text is still in one line of my email body
e.g for duffyduck14 it reads:
Dear sirs,Text...text...Regards,

What is wrong, I think the answer is worth more than 1 or two pints, therefore I increase it to 120
0
themrocAuthor Commented:
I stuck a little bit, what is the recomendation of the experts. Should I place the question again with a different header or is it worth to wait longer for an answer

????????????????????????
0
daffyduck14milCommented:
Um,

If your purpose is to send an e-mail message using the default mailsystem, and format the text you want to put into it...

I would not use a shellexecute method. Might work for little things, but when you get to a more complex sytem, it's not so usefull anymore. I would use CDO, or MAPI. Mapi is standard, and most (read "commercial") e-mail packages respond to it.

If my memory serves, Mailto: will launch the default MAPI enabled mail-system.

Grtz.&copy;

D.
0
themrocAuthor Commented:
gritz & copy,

does it mean it would not work in every envirnonment?
for example if it runs on an network?

So how do I launch mailto
do I have to implement the MAPI controll into my application.

The problem I have the programme I wrote might in some cases run on an network would this be effected by the shellexecute methode???

P.S. I solved the above mentoned problem by doing a not very elegant procedure.
I add always about 300 blanks to the line where I want the linebreak, then in the email it comes up with a linebreak!
0
daffyduck14milCommented:
>does it mean it would not work in every envirnonment?
Correct. There must be a working e-mail system in place for MAPI to work. This is a requirement for both client and server.

Thus, if your program can be started on a server (or network, I don't exactly understand what you mean by that word), it must have a MAPI enabled mail-system. But, this is a requirement you can check and enforce. Even with the ShellExecute solution, you still have the same requirement. And yes, starting the program on the network might yield problems with ShellExecute.

Using MAPI is fairly simple, it has a component in VB, after you add it to the toolbox, add a Mapi Session, and a Mapi Message. Then, a command box, and use:

Private Sub cmdMail_click()
  MAPISession1.SignOn
  MAPIMessages1.SessionID = MAPISession1.SessionID
  MAPIMessages1.Compose
  MAPIMessages1.RecipType = RecipTypeConstants.mapToList
  MAPIMessages1.RecipDisplayName = "someone@somewhere.com"
  MAPIMessages1.MsgSubject = "Test message"
  MAPIMessages1.MsgNoteText = "This is a test message using" & vbCrLf & "MAPI."
  MAPIMessages1.Send
  MAPISession1.SignOff
End Sub

The above code-snippet is the basis of sending an E-mail message through MAPI and VB.

Hope this helps you somewhat.

Grtz.&copy;

D.

P.s. The Grtz.&copy; ain't my name... ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
themrocAuthor Commented:
thanks duffyduck14,

that soves some of my problems I had before .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.