Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 18th, 2005, 06:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Question on the ARRAY function

I am getting a TYPE MISMATCH error on the following line of my code:

strPrintServers = Array(strFinalArray)

The strFinalArray is comprised of the following:

FTWPRNADMIN01, PHDPRN01, PHDPRN02, SVFTWPRN01, SVFTWPRN02

Can someone tell me, please, what I am doing wrong? Any direction or help would be appreciated.

Thanks.
Reply With Quote
  #2 (permalink)  
Old May 18th, 2005, 12:03 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What are you trying to do? Are you trying to get all of the values in the array jammed into one variable? Are you trying to get one variable with all this text ("FTWPRNADMIN01, PHDPRN01, PHDPRN02, SVFTWPRN01, SVFTWPRN02") jammed into an array?

There is a way to do both of these things, but I don't think the way you are trying this will work. Is "strFinalArray" an array or a string variable?


mmcdonal
Reply With Quote
  #3 (permalink)  
Old May 18th, 2005, 12:12 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

Make a vbscript out of this code and it should demonstrate getting your array packed into one variable formatted with a comma and space between each element.

'======================
Dim NewArray(2)
Dim strNewString
Dim i

NewArray(0) = "Test0"
NewArray(1) = "Test1"
NewArray(2) = "Test2"

strNewString = NewArray(0)
i = 1
Do Until i = UBound(NewArray) + 1
    strNewString = strNewString & ", " & NewArray(i)
    i = i + 1
Loop
WScript.Echo strNewString
'========================

Output is:

"Test0, Test1, Test2"

mmcdonal
Reply With Quote
  #4 (permalink)  
Old May 20th, 2005, 06:41 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   Any word?

To go the other way and split the variable strNewString back into an array, do this:

'==========
NewArray = Split(strNewString, ", ")

i = 0

Do Until i = UBound(NewArray) + 1
   WScript.Echo NewArray(i)
   i = i + 1
Loop
'==========

This will yield:

Test0
Test1
Test2

HTH



mmcdonal
Reply With Quote
  #5 (permalink)  
Old May 23rd, 2005, 12:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

mmcdonal,

Sorry it took me so long to respond. The SPLIT function is what I needed, just as you stated. I thought that passing in my variable the values of the array would work through the ARRAY function but it did not work until I used the SPLIT function which did exactly what I needed.

Thanks so much for your time and help.
Reply With Quote
  #6 (permalink)  
Old May 31st, 2005, 02:04 AM
Registered User
 
Join Date: May 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can do by this way:

strFinalArray = "FTWPRNADMIN01,PHDPRN01,PHDPRN02,SVFTWPRN01,SVFTWP RN02"
strPrintServers = Split(strFinalArray,",")
With that you build an array same as :

strFinalArray(0)="FTWPRNADMIN01"
strFinalArray(1)="PHDPRN01"
strFinalArray(2)="PHDPRN02"
strFinalArray(3)="SVFTWPRN01"
strFinalArray(4)="SVFTWPRN02"

It to simple to use,
Warn, if you use split with crlf, this can't work, Split work with 1 char and CRLF equal 2 char.
you must do it before :
mystring = replace(mystring,vbcrlf,vbcr)

Great.

Reply With Quote
  #7 (permalink)  
Old May 31st, 2005, 06:53 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I know. I posted that with this line above:

'==========
NewArray = Split(strNewString, ", ")

...

I assumed that strNewString contained "FTWPRNADMIN01,PHDPRN01,PHDPRN02,SVFTWPRN01,SVFTWP RN02"


mmcdonal
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Function returning an array rfstuck Pro VB 6 5 March 12th, 2008 07:35 AM
IRR function or array oneroler84 Access 3 September 7th, 2007 10:37 AM
Passing an array to a Sub or Function donrafeal Access VBA 2 May 11th, 2006 09:39 AM
Function to Clear Text array! ebycorreia_81 VB How-To 1 January 16th, 2006 05:47 AM
How to return array value from a function nebpro BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 September 29th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.