Newbie Array question.

Discussion in 'ASP General' started by Andrew, Jan 27, 2004.

  1. Andrew

    Andrew Guest

    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
     
    Andrew, Jan 27, 2004
    #1
    1. Advertising

  2. Andrew

    TomB Guest

    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





    "Andrew" <> wrote in message
    news:...
    > 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
     
    TomB, Jan 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mara Guida

    const and array of array (of array ...)

    Mara Guida, Sep 2, 2009, in forum: C Programming
    Replies:
    3
    Views:
    509
    David RF
    Sep 3, 2009
  2. Yvon Thoraval
    Replies:
    5
    Views:
    224
    Jason Creighton
    Sep 17, 2003
  3. Alfonso Caponi

    newbie: argh! array of array

    Alfonso Caponi, Dec 23, 2009, in forum: Ruby
    Replies:
    3
    Views:
    107
    Alfonso Caponi
    Dec 24, 2009
  4. darren_uk
    Replies:
    4
    Views:
    140
    Tad McClellan
    Nov 1, 2003
  5. Jerry C.
    Replies:
    8
    Views:
    262
    Uri Guttman
    Nov 23, 2003
Loading...

Share This Page