Solved

Number to String

Posted on 1998-07-02
8
161 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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