Arrays

B

bryan

document.new
I get the userid from a module and want to populate a text field with the
user's phone extension.
Here's an example of user's and phone ext:
bjsorens336
rewelin415
reellis613

Thanks,
Bryan
 
G

Graham Mayor

You haven't given enough information to do more than stab a guess at what
you are doing however

Dim sExtension As String
sExtension = Right(UserID, 3)
ActiveDocument.FormFields("Text1").Result = "Ext: " & sExtension

will put the last three characters that form the extension number of your
variable UserID in a text form field Text1

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

bryan

In vb, how do I do a lookup of a value in an array or table of elements.
ie bjsorens is my userid, how do I lookup in the array to get 336 where the
array is biult in with values of users and ext?
Again the array or table would have a userid of 8 length and ext of 3 length
bjsorens 336
rewelin 415
reellis 613

If usewr is bjsorens, how do I look up in this array to get 336?

Thanks,
Bryan
 
B

bryan

A little more clarity
I have variable strUserID.
I want to get the 2nd dimentional value where strUserID = the 1st
dimentional value.
Coming from the AS/400 world I can do this with a lookup in a compile time
array.
Something like:
stringA lookup array1
if %found
move array2 txt1
endif

Thanks,
Bryan
 
B

bryan

A little more clarity.
I have strUserID.
With this I want to lookup up the match in array element 1 and get array
element 2 which would be the phone ext.

Thanks,
Bryan
 
G

Graham Mayor

If your items are in an array then you can read the array as follows

Dim sExtension As String
Dim UserId As Variant
UserId = Array("bjsorens336", "rewelin415", "reellis613")
sExtension = Right(UserId(0), 3)
MsgBox sExtension

Where UserID = 0 ie bjsorens336

Checkout vba help on Array

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

bryan

I am using this:
Dim USERID
Dim iarray(4)
Dim ares
Dim smd
Dim ext
USERID = GetUserName

'Test array
iarray(0) = "bjsorens336"
iarray(1) = "rewelin112"
iarray(2) = "chadman223"
iarray(3) = "alyssa334"

ares = Filter(iarray, USERID, True, vbTextCompare)

Dim i
For i = 0 To UBound(ares)
smd = ares(i)
Next
ext = Right(smd, 3)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top