#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    AS400 programmer needs help with classic asp problem


    I am a AS400 programmer asked to fix this Classic ASP program. I am clueless with classic asp, please offer help if you can.

    I am attempting to get the last record (many sequence numbers) as long as the date field is not blank. If so read the next one. I am able to grab the last record if the hearing date is not zero.

    I am having difficulty getting the code the read the next record. For example, if seq. 12 has a hearing date with a 0, read seq. 11, check if 0, is so, read seq. 10, if not use that hearing date.

    Please show me what i am doing wrong and explain, if possible. The form is CASE "34" and the fields are Hearing Date (dthearing) and decision code (decCode). Some of the code is commented out, as I test, to attempt to get it to work. This code pre-populates a formatta form from a as400 database. The hearing date is HRGDAT and the decision code is DECCOD (COPY) in the descriptor file. The hearing date cannot be greater than today's date.




    Function GetLastHeldHearing(x)
    dim dtHearing, dtLastHearing, hearingDate, decCode, idx, arr(1)
    hearingDate = ""
    decCode = ""
    dtLastHearing = cdate("1/1/1901")
    For idx = 0 To x.getElementsByTagName("CASHRG").Length - 1
    dtHearing = CDate(FixDate(x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("HRGDAT").Text, "Short"))
    decCode = x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("DECCOD").Text

    arr(0) = dtHearing
    'arr(0) = hearingDate
    arr(1) = decCode
    GetLastHeldHearing = arr

    If dtHearing <= Now() And dtHearing > dtLastHearing then

    dtHearing = FixDate(x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("HRGDAT").Text, "Short")
    decCode = x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("DECCOD").Text

    'arr(0) = hearingDate
    'arr(1) = decCode

    end if

    Next
    'arr(0) = hearingDate
    'arr(1) = decCode
    'GetLastHeldHearing = arr

    End Function



    Case "34"
    If hearingDate = "" Then
    For idx = 0 To x.getElementsByTagName("CASHRG").Length - 1
    dtHearing = CDate(FixDate(x.getElementsByTagName("CASHRG").Item (idx).Attributes.getNamedItem("HRGDAT").Text, "Short"))
    decCode = x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem ("DECCOD").Text

    'arr = GetLastHeldHearing(x)
    'hearingDate = dtHearing
    'hearingDate = arr(0)
    'decCode = arr(1)

    Next
    End If
    'SetPffField pff, a(i+1), hearingDate
    SetPffField pff, a(i+1), dtHearing
    SetPffField pff, a(i+1), FixDate(x.getElementsByTagName(a(i+2)).Item (0).Attributes.getNamedItem(a(i+3)).Text, "Short")
    End Select
    Else ' org code
    SetPffField pff, a(i+1), FixDate(x.getElementsByTagName(a(i+2)).Item (0).Attributes.getNamedItem(a(i+3)).Text, "Short")
    End if 'Last END IF



    Case "COPY"
    If a(i+3) = "DECCOD" Then
    If a(i) = "34" Then
    If hearingDate = "" Then

    arr = GetLastHeldHearing(x)
    'hearingDate = dtHearing
    hearingDate = arr(0)
    decCode = arr(1)
    End if
    arr = GetLastHeldHearing(x)
    'hearingDate = dtHearing
    hearingDate = arr(0)
    decCode = arr(1)
    SetPffField pff, a(i+1), decCode
    Else
    SetPffField pff, a(i+1), HTMLCode(x.getElementsByTagName(a(i+2)).Item(0).Attributes.getNamedItem(a(i+3)).Text)
    End If
    Else
    SetPffField pff, a(i+1), HTMLcode(x.getElementsByTagName(a(i+2)).Item(0).Attributes.getNamedItem(a(i+3)).Text)
    End If


    Thank you so very much.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    120
    Rep Power
    10
    it looks like you writing client side vbscript, right? is that data validation?
    if not, your data located on AS400 right?
    You run query directly from as400 and need to massage before dispay to user? If yes it is too late to do that in vbscript on client you make that work, but screen will be flash and rearange in browser.
    if you read data from AS400 you can filter and sort your recordset to anyway need and just output data to the screen.
    If I'm not right and you need client validation it is better and more realieble to use jquery or javascript for that (at least all borwsers understand javascript and jquery)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by gk53
    it looks like you writing client side vbscript, right? is that data validation?
    if not, your data located on AS400 right?
    You run query directly from as400 and need to massage before dispay to user? If yes it is too late to do that in vbscript on client you make that work, but screen will be flash and rearange in browser.
    if you read data from AS400 you can filter and sort your recordset to anyway need and just output data to the screen.
    If I'm not right and you need client validation it is better and more realieble to use jquery or javascript for that (at least all borwsers understand javascript and jquery)
    Hello, this is being done with classic asp, using formatta forms and a descriptor file. I know some vb.net, asp.net and this is nothing like that. No javascript or vb script. I have been told not to use VS2010 and to edit in Notepad. I think I just do not understand how the loop works. When I debug with Response.write, after the NEXT statement, it is at the "first" record, I mean sequence number 1, this is in the function
    GetLastHeldHearing. The query is an XML query that gets the "last record". I only read from the as400.
    Thanks so much for your quick reply.
    Last edited by tnickey; November 18th, 2013 at 04:00 PM. Reason: left out important note
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    120
    Rep Power
    10
    this is how your function works
    Function GetLastHeldHearing(x)
    rem variables declaration
    dim dtHearing, dtLastHearing, hearingDate, decCode, idx, arr(1)
    rem set default values
    hearingDate = ""
    decCode = ""
    dtLastHearing = cdate("1/1/1901")
    rem loop throw all form elements with name "CASHRG"
    For idx = 0 To x.getElementsByTagName("CASHRG").Length - 1
    rem fo earch element "CASHRG" find inside element "HRGDAT" and read value into dtHearing as date
    dtHearing = CDate(FixDate(x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("HRGDAT").Text, "Short"))
    rem fo earch element "CASHRG" find inside element "DECCOD" and read value into decCode
    decCode = x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("DECCOD").Text
    rem move dtHearing and hearingDate into array
    arr(0) = dtHearing
    'arr(0) = hearingDate
    arr(1) = decCode
    rem assign value of array to function
    GetLastHeldHearing = arr
    rem if dtHearing between now and dtLastHearing
    If dtHearing <= Now() And dtHearing > dtLastHearing then
    rem fo earch element "CASHRG" find inside element "HRGDAT" and read value into dtHearing as date
    dtHearing = FixDate(x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("HRGDAT").Text, "Short")
    rem fo earch element "CASHRG" find inside element "DECCOD" and read value into decCode
    decCode = x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("DECCOD").Text

    rem move dtHearing and hearingDate into array
    'arr(0) = hearingDate
    'arr(1) = decCode
    end if

    Next
    'arr(0) = hearingDate
    'arr(1) = decCode
    'GetLastHeldHearing = arr

    End Function
    that does not make a lot of sense...
    try something like

    Function GetLastHeldHearing()
    dim dtHearing, dtLastHearing, hearingDate, decCode, idx, arr(1)
    hearingDate = ""
    decCode = ""
    dtLastHearing = cdate("1/1/1901")
    For idx = 0 To x.getElementsByTagName("CASHRG").Length - 1
    dtHearing = GetHeldHearing x
    if If dtHearing <= Now() And dtHearing > dtLastHearing then
    dtLastHearing = dtHearing
    end if
    Next

    GetLastHeldHearing = dtLastHearing

    End Function

    function GetHeldHearing(x)
    dtHearing = CDate(FixDate(x.getElementsByTagName("CASHRG").Item(idx).Attributes.getNamedItem("HRGDAT").Text, "Short"))
    GetHeldHearing = dtHearing
    End Function
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,453
    Rep Power
    4539
    Please use forum CODE tags around posted code.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo