Question

VB 6.0 String question

Asked by: themroc

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?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-02-19 at 02:14:30ID20520195
Tags

carriage

,

linechange

,

return

,

string

Topic

Visual Basic Programming

Participating Experts
4
Points
120
Comments
12

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Invoking a function
    Some libs export functions starting with underscores like "_foo()". Can we invoke such functions in VB.
  2. How to quickly remove a carriage return from a VB string
    I am retreiving data stored on a oracle database using VB 6. The data is from tru-64 box, so has a carriage return embedded in string when it gets back from server. When it comes into VB, data in string cannot be searched effciently with chr(32) in it. The code processes m...
  3. remove carriage returns
    Hi, I need to produce a file from VB 6 with Windows 2000 for Unix. The file contains different lines all ending by a carriage return and a line feed (using the print method in VB). As the file is destinated to a Unix System, I need to remove the carriage returns. How can I d...
  4. Carriage return in a textbox
    Hi All, Is it possible to have a carriage return in a text box on a report or a form? I have varying length Names and contact numbers which I want to place in one textbox, rather than several, but I need a carriage return after each piece of information. Thanks in advance f...
  5. To Get the Name of the invoking application in VB 6
    Hi, I have 2 VB applications E1,E2. I invoke E2 from E1.is there a way to determine which application has invoked the current application. ie : i should know which application has invoked E2 since E2 can be invoked manually also. Waiting for ur help and reply.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: TimCotteePosted on 2003-02-19 at 02:18:25ID: 7980557

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.

 

by: daffyduck14milPosted on 2003-02-19 at 02:19:29ID: 7980562

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

 

by: sazhagianambiPosted on 2003-02-19 at 03:52:20ID: 7980855

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

 

by: dmangPosted on 2003-02-19 at 09:50:52ID: 7982699

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

 

 

by: sazhagianambiPosted on 2003-02-20 at 21:58:27ID: 7991837

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

 

by: sazhagianambiPosted on 2003-02-20 at 23:56:13ID: 7992174

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

 

by: themrocPosted on 2003-02-21 at 02:51:05ID: 7992514

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

 

by: themrocPosted on 2003-02-24 at 04:05:26ID: 8007818

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

????????????????????????

 

by: daffyduck14milPosted on 2003-03-04 at 23:55:14ID: 8070136

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.

 

by: themrocPosted on 2003-03-05 at 02:56:18ID: 8070761

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!

 

by: daffyduck14milPosted on 2003-03-05 at 04:27:34ID: 8071145

>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... ;-)

 

by: themrocPosted on 2003-03-05 at 05:56:55ID: 8071663

thanks duffyduck14,

that soves some of my problems I had before .

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...