Click to See Complete Forum and Search --> : JavaScript to VBScript conversion


kwilliams
06-03-2004, 11:59 AM
JavaScript = JS
VBScript = VB

Hello,

I've developed some code in the past that used JS to display alternating row colors (cream), but I now need to create the same effect with VB. Here's the JS code:
<%
var Repeat1__numRows = 20;
var Repeat1__index = 0;
rsRecordset_numRows += Repeat1__numRows;
%>

<%
var RecordCounter = 0;
%>

<% while ((Repeat1__numRows-- != 0) && (!Recordset.EOF)) { %>
<tr bgcolor=
<%RecordCounter++;
if (RecordCounter % 2 == 1)
Response.Write("#ffffcc");
%>>

<%
Repeat1__index++;
rsRecordset.MoveNext();
}
%>

...and I want to covert it to VB. This is what I've come up with so far:
<%
RecordCounter = 0
Response.Write "<tr bgcolor=RecordCounter++"
If RecordCounter % 2 = 1 Then
Response.Write("#FFFFCC")
End If
Response.Write ">"
%>

The only problem I'm having relates to where it says:
If RecordCounter % 2 = 1

Does anyone know of the VB equivalent to this JS code for this statement that uses the percent sign "%"? Thanks for any help.

KWilliams

simflex
06-03-2004, 03:11 PM
why don't you try using MOD?

If RecordCounter mod 2 = 1 Then
Response.Write("<TR bgcolor=#FFFFCC>")

else
Response.Write("<TR bgcolor=#FFFFFF>")

End If

In fact, I will even trash the whole darn translation thing and use this simple code:


<%
Dim rc
If rc = "" Or
rc="#FFFFFF" Then
rc =
"#CECECE"
Else
rc =
"#FFFFFF"
%>
-------------------------
----------
And then, inside the while
loop when you retrive the records, plug
that value back in within the TR tag
like this :
<TR bgcolor = "<%=rc%>">

kwilliams
06-03-2004, 03:28 PM
Hello simflex,

When I'm saying conversion, I just mean converting the syntax for VBScript code so that it works in the same way as JavaScript code that I currently have.

After I posted this question, I found the "If RecordCounter mod 2 = 1 Then" solution on Macromedia's support site. So thanks for the suggestion. I greatly appreciate the quick reponse. Have a good one.

KWilliams