 |
| 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
|
|
|

May 18th, 2005, 06:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

May 18th, 2005, 12:03 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

May 18th, 2005, 12:12 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

May 20th, 2005, 06:41 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

May 23rd, 2005, 12:17 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

May 31st, 2005, 02:04 AM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

May 31st, 2005, 06:53 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I know. I posted that with this line above:
'==========
NewArray = Split(strNewString, ", ")
...
I assumed that strNewString contained "FTWPRNADMIN01,PHDPRN01,PHDPRN02,SVFTWPRN01,SVFTWP RN02"
mmcdonal
|
|
 |