Newbie Array question.

A

Andrew

Hi,

I've got a function that outputs any errors that it encounters as it
loops through an array (using response.write). The function works
fine, but I'd like to dump any errors into an array, then loop through
that array and output errors that way. I'm not an ASP developer, so
just getting this to work was, eh, a journey:)

Basically, I'm asking some helpful developer to essentially insert
array functionality into the function below or provide helpful hints
(where/when to redim, how to loop through and output the array, and so
on) on how to use an array to replace strErrorMsg in the code below so
I can see how it is done. I've spent the last hour or so Googling for
answers, but found nothing that is applicable. Any help is greatly
appreciated. Thanks in advance!

Function UpdateAllUsers(strUpdateUserErrors)
Dim EditAllDataFields
Dim errorOccurred
EditAllDataFields = True
strErrorMsg = ""

For ws_intAgencyUserIdx = 0 To ws_intAgencyUserCnt-1

If ws_strAgencyUserPassword(ws_intAgencyUserIdx) <>
ws_strConfirmAgencyUserPassword(ws_intAgencyUserIdx) Then
strErrorMsg = "Error: Passwords do not match. ID " &
ws_strAgencyUserID(ws_intAgencyUserIdx) & "<br>"
EditAllDataFields = False
End If

If ucase(ws_strAgencyUserPassword(ws_intAgencyUserIdx)) =
ucase(ws_strAgencyUserID(ws_intAgencyUserIdx)) and EditAllDataFields =
True Then
strErrorMsg = "Error: Your User ID and your password cannot be the
same. ID "+ws_strAgencyUserID(ws_intAgencyUserIdx)
EditAllDataFields = False
End If

If len(ws_strAgencyUserPassword(ws_intAgencyUserIdx)) > 8 and
EditAllDataFields = True Then
strErrorMsg = "Error: Your password must be between 5 and 8
characters in length. ID "+ws_strAgencyUserID(ws_intAgencyUserIdx)
EditAllDataFields = False
End If

'***** more If statements commented out ...

If EditAllDataFields = True Then
ws_strWkAgencyUserUserSrc =
Mid(ws_strAgencyUserUserSrc(ws_intAgencyUserIdx)+" ",1,1)
ws_strNewPassEncrypt =
Encrypt(ws_strAgencyUserPassword(ws_intAgencyUserIdx))

If RunSQL("UPDATE AGENCY_SECURITY SET "+_
"PASSWORD = :ws_strNewPassEncrypt, "+_
"GROUP_ID = :ws_strAgencyUserGroupId(ws_intAgencyUserIdx), "+_
"USER_SOURCE = :ws_strWkAgencyUserUserSrc,"+_
"LAST_UPDATE_USER = :CurrentUser(), LAST_UPDATE_DATE =
:CurrentDate() "+_
"WHERE AGENCY_NO = :ws_strAgencyIdKey "+_
" AND USER_ID = :ws_strAgencyUserID(ws_intAgencyUserIdx) ") Then
strUpdateUserErrors = "Users Updated Successfully."
'strUpdateUserErrors &
UpdateAllUsers = True
Else
strUpdateUserErrors = strUpdateUserErrors & "Error: ERROR UPDATING
(Reimbursement Header)"+glbl_sqlErrorString
WriteStrMsg = "Error with " & ws_intAgencyUserIdx
End If
End IF

If strErrorMsg <> "" Then
response.write "<span style='color:red;font-family:Arial;
font-weight:bold;'>" & strErrorMsg & "</span>"
strErrorMsg = ""
errorOccurred=True
end if

Next

If errorOccurred Then
response.write "<hr><b>Click <a href='fixErrors.asp'>here</a> to
Continue.</b> <i>
End If
End Function

Thanks again.

Sincerely,
Andrew
 
T

TomB

It looks to me like you wish to validate user input and would rather have
all the "errors" assembled together. I normally don't use an array for
this.
I create a page scope variable sErrorMessages that'll store the Messages.
Then everytime I get an "error" i add to it through a subroutine


Dim sErrorMessages
Dim bErrors 'a boolean for testing...
bErrors=false
sErrorMessages=""


if variableX=badvalue then AddError "bad value for variableX"
if variableY=badvalue then AddError "bad value for variableY"


if bErrors then
Response.write sErrorMessages
end if


Sub AddError (sMessage)
sErrorMessages=sErrorMessages & "<li>" & sMessage & "</li>"
bErrors=true
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top