Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Array problem

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,39043
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array problem
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Array problem - 10/23/2006 11:19:21 PM   
  chris_cs

 

Posts: 93
Score: 0
Joined: 10/9/2006
Status: offline
I'm trying to loop through each element of an array to check if any of the elements match a field I've pulled out of a database and then alert the user with a MsgBox. The first element in the array should match and alert the user but the script indictaes that the 2nd and 3rd elements also match which is incorrect. The code is below:

dim dsn, dbuser, dbpass, thePeeps(2)
thePeeps(0) = "Shay"
thePeeps(1) = "Warfield"
thePeeps(2) = "Maeda"
Set Conn = CreateObject("ADODB.Connection")
Conn.Open dsn, dbuser, dbpass
strsql = "SELECT ContactNames002 FROM JL_01_JobHeader where JobNumber = 'G032697PT'"
Set oRs2 = Conn.Execute(strsql)
Results2=oRs2.getString()
set Conn = nothing
for each x in thePeeps
if findMatch(x,Results2) then
 MsgBox "There is a match!"
end if
next

public function findMatch(theName, theData)
Set expressionObject = new RegExp
with expressionObject
 .Pattern = "Shay"
 .IgnoreCase = true
 .Global = true
end with
expressionMatch = expressionObject.Test(theData)
if expressionMatch then
 findMatch = "true"
else
 findMatch = "False"
end if
set expressionObject = nothing
end function

I've left out one of the database lines for security but can anyone see why the script alerts the user when the last 2 elements don't match?
 
 
Post #: 1
 
 RE: Array problem - 10/24/2006 12:34:17 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I would have to see actual (or accurate dummy) data to say for sure, but for issues like this I typically put in a lot of WScript.Echo statements to see exactly what is being compared where.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to chris_cs)
 
 
Post #: 2
 
 RE: Array problem - 10/24/2006 1:24:08 AM   
  chris_cs

 

Posts: 93
Score: 0
Joined: 10/9/2006
Status: offline
The string i'm pulling out of the DB is 'B.E. Shay'. So the 1st element in the array is the only 1 which should match.

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Array problem - 10/24/2006 1:29:53 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
The important thing is what the other elements of the array are.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to chris_cs)
 
 
Post #: 4
 
 RE: Array problem - 10/24/2006 4:24:41 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
I think, the important thing is what the findMatch() function is looking for:

public function findMatch(theName, theData)
Set expressionObject = new RegExp
with expressionObject
 .Pattern = "Shay"
==>
  .Pattern = theName

(not testet)

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Array problem - 10/24/2006 4:30:39 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I saw that. I just assumed he had hard coded "Shay" for testing. Entirely possible I'm wrong though.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 6
 
 RE: Array problem - 10/24/2006 9:50:26 PM   
  chris_cs

 

Posts: 93
Score: 0
Joined: 10/9/2006
Status: offline
I have this sorted and working now. I had some of the data mixed up which is very annoying but I am a rookie.

Thanks for the help


(in reply to ebgreen)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array problem Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts