Show/Split 4 rows in a table in Loop - asp-classic

The code below is how to show/split 2 rows in a table.
But how do I get it to show/split it to 4 rows and not only two ???
dim bCloseRow
bCloseRow = True
Do while not objTrucks.eof
If bCloseRow Then response.write "<tr>"
bCloseRow = Not bCloseRow
response.write "<td><input type=checkbox name=dno value=" & objTrucks("TRUCK_NO") & objTrucks("TRUCK_NO") & ">" & objTrucks("TRUCK_NO") & "</td>"
If bCloseRow Then response.write "</tr>"
objTrucks.movenext
loop
Thanks for any help.

If there are more rows then four in the recordset you have to make a row more. And if there is less then four you have to insert some empty td tags.
Hope this helps
const iCols=4
dim iCount:iCount=0
if not objTrucks.eof then
response.write "<table>"
Do while not objTrucks.eof
if iCount=0 then response.write "<tr>"
response.write "<td><input type=checkbox name=dno value=" & objTrucks("TRUCK_NO") & objTrucks("TRUCK_NO") & ">" & objTrucks("TRUCK_NO") & "</td>"
objTrucks.movenext
iCount = iCount + 1
if iCount=iCols then
response.write "</tr>"
iCount=0
end if
loop
if iCount>0 then
for i = iCount to iCols-1
response.write "<td></td>"
next
response.write "</tr>"
end if
response.write "</table>"
end if

I would do this using a counter instead of a Boolean flag:
Const numCols = 4
Dim counter
counter = 0
Do While Not objTrucks.EOF
If counter Mod numCols = 0 Then
Response.Write "<tr>"
End If
counter = counter + 1
Response.Write "<td><input type=checkbox name=dno value=" & objTrucks("TRUCK_NO") & objTrucks("TRUCK_NO") & ">" & objTrucks("TRUCK_NO") & "</td>"
If counter Mod numCols = 0 Then
Response.Write "</tr>"
End If
objTrucks.MoveNext
Loop

Related

Read a tab delimited txt file and Display it in reverse order

I have a tab delimited text file that uses a Classic ASP page to read it and display it from top to bottom. Here is the text file:
Email Division Course TotalIncorrect Score DATE_TIME
1steve.perry#gov.gc.ca National BI Course 5 40% 2014-01-23 16:38:55
2sylvie.smith#gov.gc.ca B - H - J - L BI Course 5 100% 2014-01-31 14:56:34
3Jen.peter#gov.gc.ca D - F - K BI Course 5 100% 2014-02-07 18:11:22
4BigJimMcBob#gov.gc.ca National BI Course 5 40% 2014-01-23 16:38:55
5Tony.Montana#gov.gc.ca B - H - J - L BI Course 5 100% 2014-01-31 14:56:34
Here is the ASP code which reads the txt file:
<%
Response.CharSet = "UTF-8"
dim import_file,counter,line,fso,objFile
import_file="QuizScores.txt"
counter=0
set fso = createobject("scripting.filesystemobject")
If (fso.FileExists("D:\Vignette\QuizScores.txt"))=true Then
set objFile = fso.opentextfile(server.mappath(import_file))
str_imported_data="<table style='text-align: left; width: 98%; margin-left: 0px; margin-right: auto; font-family: Arial Narrow;' cellpadding='3' cellspacing='2' border='0'>"
Do Until objFile.AtEndOfStream
line = split(objFile.ReadLine, vbTab)
if (counter Mod 2 = 0) And (counter = 0) then
str_imported_data=str_imported_data&"<tr bgcolor='#3C3C3C' style='font-weight: bold; color:white;'>"
Elseif (counter Mod 2 = 0) Then
str_imported_data=str_imported_data&"<tr bgcolor='#EEEEEE'>"
Else
str_imported_data=str_imported_data&"<tr bgcolor='#FFFFE5'>"
end if
counter=counter+1
total_records=ubound(line)
for i=0 to total_records
if ((i=0) or (i=6)) then
str_imported_data=str_imported_data&"<td style='font-weight: bold;'><font size='-1'>"&line(i)&"</td>"
else
str_imported_data=str_imported_data&"<td><font size='-1'>"&line(i)&"</td>"
end if
next
str_imported_data=str_imported_data&"</tr>" & chr(13)
Loop
str_imported_data=str_imported_data&"<caption><b>Project Systems Solution Real Property Course Test Scores</b></caption></table>"
objFile.Close
response.Write str_imported_data
set fso=nothing
Else
Response.Write("Test Scores File does NOT exist.")
End If
%>
I would like to have the asp page read the txt file but reverse the order so that the most recent record would appear at the top of the table and the oldest at the bottom.
Any help would be appreciated. I am fairly new at ASP!
Thanks
Here is my REVISED CODE April 1st 2014:
<%
Response.CharSet = "UTF-8"
dim import_file,counter,line,fso,objFile
Dim array_line(), array_column()
import_file="QuizScores.txt"
set fso = createobject("scripting.filesystemobject")
If (fso.FileExists("D:\Vignette\QuizScores.txt")) Then
set objFile = fso.opentextfile(server.mappath(import_file))
counter=0
Do Until objFile.AtEndOfStream
array_line(counter) = objFile.ReadLine
counter=counter+1
Redim Preserve array_line(counter)
Loop
objFile.Close
set fso=nothing
str_imported_data="<table style='text-align: left; width: 98%; margin-left: 0px; margin-right: auto; font-family: Arial Narrow;' cellpadding='3' cellspacing='2' border='0'>"
total_records=ubound(array_line)
for i_row=total_records to 0 step -1
array_column = split(array_line(i_row), vbTab)
if (i_row Mod 2 = 0) And (i_row = 0) then
s_bgcolor = "bgcolor='#3C3C3C' style='font-weight: bold; color:white;'"
Elseif (i_row Mod 2 = 0) Then
s_bgcolor = "bgcolor='#EEEEEE'"
Else
s_bgcolor = "bgcolor='#FFFFE5'"
end if
str_imported_data=str_imported_data & "<tr>" & vbCrLf
for i_col = 0 to 6
if ((i=0) or (i=6)) then
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1' style='font-weight: bold;'>" & array_column(i_col) & "</td>" & vbCrLf
else
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1'>" & array_column(i_col) & "</td>" & vbCrLf
end if
next 'i_col
str_imported_data = str_imported_data & "</tr>" & vbCrLf & vbCrLf
next 'i_row
str_imported_data = "<caption><b>Project Systems Solution Real Property Course Test Scores</b></caption></table>" & vbCrLf & str_imported_data
response.Write (str_imported_data)
Else
Response.Write("Test Scores File does NOT exist.")
End If
%>
Untested but won't have many errors.
FYI: I recommend you notice the way I spaced things out; for more readable code.
Oh and if memory serves, putting "bgcolor" attribute into TR does not work in most browsers, which is why I moved it to the TDs.
<%
Response.CharSet = "UTF-8"
dim import_file,counter,line,fso,objFile
import_file="QuizScores.txt"
counter=0
set fso = createobject("scripting.filesystemobject")
If (fso.FileExists("D:\Vignette\QuizScores.txt")) Then
set objFile = fso.opentextfile(server.mappath(import_file))
counter=0
Do Until objFile.AtEndOfStream
array_line(counter) = objFile.ReadLine
counter=counter+1
Loop
objFile.Close
set fso=nothing
str_imported_data="<table style='text-align: left; width: 98%; margin-left: 0px; margin-right: auto; font-family: Arial Narrow;' cellpadding='3' cellspacing='2' border='0'>"
total_records=ubound(array_line)
for i_row=total_records to 0 step -1
array_column = split(array_line(i_row), vbTab)
if (i_row Mod 2 = 0) And (i_row = 0) then
s_bgcolor = "bgcolor='#3C3C3C' style='font-weight: bold; color:white;'"
Elseif (i_row Mod 2 = 0) Then
s_bgcolor = "bgcolor='#EEEEEE'"
Else
s_bgcolor = "bgcolor='#FFFFE5'"
end if
str_imported_data=str_imported_data & "<tr>" & vbCrLf
for i_col = 0 to 6
if ((i=0) or (i=6)) then
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1' style='font-weight: bold;'>" & array_column(i_col) & "</td>" & vbCrLf
else
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1'>" & array_column(i_col) & "</td>" & vbCrLf
end if
next 'i_col
str_imported_data = str_imported_data & "</tr>" & vbCrLf & vbCrLf
next 'i_row
str_imported_data = "<caption><b>Project Systems Solution Real Property Course Test Scores</b></caption></table>" & vbCrLf & str_imported_data
response.Write (str_imported_data)
Else
Response.Write("Test Scores File does NOT exist.")
End If
%>

Classic ASP: Empty Select When Using If Statement

I have a simple bit of code that is filling a select object from a db table. I want to check a value to set an entry as selected, but when I check a db value, I get an empty select box. This code produces the empty box:
response.write "<td><select name='FromDept'>"
Do While not rs.eof
If rs("DeptID") = 61 Then
response.write "<option value=" & rs("DeptID") & " selected>" & rs("DeptName") & "</option>"
Else
response.write "<option value=" & rs("DeptID") & ">" & rs("DeptName") & "</option>"
End If
rs.MoveNext
Loop
rs.close
response.write "</select></td>"
However, this code produces a select box with values:
response.write "<td><select name='FromDept'>"
LpCnt = 0
Do While not rs.eof
If LpCnt = 9 Then
response.write "<option value=" & rs("DeptID") & " selected>" & rs("DeptName") & "</option>"
Else
response.write "<option value=" & rs("DeptID") & ">" & rs("DeptName") & "</option>"
End If
rs.MoveNext
LpCnt = LpCnt + 1
Loop
rs.close
response.write "</select></td>"
Thanks for any help!
Assign the value to a temporary variable:
response.write "<td><select name='FromDept'>"
Do While not rs.eof
dept = rs("DeptID")
If dept = 61 Then
response.write "<option value=" & dept & " selected>" & rs("DeptName") & "</option>"
...
Empty drop down means you get error in that statement and it's ignored most likely due to On Error Resume Next line you have somewhere.
First of all, get rid of that On Error Resume Next line.
Second, error in such code means type conversion problem. Try this code instead:
Dim curDeptID
Do While not rs.eof
curDeptID = 0
If Not IsNull(rs("DeptID")) Then
curDeptID = CLng(CStr(rs("DeptID")))
End If
If curDeptID=61 Then
response.write "<option value=" & rs("DeptID") & " selected>" & rs("DeptName") & "</option>"
Else
response.write "<option value=" & rs("DeptID") & ">" & rs("DeptName") & "</option>"
End If
rs.MoveNext
Loop

how to use <a href ></a> in classic asp?

i have three columns column(0),column(1),column(2)and i want tag for these three columns in following code for this line: "strNewContents = strNewContents & "" & columns(0) & "" & columns(1) & "" & columns(2) & "" & vbcrlf:"
actual code:
Dim strFileName1
Dim objFSO, objTextFile
Dim intLineNumber, strNewContents, strReadLineText,strLineNumbers
dim data, columns
strFileName1 = "saveimagename.txt"
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(strFileName1))
intLineNumber = 0
strLineNumbers = ""
data = split(objTextFile.readall(), vbcrlf)
for intLineNumber = 0 to ubound(data)
columns = split(data(intLineNumber), ",", 3)
if (ubound(columns) = 2) then
''//strNewContents = "<td class='red'>" & columns(0) & "</td><td class='blue'>" & columns(2) & "</td>"
strNewContents = strNewContents & "<tr><td>" & columns(0) & "</td><td>" & columns(1) & "</td><td>" & columns(2) & "</td></tr>" & vbcrlf
end if
next
You are already using Response.Write with strings.
You simply:
Response.Write "" & linkName & ""

Classic ASP sub procedure call in Response.Write

I have a classic ASP question.
Attempting to do this: the recordset is a simple list of years from 1995 to 2020; and i am trying to make 2010(current year) the default selection in the drop down.
issue: I trying to call a Sub proc in "Response.Write", but it keeps giving me this error:
"Error '800a000d' Type mismatch: 'selectyear' "
Below is the code, the Attempt 1 works with out any problem. But when i move that "if" logic to a sub procedure and call it in the Request.Write, it gives me the error.
Can any one please explain why Attempt1 works and Attempt2 wouldnt.
' Attempt 1:
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td> <td> <select name='theyear' style=""WIDTH: 67px"">"
dim selyr
while not rsYEAR.EOF
if CINT(rsYEAR.fields("year")) = year(now) then
selyr = "selected"
else selyr = ""
end if
Response.Write"<option value='" & rsYEAR.fields("year") & "' "& selyr &" >" & cstr(rsYEAR.Fields("year"))
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
rsYEAR.Close
' Attempt 2:
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td> <td> <select name='theyear' style=""WIDTH: 67px"">"
dim selyr2
while not rsYEAR.EOF
Response.Write "<option value='" & rsYEAR.fields("year") & "' " & cstr(selectyear(cint(rsYEAR.fields("year")))) &" >" & cstr(rsYEAR.Fields("year"))
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
'close and clean up
rsYEAR.Close
set rsYEAR = nothing
I would greatly appreciate your response.
thank you,
Shiva
I am guessing that cint(rsYEAR.fields("year")) is throwing the error because there is data that cannot be converted to int. I would expect that to happen in both cases though.
You shouldn't need the cstr in cstr(selectyear(cint(rsYEAR.fields("year")))) in the second attempt, as I assume selectyear is already returning a string. Can you show the code for selectyear?
(How has this sat for so long without a correct answer?)
A Sub does not have a value, so you can't Response.Write it. You need to either use a function, or put the Sub call on its own line.
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td><td><select name='theyear' style=""width: 67px"">"
dim y
while not rsYEAR.EOF
y = rsYEAR.fields("year")
Response.Write "<option value='" & y & "'" & IsCurr(y) & ">" & y & "</option>"
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
rsYEAR.Close
Function IsCurr(yr)
if Cstr(yr) = Cstr(year(now)) then
IsCurr = " selected"
else
IsCurr = ""
end if
End Function
Using a sub instead of a function, this would become
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td><td><select name='theyear' style=""width: 67px"">"
dim y
while not rsYEAR.EOF
y = rsYEAR.fields("year")
Response.Write "<option value='" & y & "'"
IsCurr y
Response.Write ">" & y & "</option>"
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
rsYEAR.Close
Sub IsCurr(yr)
if Cstr(yr) = Cstr(year(now)) then
Response.Write " selected"
end if
End Sub

asp pagination problem

Hi i have a problem with this asp pagination. it seems to be putting all the links in the one row, so i think it might have something to do with the check of the int i...
but im not that familar with asp. can anyone shed any light on this problem.
the folders contain pdfs for each day of the month, named A08P2.pdf A09P2.pdf etc...
Thanks
i = 1
Set fc = f.Files
Set ff = f.SubFolders
For Each f1 in fc
intPage = cint(mid(f1.name,2,2))
chrEdition = mid(f1.name,1,1)
if chrEdition = "A" then
if i = 1 then
Response.Write "<tr>"
end if
Response.Write "<td width='40' align='center'><a href=" & sUP & f1.name & " class='blue_11px'>" & intPage & "</a></td>"
if i = 10 then
Response.Write "</tr>"
i = 0
end if
end if
i = i + 1
Next
You should move the incrementing of the i (i=i+1) inside the if...end if, since if i is 9 and you encounter two chrEditions that are not 'A' then i will become 11 and will never match the closing condition i=10:
if chrEdition = "A" then
if i = 1 then
Response.Write "<tr>"
end if
Response.Write "<td width='40' align='center'><a href=" & sUP & f1.name & " class='blue_11px'>" & intPage & "</a></td>"
if i = 10 then
Response.Write "</tr>"
i = 0
end if
i = i + 1
end if

Resources