String manipulation in VBA 
Author Message
 String manipulation in VBA

Hi,

I am writing a function in VBA and I'm interested in writing a string
composed of a couple of words separated by a 'tab' key.
In pure Visual Basic I wrote the following:

dim str as String
str = "aaa" + Chr(9) + "bbb"

However, in VBA the function 'Chr()' is not recognized.
Do you know any other way I can use to mark the tab key? (I tried \t, it
didn't work) Or maybe how can I make my VBA environment familiar with this
function?

I will appreciate any hint you can give,
Thanks in advance,

Shoshi.



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
str = "aaa" & vbTab & "bbb" & vbCR & "a new line of text here"

--
/Anna Bohman
----------------------------------------------------------------------------
Bra Utbildning AB, Sundsvall, Sweden

----------------------------------------------------------------------------
Shoshi Gutreich skrev i meddelandet

Quote:
>Hi,

>I am writing a function in VBA and I'm interested in writing a string
>composed of a couple of words separated by a 'tab' key.
>In pure visual basic I wrote the following:

>dim str as String
>str = "aaa" + Chr(9) + "bbb"

>However, in VBA the function 'Chr()' is not recognized.
>Do you know any other way I can use to mark the tab key? (I tried \t, it
>didn't work) Or maybe how can I make my VBA environment familiar with this
>function?

>I will appreciate any hint you can give,
>Thanks in advance,

>Shoshi.



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Hi Soshi

What gives you the idea that VBA doesn't support Chr()?!?! It does for the
rest of us...

Regards

Dave


| Hi,
|
| I am writing a function in VBA and I'm interested in writing a string
| composed of a couple of words separated by a 'tab' key.
| In pure visual basic I wrote the following:
|
| dim str as String
| str = "aaa" + Chr(9) + "bbb"
|
| However, in VBA the function 'Chr()' is not recognized.
| Do you know any other way I can use to mark the tab key? (I tried \t, it
| didn't work) Or maybe how can I make my VBA environment familiar with this
| function?
|
| I will appreciate any hint you can give,
| Thanks in advance,
|
| Shoshi.
|
|
|



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Having said that, I prefer using the built-in constants - see Anna's
posting - it gives you more readable code ...

Dave


| Hi Soshi
|
| What gives you the idea that VBA doesn't support Chr()?!?! It does for the
| rest of us...
|
| Regards
|
| Dave



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Dave,
Just curious. Is there a difference between chr() and chr$()?
VBA accepts both but only documents chr().


Quote:
> Having said that, I prefer using the built-in constants - see Anna's
> posting - it gives you more readable code ...

> Dave



> | Hi Soshi
> |
> | What gives you the idea that VBA doesn't support Chr()?!?! It does for
the
> | rest of us...
> |
> | Regards
> |
> | Dave



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Dave,
Just curious. Is there a difference between chr() and chr$()?
VBA accepts both but only documents chr().


Quote:
> Having said that, I prefer using the built-in constants - see Anna's
> posting - it gives you more readable code ...

> Dave



> | Hi Soshi
> |
> | What gives you the idea that VBA doesn't support Chr()?!?! It does for
the
> | rest of us...
> |
> | Regards
> |
> | Dave



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Hi Shoshi,

If Chr() isn't working for you, then you almost certainly have a reference
not set correctly.

In the VBA editor, go to Tools, References, and let us know which references
have a checkmark against them.

It will also help if you let us know which version of Office you are using
(97 or 2000), and which application you are writing the macro for (you have
posted your message to groups concerned with VB, Outlook and Word)

Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:
>Hi,

>I am writing a function in VBA and I'm interested in writing a string
>composed of a couple of words separated by a 'tab' key.
>In pure visual basic I wrote the following:

>dim str as String
>str = "aaa" + Chr(9) + "bbb"

>However, in VBA the function 'Chr()' is not recognized.
>Do you know any other way I can use to mark the tab key? (I tried \t, it
>didn't work) Or maybe how can I make my VBA environment familiar with this
>function?

>I will appreciate any hint you can give,
>Thanks in advance,

>Shoshi.



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
chr$ is an explicit string function as opposed to a variant of type string
so should be faster in theory.  In practice I suspect you fuind it hard to
demonstrate any difference in speed even with a millisecond timer... but I
tend to use the $ version for reasons of "best practice".  Same with Left$,
Trim$ etc.

Regards

Dave


| Dave,
| Just curious. Is there a difference between chr() and chr$()?
| VBA accepts both but only documents chr().
|


| > Having said that, I prefer using the built-in constants - see Anna's
| > posting - it gives you more readable code ...
| >
| > Dave
| >


| > | Hi Soshi
| > |
| > | What gives you the idea that VBA doesn't support Chr()?!?! It does for
| the
| > | rest of us...
| > |
| > | Regards
| > |
| > | Dave
| >
| >
|
|



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Hi Stephen,

Chr returns a variant of type string. Chr$ returns a string. If you are
putting the result into a string variable, I'd recommend you use Chr$, as
you avoid the unnecessary conversion from string to variant & back again.

To see more on this, look up the topic "Returning Strings from Functions" in
the Word VBA Help. You'll find a complete list of the functions you can use
with the $ suffix.

Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email

Quote:

>Dave,
>Just curious. Is there a difference between chr() and chr$()?
>VBA accepts both but only documents chr().



>> Having said that, I prefer using the built-in constants - see Anna's
>> posting - it gives you more readable code ...

>> Dave



>> | Hi Soshi
>> |
>> | What gives you the idea that VBA doesn't support Chr()?!?! It does for
>the
>> | rest of us...
>> |
>> | Regards
>> |
>> | Dave



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Dave and Jonathan,
Thanks for the advice. I will read up on this.

BTW. Sorry  I posted twice, but I went offline during Send , and when I wen
back online, it got sent again.


Quote:
> Hi Stephen,

> Chr returns a variant of type string. Chr$ returns a string. If you are
> putting the result into a string variable, I'd recommend you use Chr$, as
> you avoid the unnecessary conversion from string to variant & back again.

> To see more on this, look up the topic "Returning Strings from Functions"
in
> the Word VBA Help. You'll find a complete list of the functions you can
use
> with the $ suffix.

> Regards
> Jonathan West - Word MVP
> MultiLinker - Automated generation of hyperlinks in Word
> Conversion to PDF & HTML
> http://www.multilinker.com
> Word FAQs at http://www.multilinker.com/wordfaq
> Please post any follow-up in the newsgroup. I do not reply to Word
questions
> by email


> >Dave,
> >Just curious. Is there a difference between chr() and chr$()?
> >VBA accepts both but only documents chr().



> >> Having said that, I prefer using the built-in constants - see Anna's
> >> posting - it gives you more readable code ...

> >> Dave



> >> | Hi Soshi
> >> |
> >> | What gives you the idea that VBA doesn't support Chr()?!?! It does
for
> >the
> >> | rest of us...
> >> |
> >> | Regards
> >> |
> >> | Dave



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Jonathan

Could you pls inform us which ref should be selected. One customer had
problems with Chr(13) and for the sake of it we just replaced it without
further investigations.

--
/Anna Bohman
----------------------------------------------------------------------------
Bra Utbildning AB, Sundsvall, Sweden

----------------------------------------------------------------------------

Quote:
>Hi Shoshi,

>If Chr() isn't working for you, then you almost certainly have a reference
>not set correctly.

>In the VBA editor, go to Tools, References, and let us know which
references
>have a checkmark against them.

>It will also help if you let us know which version of Office you are using
>(97 or 2000), and which application you are writing the macro for (you have
>posted your message to groups concerned with VB, Outlook and Word)

>Regards
>Jonathan West - Word MVP
>MultiLinker - Automated generation of hyperlinks in Word
>Conversion to PDF & HTML
>http://www.multilinker.com
>Word FAQs at http://www.multilinker.com/wordfaq
>Please post any follow-up in the newsgroup. I do not reply to Word
questions
>by email



>>Hi,

>>I am writing a function in VBA and I'm interested in writing a string
>>composed of a couple of words separated by a 'tab' key.
>>In pure visual basic I wrote the following:

>>dim str as String
>>str = "aaa" + Chr(9) + "bbb"

>>However, in VBA the function 'Chr()' is not recognized.
>>Do you know any other way I can use to mark the tab key? (I tried \t, it
>>didn't work) Or maybe how can I make my VBA environment familiar with this
>>function?

>>I will appreciate any hint you can give,
>>Thanks in advance,

>>Shoshi.



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Hi Anna,

The basic set for Word 97 is as follows

Visual Basic for Applications
Microsoft Word 8.0 Object Library (C:\Program Files\Microsoft
Office\Office\MSWORD8.OLB)
OLE Automation (C:\WINDOWS\SYSTEM\STDOLE2.TLB)
Microsoft Forms 2.0 Object Library (C:\WINDOWS\SYSTEM\FM20.DLL
Microsoft Office 8.0 Object Library (C:\Program Files\Microsoft
Office\Office\MSO97.DLL)

I don't have Word 2000 loaded just at the moment, the list will be a bit
different, using the Office 9.0 and Word 9.0 object libraries, & possibly
some others. maybe somebody else can post a complete listing for Word 2K

Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email

Quote:

>Jonathan

>Could you pls inform us which ref should be selected. One customer had
>problems with Chr(13) and for the sake of it we just replaced it without
>further investigations.

>--
>/Anna Bohman
>---------------------------------------------------------------------------
-
>Bra Utbildning AB, Sundsvall, Sweden

>---------------------------------------------------------------------------
-

>>Hi Shoshi,

>>If Chr() isn't working for you, then you almost certainly have a reference
>>not set correctly.

>>In the VBA editor, go to Tools, References, and let us know which
>references
>>have a checkmark against them.

>>It will also help if you let us know which version of Office you are using
>>(97 or 2000), and which application you are writing the macro for (you
have
>>posted your message to groups concerned with VB, Outlook and Word)

>>Regards
>>Jonathan West - Word MVP
>>MultiLinker - Automated generation of hyperlinks in Word
>>Conversion to PDF & HTML
>>http://www.multilinker.com
>>Word FAQs at http://www.multilinker.com/wordfaq
>>Please post any follow-up in the newsgroup. I do not reply to Word
>questions
>>by email



>>>Hi,

>>>I am writing a function in VBA and I'm interested in writing a string
>>>composed of a couple of words separated by a 'tab' key.
>>>In pure visual basic I wrote the following:

>>>dim str as String
>>>str = "aaa" + Chr(9) + "bbb"

>>>However, in VBA the function 'Chr()' is not recognized.
>>>Do you know any other way I can use to mark the tab key? (I tried \t, it
>>>didn't work) Or maybe how can I make my VBA environment familiar with
this
>>>function?

>>>I will appreciate any hint you can give,
>>>Thanks in advance,

>>>Shoshi.



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Jonathan

Thanks. Those are the common ones. The problem is long gone but the error
occurred at every Errorhandler containing a MsgBox with Chr(13) in the text,
there was a problem at the customers office,  NT4, Word97. Replacing it with
vbCr made the difference. Doesn't make sense to me.

--
/Anna Bohman
----------------------------------------------------------------------------
Bra Utbildning AB, Sundsvall, Sweden

----------------------------------------------------------------------------


Quote:
>Hi Anna,

>The basic set for Word 97 is as follows

>Visual Basic for Applications
>Microsoft Word 8.0 Object Library (C:\Program Files\Microsoft
>Office\Office\MSWORD8.OLB)
>OLE Automation (C:\WINDOWS\SYSTEM\STDOLE2.TLB)
>Microsoft Forms 2.0 Object Library (C:\WINDOWS\SYSTEM\FM20.DLL
>Microsoft Office 8.0 Object Library (C:\Program Files\Microsoft
>Office\Office\MSO97.DLL)

>I don't have Word 2000 loaded just at the moment, the list will be a bit
>different, using the Office 9.0 and Word 9.0 object libraries, & possibly
>some others. maybe somebody else can post a complete listing for Word 2K

>Regards
>Jonathan West - Word MVP
>MultiLinker - Automated generation of hyperlinks in Word
>Conversion to PDF & HTML
>http://www.multilinker.com
>Word FAQs at http://www.multilinker.com/wordfaq
>Please post any follow-up in the newsgroup. I do not reply to Word
questions
>by email


>>Jonathan

>>Could you pls inform us which ref should be selected. One customer had
>>problems with Chr(13) and for the sake of it we just replaced it without
>>further investigations.

>>--
>>/Anna Bohman
>>--------------------------------------------------------------------------
-
>-
>>Bra Utbildning AB, Sundsvall, Sweden

>>--------------------------------------------------------------------------
-
>-

>>>Hi Shoshi,

>>>If Chr() isn't working for you, then you almost certainly have a
reference
>>>not set correctly.

>>>In the VBA editor, go to Tools, References, and let us know which
>>references
>>>have a checkmark against them.

>>>It will also help if you let us know which version of Office you are
using
>>>(97 or 2000), and which application you are writing the macro for (you
>have
>>>posted your message to groups concerned with VB, Outlook and Word)

>>>Regards
>>>Jonathan West - Word MVP
>>>MultiLinker - Automated generation of hyperlinks in Word
>>>Conversion to PDF & HTML
>>>http://www.multilinker.com
>>>Word FAQs at http://www.multilinker.com/wordfaq
>>>Please post any follow-up in the newsgroup. I do not reply to Word
>>questions
>>>by email



>>>>Hi,

>>>>I am writing a function in VBA and I'm interested in writing a string
>>>>composed of a couple of words separated by a 'tab' key.
>>>>In pure visual basic I wrote the following:

>>>>dim str as String
>>>>str = "aaa" + Chr(9) + "bbb"

>>>>However, in VBA the function 'Chr()' is not recognized.
>>>>Do you know any other way I can use to mark the tab key? (I tried \t, it
>>>>didn't work) Or maybe how can I make my VBA environment familiar with
>this
>>>>function?

>>>>I will appreciate any hint you can give,
>>>>Thanks in advance,

>>>>Shoshi.



Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Anna,

I didn't really investigate why, but I had similar problems with some vba
functions and used the library qualifier, hence, VBA.Chr instead of plain
Chr.

FWIW,

Greg Longtin

Quote:
> Jonathan

> Thanks. Those are the common ones. The problem is long gone but the error
> occurred at every Errorhandler containing a MsgBox with Chr(13) in the
text,
> there was a problem at the customers office,  NT4, Word97. Replacing it
with
> vbCr made the difference. Doesn't make sense to me.

> --
> /Anna Bohman
> --------------------------------------------------------------------------
--
> Bra Utbildning AB, Sundsvall, Sweden

> --------------------------------------------------------------------------

--


Sun, 07 Jul 2002 03:00:00 GMT  
 String manipulation in VBA
Hi Greg,
The one time I heard of this happening was when using a beta version of a
third-party VB control, and control had a Left property. Setting the
compiler options wrong when compiling the control meant that the Left
property interfered with the Left() function of VBA. Using the VBA qualifier
was the workaround until a fix was made (fortunately very quickly)

Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email

Quote:

>Anna,

>I didn't really investigate why, but I had similar problems with some vba
>functions and used the library qualifier, hence, VBA.Chr instead of plain
>Chr.

>FWIW,

>Greg Longtin


>> Jonathan

>> Thanks. Those are the common ones. The problem is long gone but the error
>> occurred at every Errorhandler containing a MsgBox with Chr(13) in the
>text,
>> there was a problem at the customers office,  NT4, Word97. Replacing it
>with
>> vbCr made the difference. Doesn't make sense to me.

>> --
>> /Anna Bohman
>> -------------------------------------------------------------------------
-
>--
>> Bra Utbildning AB, Sundsvall, Sweden

>> -------------------------------------------------------------------------
-
>--



Tue, 09 Jul 2002 03:00:00 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. VBA String Manipulation DLL Missing

2. string manipulation, string routines, etc.

3. String manipulation

4. String Manipulation

5. String/Text Manipulations

6. String Manipulation

7. String manipulation with vbscript

8. String manipulation topic

9. String manipulation...

10. Text String Manipulation

11. Newbie question : string manipulation with VBscript.

12. String manipulation

 

 
Powered by phpBB® Forum Software