Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Re: Adding and concatenating a variable.


Message #1 by Paul Stearns <pauls@c...> on Wed, 26 Jun 2002 20:33:51 -0400
--------------F5AE6E08F95F25E1A6353E67
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Cheng:

I was answering a different question. But it is one that you should
consider. What to do when two people enter your site at the same time.
The problem is that if you get the highest value from the DB for both
users at the same time you will have a problem of duplicate numbers.

The two choices to solve this problem are to use an application variable
which gets set at application startup and is constantly updated as users
enter the system or to use the method I mention below.

Paul

Cheng Kok Wai wrote:

>  i am using MS Access now. later i will change to MSSQL Server 2000
> when the server arrives. i am thinking ot splitting the record. for
> example the record is CSC467_0001, i will split it to "CSC467_" to the
> 1st variable and "0001" to the second variable. i tried to add 1 to
> the value "0001" but the result i get is 2 instead of of "0002" which
> is wat i wanted. how do i get "0002" so that i can concatenate to the
> first variable to become the new id of CSC467_0002 and display on the
> form? thanks for the help.
>
>      ----- Original Message -----
>      From: Paul Stearns
>      To: ASP Web HowTo
>      Sent: Wednesday, June 26, 2002 11:17 AM
>      Subject: [asp_web_howto] Re: Adding and concatenating a
>      variable.
>       Cheng:
>
>      In order to provide help it would be good to know what
>      Database are you using.
>
>      The problem that arises is that you need an atomic insert
>      and select, and different databses do it differently. In
>      Oracle you would set up a "sequence" select the sequence,
>      and then insert the record with the sequence into the DB.
>      You would then be able to use the sequence number in your
>      vbscript. I know that SQL Server has equivalent
>      functionality, but I am not familiar with it.
>
>      Paul
>
>
>      Cheng Kok Wai wrote:
>
>     > i have a problem here. once a user enters one of my form
>     > in the system i am doing, i want to generate an id. in my
>     > database i have got record from CSC467_0001 to CSC467_0005
>     > (this is the last record). then the new generated id
>     > should be CSC467_0006 appeared on the text field form. if
>     > the last record is CSC467_0010, then the new id is
>     > CSC467_0011, if the last record is CSC467_0100, then the
>     > new id is CSC467_0101 and so on. it will add 1 to the last
>     > record in the database. thanks for the help.--- Improve
>     > your web design skills with these new books from
>     > Glasshaus. Usable Web Menus
>     > http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
>     > r-20 Constructing Accessible Web Sites
>     > http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
>     > r-20 Practical JavaScript for the Usable Web
>     > http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
>     > r-20 --- 
>     > http://p2p.wrox.com/manager.asp or to unsubscribe send a
>     > blank email to 
>
>      --- Improve your web design skills with these new books from
>      Glasshaus. Usable Web Menus
>      http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
>      r-20 Constructing Accessible Web Sites
>      http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
>      r-20 Practical JavaScript for the Usable Web
>      http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
>      r-20 --- 
>      http://p2p.wrox.com/manager.asp or to unsubscribe send a
>      blank email to 
>
> --- Improve your web design skills with these new books from
> Glasshaus. Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20 Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20 Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20 --- Change your mail options at http://p2p.wrox.com/manager.asp
> or 


Message #2 by "Ken Schaefer" <ken@a...> on Wed, 26 Jun 2002 16:18:44 +1000
0001 and 0002 are not numbers, they are strings.

Whan you need to do is convert them to a number, add 1, then convert it back
to a string.

So:

<%
On Error Resume Next

lngOldID = "0001"
lngNewID = CLng(lngOldID) + 1
strNewID = Right("000" & lngNewID, 4)

If Err.Number <> 0 then
    ' Something went wrong trying to do the Cast
End If
%>

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Cheng Kok Wai" <kwcheng@i...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Wednesday, June 26, 2002 1:43 PM
Subject: [asp_web_howto] Re: Adding and concatenating a variable.


i am using MS Access now. later i will change to MSSQL Server 2000 when the
server arrives. i am thinking ot splitting the record. for example the
record is CSC467_0001, i will split it to "CSC467_" to the 1st variable and
"0001" to the second variable. i tried to add 1 to the value "0001" but the
result i get is 2 instead of of "0002" which is wat i wanted. how do i get
"0002" so that i can concatenate to the first variable to become the new id
of CSC467_0002 and display on the form? thanks for the help.
  ----- Original Message -----
  From: Paul Stearns
  To: ASP Web HowTo
  Sent: Wednesday, June 26, 2002 11:17 AM
  Subject: [asp_web_howto] Re: Adding and concatenating a variable.


  Cheng:
  In order to provide help it would be good to know what Database are you
using.

  The problem that arises is that you need an atomic insert and select, and
different databses do it differently. In Oracle you would set up a
"sequence" select the sequence, and then insert the record with the sequence
into the DB. You would then be able to use the sequence number in your
vbscript. I know that SQL Server has equivalent functionality, but I am not
familiar with it.

  Paul


  Cheng Kok Wai wrote:

    i have a problem here. once a user enters one of my form in the system i
am doing, i want to generate an id. in my database i have got record from
CSC467_0001 to CSC467_0005 (this is the last record). then the new generated
id should be CSC467_0006 appeared on the text field form. if the last record
is CSC467_0010, then the new id is CSC467_0011, if the last record is
CSC467_0100, then the new id is CSC467_0101 and so on. it will add 1 to the
last record in the database. thanks for the help.--- Improve your web design
skills with these new books from Glasshaus. Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20 Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20 Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20 --- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to 
  --- Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20 Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20 Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20 --- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to 



---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20




Message #3 by "Cheng Kok Wai" <kwcheng@i...> on Wed, 26 Jun 2002 10:57:18 +0800
This is a multi-part message in MIME format.

------=_NextPart_000_0064_01C21D00.3D938A00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

i have a problem here. once a user enters one of my form in the system i 
am doing, i want to generate an id. in my database i have got record 
from CSC467_0001 to CSC467_0005 (this is the last record). then the new 
generated id should be CSC467_0006 appeared on the text field form. if 
the last record is CSC467_0010, then the new id is CSC467_0011, if the 
last record is CSC467_0100, then the new id is CSC467_0101 and so on. it 
will add 1 to the last record in the database. thanks for the help.


Message #4 by Paul Stearns <pauls@c...> on Tue, 25 Jun 2002 23:17:20 -0400
--------------901A18376266EBA801258C08
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Cheng:

In order to provide help it would be good to know what Database are you
using.

The problem that arises is that you need an atomic insert and select,
and different databses do it differently. In Oracle you would set up a
"sequence" select the sequence, and then insert the record with the
sequence into the DB. You would then be able to use the sequence number
in your vbscript. I know that SQL Server has equivalent functionality,
but I am not familiar with it.

Paul


Cheng Kok Wai wrote:

> i have a problem here. once a user enters one of my form in the system
> i am doing, i want to generate an id. in my database i have got record
> from CSC467_0001 to CSC467_0005 (this is the last record). then the
> new generated id should be CSC467_0006 appeared on the text field
> form. if the last record is CSC467_0010, then the new id is
> CSC467_0011, if the last record is CSC467_0100, then the new id is
> CSC467_0101 and so on. it will add 1 to the last record in the
> database. thanks for the help.--- Improve your web design skills with
> these new books from Glasshaus. Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20 Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20 Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20 --- Change your mail options at http://p2p.wrox.com/manager.asp
> or 


Message #5 by "Cheng Kok Wai" <kwcheng@i...> on Wed, 26 Jun 2002 11:43:33 +0800
This is a multi-part message in MIME format.

------=_NextPart_000_0095_01C21D06.B315E100
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

i am using MS Access now. later i will change to MSSQL Server 2000 when 
the server arrives. i am thinking ot splitting the record. for example 
the record is CSC467_0001, i will split it to "CSC467_" to the 1st 
variable and "0001" to the second variable. i tried to add 1 to the 
value "0001" but the result i get is 2 instead of of "0002" which is wat 
i wanted. how do i get "0002" so that i can concatenate to the first 
variable to become the new id of CSC467_0002 and display on the form? 
thanks for the help.
  ----- Original Message -----
  From: Paul Stearns
  To: ASP Web HowTo
  Sent: Wednesday, June 26, 2002 11:17 AM
  Subject: [asp_web_howto] Re: Adding and concatenating a variable.


  Cheng:
  In order to provide help it would be good to know what Database are 
you using.

  The problem that arises is that you need an atomic insert and select, 
and different databses do it differently. In Oracle you would set up a 
"sequence" select the sequence, and then insert the record with the 
sequence into the DB. You would then be able to use the sequence number 
in your vbscript. I know that SQL Server has equivalent functionality, 
but I am not familiar with it.

  Paul
   

  Cheng Kok Wai wrote:

    i have a problem here. once a user enters one of my form in the 
system i am doing, i want to generate an id. in my database i have got 
record from CSC467_0001 to CSC467_0005 (this is the last record). then 
the new generated id should be CSC467_0006 appeared on the text field 
form. if the last record is CSC467_0010, then the new id is CSC467_0011, 
if the last record is CSC467_0100, then the new id is CSC467_0101 and so 
on. it will add 1 to the last record in the database. thanks for the 
help.--- Improve your web design skills with these new books from 
Glasshaus. Usable Web Menus 
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e r-20 Constructing Accessible Web Sites 
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e r-20 Practical JavaScript for the Usable Web 
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e r-20 --- Change your mail options at http://p2p.wrox.com/manager.asp 
or 
  --- Improve your web design skills with these new books from 
Glasshaus. Usable Web Menus 
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e r-20 Constructing Accessible Web Sites 
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e r-20 Practical JavaScript for the Usable Web 
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e r-20 --- Change your mail options at http://p2p.wrox.com/manager.asp 
or 



  Return to Index