PC Review


Reply
Thread Tools Rate Thread

Problem Generating Key = reprise

 
 
Wes
Guest
Posts: n/a
 
      22nd Mar 2010
has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M.

I find it strange that I get a space added to my variable

After retrieving the highest key, I pick up the last 4 characters and add 1

intNewKey = Int(Mid(strMax, 3, 4)) + 1 ' pick up the last 4 bytes and
increment

[ IntNewkey 1003 ]


I then have to convert it back to a string to create the new key

strNewKey = Str(intNewKey) ' cast to string

when I do, the variabel has a blank placed in the first position

[ StrNewKey " 1003" Notice the leading space ]


Is there something I am doing incorrectly here, is this the way it is
supposed to work?

I have done some research and a lot of testing, and it always appears to
work like this.

thanks

Wes
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      22nd Mar 2010
According to the Help file entry for the Str function "When numbers are
converted to strings, a leading space is always reserved for the sign of
number. If number is positive, the returned string contains a leading space
and the plus sign is implied."

Try:

strNewKey = Format(CInt(Right(strMax, 4) + 1, "0000")

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Wes" <(E-Mail Removed)> wrote in message
news:m7Qpn.14851$(E-Mail Removed)...
> has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M.
>
> I find it strange that I get a space added to my variable
>
> After retrieving the highest key, I pick up the last 4 characters and add
> 1
>
> intNewKey = Int(Mid(strMax, 3, 4)) + 1 ' pick up the last 4 bytes and
> increment
>
> [ IntNewkey 1003 ]
>
>
> I then have to convert it back to a string to create the new key
>
> strNewKey = Str(intNewKey) ' cast to string
>
> when I do, the variabel has a blank placed in the first position
>
> [ StrNewKey " 1003" Notice the leading space ]
>
>
> Is there something I am doing incorrectly here, is this the way it is
> supposed to work?
>
> I have done some research and a lot of testing, and it always appears to
> work like this.
>
> thanks
>
> Wes



 
Reply With Quote
 
 
 
 
XPS350
Guest
Posts: n/a
 
      22nd Mar 2010
On 22 mrt, 21:08, Wes <wesjes...@charter.net> wrote:
> has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M..
>
> I find it strange that I get a space added to my variable
>
> After retrieving the highest key, I pick up the last 4 characters and add1
>
> intNewKey = Int(Mid(strMax, 3, 4)) + 1 *' pick up the last 4 bytes and
> increment
>
> [ *IntNewkey 1003 *]
>
> I then have to convert it back to a string to create the new key
>
> strNewKey = Str(intNewKey) * * * * * * *' cast to string
>
> when I do, the variabel has a blank placed in the first position
>
> [ * StrNewKey " 1003" * Notice the leading space ]
>
> Is there something I am doing incorrectly here, is this the way it is
> supposed to work?
>
> I have done some research and a lot of testing, and it always appears to
> work like this.
>
> thanks
>
> Wes


I cannot exactly figure out what is wrong with your code. I do know
Int isn't the right function to use. It cuts off the decimal part.

Access is rathet tolerant, so this code will do:

Dim Newkey As String

Newkey = Format(Mid(strMax, 3, 4) + 1, "0000")

Debug.Print Left(strMax, 2) & Newkey



Groeten,

Peter
http://access.xps350.com
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      22nd Mar 2010
On Mon, 22 Mar 2010 16:08:45 -0400, Wes <(E-Mail Removed)> wrote:

>I then have to convert it back to a string to create the new key
>
>strNewKey = Str(intNewKey) ' cast to string
>
>when I do, the variabel has a blank placed in the first position
>
>[ StrNewKey " 1003" Notice the leading space ]
>
>
>Is there something I am doing incorrectly here, is this the way it is
>supposed to work?


Try using a negative number. You'll see that it comes out as

"-1003"

It's leaving a space for the sign.

You can use Trim(Str(intNewKey)) to trim off the leading blank.
--

John W. Vinson [MVP]
 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      23rd Mar 2010
"Wes" <(E-Mail Removed)> wrote in message
news:m7Qpn.14851$(E-Mail Removed)...
> has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M.
>
> I find it strange that I get a space added to my variable
>
> After retrieving the highest key, I pick up the last 4 characters and add
> 1
>
> intNewKey = Int(Mid(strMax, 3, 4)) + 1 ' pick up the last 4 bytes and
> increment
>
> [ IntNewkey 1003 ]
>
>
> I then have to convert it back to a string to create the new key
>
> strNewKey = Str(intNewKey) ' cast to string
>
> when I do, the variabel has a blank placed in the first position
>
> [ StrNewKey " 1003" Notice the leading space ]
>
>
> Is there something I am doing incorrectly here, is this the way it is
> supposed to work?
>
> I have done some research and a lot of testing, and it always appears to
> work like this.



Use Cstr() instead of Str() -- and CInt() instead of Int():

intNewKey = CInt(Mid(strMax, 3, 4)) + 1
strNewKey = CStr(intNewKey)


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP -Registry Corruption Reprise =?Utf-8?B?Q2luY2lEYXZl?= Windows XP Help 2 7th Jul 2006 01:17 PM
[SV] Bambini bolliti (reprise) El Bandolero Freeware 1 6th Apr 2006 02:12 PM
Print PDF files from Access (reprise) CrowT Microsoft Access 0 28th Sep 2004 01:46 AM
Re: WindowsUpdate doesn't...anymore - Reprise Fred Windows XP Help 0 30th Jun 2004 11:08 PM
Intel P4 heat sink., thermal compund reprise... Ted Williamson Computer Hardware 1 29th Mar 2004 04:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 PM.