String with quotes and more...

S

Sasa

I have two probles I cannot figure out.
1) How can I assign some string with quotes ("") to string
variable?
For example: How can I assign: "hello" including quotes?

2) Im also trying to assign number string to my predefined
integer variable.
For example: If I have somewhere in document sentence:
This number is 11. How can I assign this "11" number to
integer variable?

Can someone help?
Regards.

Sasa
 
H

Helmut Weber

Hi Sasa,
Dim myStr As String
Dim MyInt As Integer
myStr = Chr$(34) & "Hello" & Chr$(34)
MsgBox myStr
---
myStr = "11"
MyInt = CInt(myStr)
MsgBox MyInt * 2

I've recently read, that using integer is,
rather theoretically, slower on 32-bit machines,
than Type "long". Quite understandable, I think.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, NT 4.0
 
S

Sasa

That is quite interesting. Ill remember that.
Thanks for your help with my problem, my German neighbor.
Sasa
Greetings from Prague, Czech republic.
 
M

Martin Seelhofer

Hi there
1) How can I assign some string with quotes ("") to string
variable? For example: How can I assign: "hello" including
quotes?

To specify a (single) quote inside a string, you have to write
it as two quotes like this: If the result has to be ...

this is "the" result

.... then the string has to be ...

"this is ""the"" result".

VBA needs double quotes to find out whether the string starts,
ends or needs a single quote. This technique is know as "Byte-
Stuffing".
2) Im also trying to assign number string to my predefined
integer variable. For example: If I have somewhere in document
sentence: This number is 11. How can I assign this "11" number
to integer variable?

If I understand you right, you want to extract "11" out of a
string like "This number is 11". In this case, you may have to
give us more information, e.g.:

- is your number always standing at the end of the string
- can your string have more than just one number, e.g. "This 1 is 2"

In the general case, where there can be several numbers anywhere
in the string, you'll have to write a little function parsing the string
yourself. One approach might be to work through all the words
(look for spaces) and test those words for being numeric (using
the IsNumeric()-function of VBA). Then you might want to save
those numbers in an array or collection...


Cheers,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top