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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp looping issues... 1

Status
Not open for further replies.

LadyDi02

Technical User
May 25, 2006
61
CA
I am querying an LDAP server with a simple select and storing the result set in hidden variables. I then pass those hidden variables to another page, replace and apostrophes in the data and then split the data into arrays so that they will insert into a database. A sample of some of the code is listed below. This is what gets passed on the second page. ie FullNameDesc, EmailDesc, ManagerDesc and AliasDesc have a replace function on them to include double quotes for any words that have apostrophes.

Code:
strFullName = Split(FullNameDesc,", ")
strEmailName = Split(EmailDesc,", ")
strManagerName = Split(ManagerDesc,", ")
strAliasName = Split(AliasDesc,", ")

Now the Manager name is what I am currently working on and have issues. I am using a regex expression inorder to remove all the words/characters from the data except for the name. I have done this successfully with the following code.

Code:
set objRE = new RegExp
with objRE
..IgnoreCase = true
..Global = true
..pattern = "CN=(.*?),"
end with
set Names = objRE.execute(ManagerDesc)

Then I strip out the CN= and replace any apostrophes with double quotes so that they will insert correctly into a database as follows.

Code:
strName = Replace(Names, ("CN="), " ")
strName = Replace(Names, ",", " ")
strName = Replace(Names, "'", "''")

Then I perform my insert. However I am not sure how to add the regex value to the insert. Can anyone help construct the loop for the regex. If I exclude the variable(the manager variable/field) my insert will work. However, I am not how to insert the contents of the regex expression into my insert. This is the code I do have but receiving an error:

Code:
For i = 0 to Ubound(strFullName)
sSQL = "INSERT into Table (FullName, Email, Manager, Alias)"
sSQL = sSQL & "VALUES ('" & strFullName(i) &"', '"& strEmailName(i) &"', '" & strName(i) &"', '" & strAliasName(i) &"')"
'objConn2.Execute sSQL
NEXT

Code:
Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment
/activedirectory/testpass.asp, line 65

I do not need to use the regex expression for any of my other variables except the managerName variable this is why you see only one instance of regex and not multiples.

Please could you telling me where I am going wrong, possibly modifying my code. Hopefully it can be done or else I will resort to removing the reg ex and insert the whole managername string into the database.

Thanks again.
 
DotNetGnat,

Fair enough. I can appreciate where you are coming, but to say I am not reading the suggestions made is totally false. I am trying my best to learn and understand all the concepts and suggestions made. Just because I ask a question doesn't mean I haven not grasped the concept. Maybe my level of understanding is far less superior then yours. I am trying my best and have made attempts to correct what I see as inaccurate in any of the posted code. I have been following Tarwn's suggestions and sorry I incorrectly applied her replace variables. I did not see that in her code, nor did I pick up on that. Moreover, my knowledge of regex is limited and what I have learn has been from Tarwn's excellent explainations. I apologize if I have wasted your time.

With that being said I have read and tried to apply the suggestion but the code is still producing incorrect results. I still am getting the full string minus the CN='s now. Thanks.
 
No, you are not wasting anyone's time...we are here to help you and make you learn... just making sure that you are trying to understand what we are suggesting...

and now back to the code...

oops...my bad..i had included an additional line in the code which needs to be deleted once you use Tarwn's regex function...

try this:

Code:
FullNameDesc = Replace(FullNameDesc,"'","''")
EmailDesc = Replace(EmailDesc,"'","''")
[s]ManagerDesc = Replace(Replace(ManagerDesc,"'","''"),"CN=","")[/s]
AliasDesc = Replace(AliasDesc,"'","''")

Dim regex
Set regex = New RegExp
regex.Pattern = "CN=([^,]+)(,OU=[^,]+)+(,DC=[^,]+)+"
ManagerDesc = regex.Replace(ManagerDesc,"$1")

strFullName = Split(FullNameDesc,", ")
strEmailName = Split(EmailDesc,", ")
strManagerName = Split(ManagerDesc,", ")
strAliasName = Split(AliasDesc,", ") 

 
For i = 0 to Ubound(strFullName)
  sSQL = "INSERT into Table (FullName, Email, Manager, Alias)"
  sSQL = sSQL &  "VALUES ('" & strFullName(i) &"', '"& strEmailName(i) &"', '" & strManagerName(i) &"', '" & strAliasName(i)  &"')"
  'objConn2.Execute sSQL
  response.write sSQL & "<BR>"
NEXT
response.end

-DNG
 
and put back this line of code in place of the deleted line if you want to replace the single quotes...

ManagerDesc = Replace(ManagerDesc,"'","''")

-DNG
 
Hello again,

You have attempted to replay what tarwn asked me to do and then what I proceed to say didn't work. This was the code I had before I attempted to say it still wasn;t working. The regex function was still producing the whole string as opposed to replacing what it says it should do. Sorry.
 
alright...lets do this simple test to see if the code we have working fine...open a new page and put this code...

Code:
<%

Dim regex, ManagerDesc
ManagerDesc = "CN=Joe Smith,OU=Users,OU=HQ,DC=xxx,DC=XXX"

Set regex = New RegExp
regex.Pattern = "CN=([^,]+)(,OU=[^,]+)+(,DC=[^,]+)+"
ManagerDesc = regex.Replace(ManagerDesc,"$1")
Response.Write ManagerDesc

once you run this page, I am sure you would see result Joe Smith.

so that makes it sure that the code is working...now just track in your code to see where you are doing a mistake...do response.write statements to debug your code and lets us know if you find something weird that we all missed and that we should take care of...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top