Solved

Number to String

Posted on 1998-07-02
8
163 Views
Last Modified: 2010-05-03
I need to convert an iniger variable to a string.  Iv'e tried this

Dim S As String
Dim X As Integer

S=X

This works sometimes but no others. When i use it repeatedly i get a type thireen error. I looked into the help files and found a ToText function under  "String Functions", however when i try to use it i get an error Sub or "Function not defined"

Sorry i only have five points but this question should be fairly simple.
0
Comment
Question by:hess
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:hess
ID: 1464838
hold up on the answers for a little whiile i think i've got it
0
 
LVL 1

Accepted Solution

by:
Staplehead earned 0 total points
ID: 1464839
Hess,

Assuming that the data in S is numeric, you could use:

dim S as String
dim X as Integer

S = "1234"
X = CInt (S)

There's a whole family of Cxxx functions for conversions...

        Larry
0
 

Expert Comment

by:wsanchez
ID: 1464840
You could also try using Str(number).  For example:

Dim ThisString

ThisString = Str(123)  'returns " 123"
ThisString = Str(-123) 'returns "-123"

When a number is converted to a string, a leading space is reserved for its sign. Hence the space in " 123" just before 1.  This does not only convert integers but also numbers with decimal points.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:wsanchez
ID: 1464841
You could also try using Str(number).  For example:

Dim ThisString

ThisString = Str(123)  'returns " 123"
ThisString = Str(-123) 'returns "-123"

When a number is converted to a string, a leading space is reserved for its sign. Hence the space in " 123" just before 1.  This does not only convert integers but also numbers with decimal points.
0
 

Author Comment

by:hess
ID: 1464842
I siad hold up on the answers i think i've gott it and i did. It's fixed. i did it myself.
All i had to do was put the integer into a temp string and then i added the temp stings together. I guess i have to give up my five points though still cause you answered it any ways. Mabey you were writing your answer before i posted my comment but anyways, thankyou.
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1464843
hess,

yup, i didn't see your "hold on"... nonetheless, when i came back, i noticed that i typed the answer backward; it should have been:

s = CStr(x)

your comment confused me, though: what do you mean by "added temp strings together"?  if you did:
   s = "" & x
or the "less correct"
   s = "" + x
then vb did a Cstr for you, anyway...
0
 

Author Comment

by:hess
ID: 1464844
dim x as integer, y as integer
dim temp as string
dim temp2 as string
dim temp3 as string
x=6
y=4
temp=x
temp2=y
temp3=temp+temp2

this is similar to what i did
Why is string + string less correct.
It appears to work fine.
Is & faster than +
0
 

Expert Comment

by:wsanchez
ID: 1464845
+ and & can both be used in your situation but to eliminate ambiguity, avoid using + for string concatenations since it could also be used for addition of two or more expressions depending on the type of variables declared.

For example:

if + is used on two string Variants, the result is a concatenation;
if it is used on two numeric Variants, the result is addition;
if it is used on one numeric and one string Variant, the result is addition.

On the other hand,
if & is used and one expression is not a string, it is converted to a string Variant and the result is a string Variant;
if it is used and both expressions are string expressions, the result is a String;

In what you did, since temp and temp2 are both Strings, the result is also a string, other than the fact that temp3, the result, was declared as String.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 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