Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch passing Split results to array 1

Status
Not open for further replies.

mcconmw

MIS
May 16, 2001
372
US
Background:
I am writing a script to e-mail Server down events and Service failure events to a select group of admins for a specified list of servers. I write the results of my WMI query to a text file. In order to not recieve multiple e-mails for the same event I test for the existence of my text file. This part works beautifully. The script is self healing in that it deletes the text file when all checks return to normal.

Problem:
The question has been raised as to what happens if a second failure arises while the script is operating in it's error state. I am trying to minimize file use and general overhead as this script runs every five minutes. I wanted to read the results of the file if it exists into an array and then compare the results of my query to the array so that it would send an additional e-mail if a second (or third, etc.) event occurred before the status returns to normal. I use the readline function to return each line of the text file and then use Split to separate each line into it's requisite pieces. This works fine. However, when I try to pass these results to another array I get a Type Mismatch error. I have tried declaring the array as both "Dim variable" and "Dim variable()". I recieve an error either way. I have tried cStr and cVar against the array that is loaded by split and recieve other errors.

I am relatively new to scripting and I am hoping I am overlooking something simple. The only work around I can come up with is to rename the file and read it over and over again for each check. This doesn't seem overly efficient to me. Any suggestions as to how to rectify this or a better way to do it would be highly appreciated. Thanks.

Mike
 
Code for the Split and the "pass" would help. When you say "pass" do you mean pass an argument to a procedure, return an array from a procedure or assign one array to another?

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Test script to read file.....

'Declare Variables and Constants
Dim sComputer
Dim sSplit
Dim sStatus
Dim sService
Const forReading = 1, forWriting = 2, forAppending = 8

'instantiate FileStystem Object
set fs = CreateObject ("Scripting.FileSystemObject")

'Process file
If fs.FileExists(".\errors.txt") Then
Set file = fs1.OpenTextFile(".\errors.txt",forReading)
i = 0
Do While file.AtEndofStream = False
sReadLn = file.ReadLine
sSplit = Split(sReadLn,vbTab)
sComputer(i) = VarsSplit(0)
sStatus(i) = sSplit(1)
sService(i) = sSplit(2)
wscript.echo sComputer(i) & vbTab & sSatus(i) & vbTab & sService(i)
i = i + 1
Loop
file1.close
Else
bBlat = 1
End If
wScript.echo done
 
On what line is the error occurring? If it is on
sComputer(i) = VarsSplit(0)
then that is not a case of assigning an array but instead assigning an array element to another array element.
You appear to not have an
Option Explicit and since I do not see a definition for VarSplit I believe that you can not reference an element in array that you have not declared explicitly with either a DIM or a Redim.

If you insist on not using an Option Explicit then prepare for more trouble.

Also, your script will "blow up" on any line that does not have two vbTabs because sSplit(0) or sSPlit(1) will be "out of range".


Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks. The line that causes the error is sComputer(i) = sSplit(0). The Var was a typo. I saw another typo where I have fs1 instead of fs. These were from various tests. The code still creates the Type Mismatch with everything correct. Thanks.

Mike

Dim sComputer
Dim sSplit
Dim sStatus
Dim sService

'Declare Variables and Constants
Const forReading = 1, forWriting = 2, forAppending = 8
set fs = CreateObject ("Scripting.FileSystemObject")


If fs.FileExists(".\errors.txt") Then
Set file1 = fs.OpenTextFile(".\errors.txt",forReading)
i = 0
Do While file1.AtEndofStream = False
sReadLn = file1.ReadLine
sSplit = Split(sReadLn,vbTab)
sComputer(i) = sSplit(0)
sStatus(i) = sSplit(1)
sService(i) = sSplit(2)
wscript.echo sComputer(i) & vbTab & sSatus(i) & vbTab & sService(i)
i = i + 1
Loop
file1.close
Else
bBlat = 1
End If
wScript.echo done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top