Putting the value of an Integer into a String ?

  • Thread starter Thread starter Isis
  • Start date Start date
I

Isis

I want to build a String from several fields (and other variables greated
within the VB code) some Srings some Integers is there some way of doing
something like this;

strField1 = "Your current Total is" (Field creatd within the VB code)
[InvoiceTotal] (DB Field, Integer)
strField2 = "Exclusive of Shipping" (Field creatd within the VB code)
strDisplay (Field creatd within the VB code)

Expression something like this

strDisplay = Trim(strField1) + [InvoiceTotal] + strField2

This is just an example, it is not exactly what I am doing - I know that
there are spaces missing on the Strings etc - but it is the referencing
of the Integers into an existing String that I am interested in.

Any help appreciated.


Thanks
 
You can concatenate numeric values into a string expression without having to
convert their data type first, e.g.

Const conFirst = "Your current Total is "
Const conSecond = " Exclusive of Shipping"
Dim strDisplay As String

strDisplay = conFirst & [InvoiceTotal] & conSecond

Note that constants have been used here for the two literal strings. There
is no need to declare these as variables as they are unchanging. Note the
spaces at the end of the first literal string and start of the second.

Invoice Total is presumably a field in the underlying recordset of the form
or report in whose module the code is executing. Note that in a report's
module you can only refer to a control bound to the field, not directly to
the field in the underlying recordset as you can in a form's module.

Ken Sheridan
Stafford, England
 
You can concatenate numeric values into a string expression without
having to convert their data type first, e.g.

Const conFirst = "Your current Total is "
Const conSecond = " Exclusive of Shipping"
Dim strDisplay As String

strDisplay = conFirst & [InvoiceTotal] & conSecond

Note that constants have been used here for the two literal strings.
There is no need to declare these as variables as they are unchanging.
Note the spaces at the end of the first literal string and start of
the second.

Invoice Total is presumably a field in the underlying recordset of
the form or report in whose module the code is executing. Note that
in a report's module you can only refer to a control bound to the
field, not directly to the field in the underlying recordset as you
can in a form's module.

Ken Sheridan
Stafford, England

Isis said:
I want to build a String from several fields (and other variables
greated within the VB code) some Srings some Integers is there some
way of doing something like this;

strField1 = "Your current Total is" (Field creatd within the VB code)
[InvoiceTotal] (DB Field, Integer)
strField2 = "Exclusive of Shipping" (Field creatd within the VB code)
strDisplay (Field creatd within the VB code)

Expression something like this

strDisplay = Trim(strField1) + [InvoiceTotal] + strField2

This is just an example, it is not exactly what I am doing - I know
that there are spaces missing on the Strings etc - but it is the
referencing of the Integers into an existing String that I am
interested in.

Any help appreciated.


Thanks


Thanks for the reply Ken - I will give this a go.

I will actually be using variables for my text as the text will be
changed under certain circumstances - I tailored the text to make the
point.

Thanks
 
Back
Top