PC Review


Reply
Thread Tools Rate Thread

Convert a string to number

 
 
=?Utf-8?B?V0xNUGlsb3Q=?=
Guest
Posts: n/a
 
      28th Mar 2007
I am using "Right(Environ("UserName"), 1)" to pull the last character in the
username. This character happens to be a number. Since it is a string, I
need to know have to convert to a numeric in order to use in a formula.

Thanks
 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      28th Mar 2007
Dim num as Long

num = Right(Environ("UserName"), 1)

Or to make it more robust

Dim num as Variant
num = Right(Environ("UserName"), 1)
if isnumeric(num) then
num = clng(num)
end if

--
Regards,
Tom Ogilvy


"WLMPilot" <(E-Mail Removed)> wrote in message
news:7A5DB685-6FE3-460F-BD59-(E-Mail Removed)...
>I am using "Right(Environ("UserName"), 1)" to pull the last character in
>the
> username. This character happens to be a number. Since it is a string, I
> need to know have to convert to a numeric in order to use in a formula.
>
> Thanks



 
Reply With Quote
 
=?Utf-8?B?dXJrZWM=?=
Guest
Posts: n/a
 
      28th Mar 2007
I think it's not a bad idea to check if a string is numeric before
converting, just in case:

res = Right(Environ("USERNAME"), 1)

If IsNumeric(res) Then
res = CInt(res)
Else
MsgBox "Can't convert"
End If

--
urkec


"Vergel Adriano" wrote:

> CInt(Right(Environ("UserName"), 1))
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "WLMPilot" wrote:
>
> > I am using "Right(Environ("UserName"), 1)" to pull the last character in the
> > username. This character happens to be a number. Since it is a string, I
> > need to know have to convert to a numeric in order to use in a formula.
> >
> > Thanks

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      28th Mar 2007
CInt(Right(Environ("UserName"), 1))

--
Hope that helps.

Vergel Adriano


"WLMPilot" wrote:

> I am using "Right(Environ("UserName"), 1)" to pull the last character in the
> username. This character happens to be a number. Since it is a string, I
> need to know have to convert to a numeric in order to use in a formula.
>
> Thanks

 
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
Convert string to a number Rick Microsoft C# .NET 3 1st Dec 2008 10:52 PM
Convert a string which might be a number to an int Bob Powell [MVP] Microsoft C# .NET 6 23rd Jun 2008 05:39 PM
Convert a number from a string into number format =?Utf-8?B?U2FuZHk=?= Microsoft Access Queries 2 21st Feb 2007 08:23 PM
Convert a String to an number 11Oppidan Microsoft Excel Programming 4 2nd Feb 2005 03:27 AM
convert string to number =?Utf-8?B?Q2hyaXN0aW5h?= Microsoft Excel Worksheet Functions 3 16th Nov 2004 02:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:17 AM.