Avatar of Aleks
Aleks
Flag for United States of America asked on

code in ASP/Javascript to ASP/VBscript

I have a page in ASP/JavaScript. I am moving it to ASP/VB script. I need a little help with this part of the code:

I need to show a 'region' based on the value of a field in the recordset.  (Using DW) . recordset name is 'rs_qnrsent', the field name is 'isaccepted'

 If  qnrsent.isaccepted = 0
                    Sent
If qnrsent.isaccepted= 3
                    In progress
If qnrsent.isaccepted= 2
                    Awaiting approval
If qnrsent.isaccepted= 1
                    Accepted
ASPVB ScriptJavaScript

Avatar of undefined
Last Comment
Big Monty

8/22/2022 - Mon
Big Monty

Try this:

Dim isAccepted ; isAccepted = CInt ( qnrsen("isaccepted") ) 
Dim status 

select case isAccepted 
    case 0: 
         status = "Sent" 
         break 
   case 3:
         status = "in progress" 
         break 
   case 2:
         status = "awaiting approval" 
         break 
   case 1:
         status = "accepted" 
         break 
End select

Response.Write status

Open in new window

Aleks

ASKER
I get an error:

Microsoft VBScript compilation  error '800a0401'

Expected end of statement

/bluedot/Intranet/inbox/outboxall.asp, line 49
Dim isAccepted ; isAccepted = CInt ( qnrsen("isaccepted") )
Aleks

ASKER
I changed the names to correspond to my actual records:

Dim IsAccepted ; IsAccepted = CInt ( rs_outboxall("IsAccepted") )
Dim qnrstatus

select case IsAccepted
    case 0:
         qnrstatus = "Sent"
         break
   case 3:
         qnrstatus = "in progress"
         break
   case 2:
         qnrstatus = "awaiting approval"
         break
   case 1:
         qnrstatus = "accepted"
         break
End select

I get the error:

Microsoft VBScript compilation  error '800a0401'

Expected end of statement

/bluedot/Intranet/inbox/outboxall.asp, line 49
Dim IsAccepted ; IsAccepted = CInt ( rs_outboxall("IsAccepted") )
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Big Monty

That should be a colon, not a semicolon on line 49
Aleks

ASKER
They all display 'sent' even though the value is 2 or 3. Here is the final code:

Dim IsAccepted : IsAccepted = CInt ( rs_outboxall("IsAccepted") )
Dim qnrstatus

select case IsAccepted
    case 0:
         qnrstatus = "Sent"
     
   case 3:
         qnrstatus = "in progress"
       
   case 2:
         qnrstatus = "awaiting approval"
       
   case 1:
         qnrstatus = "accepted"
       
End select
Big Monty

ok let's try using string values instead, they work better in scenarios like this:

Dim IsAccepted : IsAccepted = CStr( rs_outboxall("IsAccepted") ) 
Dim qnrstatus 

select case IsAccepted 
    case "0": 
         qnrstatus = "Sent" 
      
   case "3":
         qnrstatus = "in progress" 
        
   case "2":
         qnrstatus = "awaiting approval" 
       
   case "1":
         qnrstatus = "accepted" 
        
End select

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Aleks

ASKER
no luck. Same .. all say 'sent'
Big Monty

it may help to see the entire page worth of code, as I'm guessing the problem may lie elsewhere
Aleks

ASKER
I am displaying it inside a repeated region.  

as:  <%Response.Write (qnrstatus) %>

This is the code for the repeated region:

----

  <%
While ((Repeat1__numRows <> 0) AND (NOT rs_outboxall.EOF))
%>
  <tr class="gradeX">
    <td><%Response.Write (qnrstatus) %>
-      <%=(rs_outboxall.Fields.Item("IsAccepted").Value)%></td>
    <td><a href="../Qnr/QnrPreview.asp?QnrUserid=<%=(rs_outboxall.Fields.Item("UserId").Value)%>&Qnrmailedid=<%=(rs_outboxall.Fields.Item("Id").Value)%>&Qnrtype=inbox&qnr=1" class="btn btn-white btn-sm"> <i class="fa fa-folder"></i> View </a>&nbsp;<a href="SPDeleteQnr.asp?QnrId=<%=(rs_outboxall.Fields.Item("Id").Value)%>" class="btn btn-white btn-sm" onClick="GP_popupConfirmMsg('Please confirm you wish to delete the Questionnaire.');return document.MM_returnValue"> <i class="fa fa-trash-o"></i> Delete </a>&nbsp;<a href="Resendqnremail.asp?QnrId=<%=(rs_outboxall.Fields.Item("id").Value)%>" class="btn btn-white btn-sm"> <i class="fa fa-envelope"></i> email </a></td>
    <td><%= DoDateTime((rs_outboxall.Fields.Item("SentOn").Value), 2, 9225) %></td>
    <td><span class="bodytext"><%=(rs_outboxall.Fields.Item("SentTo").Value)%>&nbsp;&nbsp;<%=(rs_outboxall.Fields.Item("firstnm").Value)%>&nbsp;<%=(rs_outboxall.Fields.Item("lastnm").Value)%></span></td>
    <td><%= DoDateTime((rs_outboxall.Fields.Item("AcceptedOn").Value), 2, 9225) %></td>
    <td><%=(rs_outboxall.Fields.Item("SenderEmail").Value)%></td>
    <td class="center">
     
      XX
    </td>
  </tr>
  <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rs_outboxall.MoveNext()
Wend
%>

----
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Big Monty

ok you need to call the code each time otherwise it'll be the same value. make the code I gave you a function and call it in your loop:

<% 
While ((Repeat1__numRows <> 0) AND (NOT rs_outboxall.EOF)) 
%>
  <tr class="gradeX">
    <td><%Response.Write getStatus( rs_outboxall("IsAccepted") ) %>
-      <%=(rs_outboxall.Fields.Item("IsAccepted").Value)%></td>
    <td><a href="../Qnr/QnrPreview.asp?QnrUserid=<%=(rs_outboxall.Fields.Item("UserId").Value)%>&Qnrmailedid=<%=(rs_outboxall.Fields.Item("Id").Value)%>&Qnrtype=inbox&qnr=1" class="btn btn-white btn-sm"> <i class="fa fa-folder"></i> View </a>&nbsp;<a href="SPDeleteQnr.asp?QnrId=<%=(rs_outboxall.Fields.Item("Id").Value)%>" class="btn btn-white btn-sm" onClick="GP_popupConfirmMsg('Please confirm you wish to delete the Questionnaire.');return document.MM_returnValue"> <i class="fa fa-trash-o"></i> Delete </a>&nbsp;<a href="Resendqnremail.asp?QnrId=<%=(rs_outboxall.Fields.Item("id").Value)%>" class="btn btn-white btn-sm"> <i class="fa fa-envelope"></i> email </a></td>
    <td><%= DoDateTime((rs_outboxall.Fields.Item("SentOn").Value), 2, 9225) %></td>
    <td><span class="bodytext"><%=(rs_outboxall.Fields.Item("SentTo").Value)%>&nbsp;&nbsp;<%=(rs_outboxall.Fields.Item("firstnm").Value)%>&nbsp;<%=(rs_outboxall.Fields.Item("lastnm").Value)%></span></td>
    <td><%= DoDateTime((rs_outboxall.Fields.Item("AcceptedOn").Value), 2, 9225) %></td>
    <td><%=(rs_outboxall.Fields.Item("SenderEmail").Value)%></td>
    <td class="center">
      
      XX
    </td>
  </tr>
  <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rs_outboxall.MoveNext()
Wend

function getStatus( valToCheck )
Dim qnrstatus 

select case valToCheck
    case "0": 
         qnrstatus = "Sent" 
      
   case "3":
         qnrstatus = "in progress" 
        
   case "2":
         qnrstatus = "awaiting approval" 
       
   case "1":
         qnrstatus = "accepted" 
        
End select

getStatus = qnrstatus

end function
%>

Open in new window

Aleks

ASKER
It displays nothing now.

My display code:  Response.Write (qnrstatus)

The part of code I changed to embed yours (and removed the code I had before)

<%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rs_outboxall.MoveNext()
Wend

function getStatus( valToCheck )
Dim qnrstatus

select case valToCheck
    case "0":
         qnrstatus = "Sent"
     
   case "3":
         qnrstatus = "in progress"
       
   case "2":
         qnrstatus = "awaiting approval"
       
   case "1":
         qnrstatus = "accepted"
       
End select

getStatus = qnrstatus

end function
ASKER CERTIFIED SOLUTION
Big Monty

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question