473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How do I highlight a number on the table when a related field is not empty?

I am using a very useful application known as GenericDB by Eli Robillard. I have a classic ASP application that requires that when a specific field contains user comments (not empty) pertaining to a particular field (which is numeric), that numeric field needs to be color highlighted or be marked with an asterisk when displayed on a table. The Lister in GenericDB has the following section that I think is where the modified code needs to be inserted. Any suggestion on how to make the modification would be appreciated.

Thanks.
jose

Expand|Select|Wrap|Line Numbers
  1.                 Select Case aFields(x,2)
  2.                     case 2, 3, 4, 5, 17  ' Integers, Reals
  3.                         if curVal <> "&nbsp;" then curval = FormatNumber(curval,0,,0) 'use commas with no decimals
  4.                     case 6 ' Currency
  5.                         if curVal <> "&nbsp;" then curval = FormatCurrency(curval,0,-1) 'replaced 2 with 0 to round off numbers
  6.                     case 11 ' Boolean
  7.                         if curVal then
  8.                             curVal = txtTrue
  9.                         else
  10.                             curVal = txtFalse
  11.                         end if
  12.                     case 7, 135 ' Date / Time: 0=General, 1=LongDate, 2=ShortDate, 3=LongTime, 4=hh:mm
  13.                         if curVal <> "&nbsp;" then curVal = FormatDateTime(curVal, Mid(strFormatDate, x, 1))
  14.                     case 130, 201, 202, 203, 204 ' String or Memo
  15.                         ' Image
  16.                         if (UCase(Left(aFields(x,1),3)) = "IMG") then
  17.                             if Session("dbMaxImageSize") = 0 then
  18.                                 curVal = "<img src=" & QUOTE & curVal & QUOTE & " alt=" & QUOTE & QUOTE & " />" 
  19.                             else 
  20.                                 ' Opens image in a new window. Use Session("dbMaxImageSize") to set "thumbnail" size
  21.                                 curVal = "<a href=" & QUOTE & curVal & QUOTE & " target = _new><img alt=" & QUOTE & txtClickToView & QUOTE & " src = " & QUOTE & curVal & QUOTE & " width=" & QUOTE & Session("dbMaxImageSize") & QUOTE & " />" & "</a>" 
  22.                             end if
  23.                             IsLink = true
  24.                         end if    
  25.  
  26.  
Aug 11 '10 #1

✓ answered by Chuck Speerly

Jose
You might want to look at my revised version of Genericdb
I just releasd GDBR4. It uses CSS style sheets, which is required. The Generic File are completely rewritten with somthings put into functions, but the concept is still the same.
I have a Session("dbFieldShowAs6") = "FONT,<font Color=#990000>
whis will display that field red

dbShowField as can be set to CONTAINS,FONT,TEXT and IMAGE

See my gdbHelp at "http://www.stauctions.com/GDBHelp/Default.asp

or here is the code i used.
'CAS Added for Session("dbFieldShowAsX")
if Session("dbFieldShowAs" & x) & "x" <> "x" then

arrFieldShowAs = split(Session("dbFieldShowAs" & x),",")

select case arrFieldShowAs(0) --------------------------------------

Case "FONT"
curVal = arrFieldShowAs(i+1) & curVal & "</font>"

Case "IMAGE"
for i = 1 to ubound(arrFieldShowAs) step 1
if ucase(trim(curVal)) = ucase(trim(arrFieldShowAs(i))) then curVal = "<img src=" & Quote & arrFieldShowAs(i+1) & Quote & ">"
next

Case "TEXT"
for i = 1 to ubound(arrFieldShowAs) step 2
if ucase(trim(curVal)) = ucase(trim(arrFieldShowAs(i))) then curVal = arrFieldShowAs(i+1) & curVal & "</font>"
next

Case "CONTAINS"

' To determine if a string contains a substring,
if ucase(Session("dbReplaceShowAs" & x)) = "YES" then curVal = replace(curVal," ","")

for i = 1 to ubound(arrFieldShowAs) step 2
If InStr(ucase(curVal),ucase(arrFieldShowAs(i))) <> 0 Then curVal = replace(curVal,arrFieldShowAs(i),arrFieldShowAs(i+ 1) & arrFieldShowAs(i) & "</font>")
next

Case "NOTNULL"
If curval


end select

end if
end if

6 1881
The logic seems simple enough:

Expand|Select|Wrap|Line Numbers
  1. strComment=Session("comment")
  2.  
  3. 'Devise a function; this is simplistic
  4.  
  5. function HighlightMe(ByVal) 
  6. If strComment <> "" then 
  7. HighlightMe = "Black" 
  8. Else 
  9. HighlightMe = "Red" 
  10. End If 
  11. end function
  12.  
  13.  
  14. 'Modify code above
  15.  
  16. If curVal <> "&nbsp;" then curval = HighlightMe(FormatNumber(curval,0,,0))
  17. .
  18. .
  19. .
  20.  
I understand that the code needs tweaking. I would appreciate any help.

Thanks.
Jose
Aug 11 '10 #2
jhardman
3,406 Expert 2GB
The thing that I think is making this hard for you to grasp, is that the table code you are using has some key features that make it ideal for making a table out of an unknown db recordset. Those same features make it hard to do what you are trying to do partly because it treats the recordset as an unknown.

What I would do is look for the beginning of the loop that has the recordset.movenext command at the end (the movenext command is going to be at teh end of the loop, but you need to go to the beginning). I would declare a variable called "isCommentEmpty" and say something like this:
Expand|Select|Wrap|Line Numbers
  1. if recordset("commentField") = "&nbsp;" then
  2.    isCommentEmpty = true
  3. end if
Then down in the line that says case 2,3,4,5,17 you need to add an if statement:
Expand|Select|Wrap|Line Numbers
  1. if aFields(x,2).name = "fieldName" then
  2.    'highlight code here
  3. end if
The key to this code is you have to know which fields are which, and it's not especially compatible with what you have above.

Jared
Aug 16 '10 #3
Hi Jared:
You are right on target as regards my general feeling about the application. It is really very easy to use for simple databases but oftentimes I found myself scratching my head on how to modify it to suit my specific need. Anyway, it has helped me a lot and 'could not complain except in cases such as this one. Jared, if you think you can help me more here is the loop routine that you described above:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. intCount = 0
  3. Do While (NOT xrs.EOF) AND (intCount < intStopRec)
  4.     intCount = intCount + 1
  5.     if Cint(intCount) >= Cint(intStartRec) then %>
  6. <tr> <%
  7.         ' Get the key
  8.         KeyField = afields(intKey,1)
  9.         curKey = xrs(Keyfield)
  10.         if NOT (curKey & "x" = "x") then 
  11.             if isNumeric(curkey) then
  12.                 strLink = "KEY=" & curKey
  13.             else ' assume text
  14.                 strLink = "KEY='" & LTrim(curKey) & "'"
  15. '                strLink = Replace(strLink," ","%20")
  16.             end if
  17.         end if
  18.         x = 0
  19.         y = 0
  20.         For Each xField in xrs.Fields
  21.             IsLink = false
  22.             x = x + 1 ' field no.
  23.             curVal = xField.Value
  24.             ' Every other line will have a shaded background
  25.             bgcolor="#FFFFFF"
  26.             if intCount mod 2 = 0 then bgcolor=strRowColor
  27.             bgcolorShade = gdbShade(bgcolor)
  28.             if Mid(strDisplay, x, 1) = "1" then 
  29.                 y = y + 1 
  30.                 ' Empty / Null / Blank
  31.                 if IsNull(curVal) OR (Trim(curVal) & "x" = "x") then 
  32.                     curVal = "&nbsp;"
  33.                 else
  34.                     if (Mid(strTotalFields, x, 1) = "1") AND IsNumeric(curVal) then aFields(x,4) = aFields(x,4) + curVal
  35.                 end if %>
  36.     <td bgcolor="<%=bgcolor%>" valign="top" <% if IsNumeric(curVal) then response.write "align=" & QUOTE & "right" & QUOTE %>><font size="<%=intFontSize%>" face="<%=strFont%>"> <%
  37.                 ' Password
  38.                 if UCase(Left(aFields(x,1),8)) = "PASSWORD" then curVal = "*****"
  39.                 ' Everything else, by field type
  40.                 Select Case aFields(x,2)
  41.                     case 2, 3, 4, 5, 17  ' Integers, Reals
  42.                         if curVal <> "&nbsp;" then curval = FormatNumber(curval,0,,0) 'use commas with no decimals
  43.                     case 6 ' Currency
  44.                         if curVal <> "&nbsp;" then curval = FormatCurrency(curval,0,-1) 'replaced 2 with 0 to round off numbers
  45.                     case 11 ' Boolean
  46.                         if curVal then
  47.                             curVal = txtTrue
  48.                         else
  49.                             curVal = txtFalse
  50.                         end if
  51.                     case 7, 135 ' Date / Time: 0=General, 1=LongDate, 2=ShortDate, 3=LongTime, 4=hh:mm
  52.                         if curVal <> "&nbsp;" then curVal = FormatDateTime(curVal, Mid(strFormatDate, x, 1))
  53.                     case 130, 201, 202, 203, 204 ' String or Memo
  54.                         ' Image
  55.                         if (UCase(Left(aFields(x,1),3)) = "IMG") then
  56.                             if Session("dbMaxImageSize") = 0 then
  57.                                 curVal = "<img src=" & QUOTE & curVal & QUOTE & " alt=" & QUOTE & QUOTE & " />" 
  58.                             else 
  59.                                 ' Opens image in a new window. Use Session("dbMaxImageSize") to set "thumbnail" size
  60.                                 curVal = "<a href=" & QUOTE & curVal & QUOTE & " target = _new><img alt=" & QUOTE & txtClickToView & QUOTE & " src = " & QUOTE & curVal & QUOTE & " width=" & QUOTE & Session("dbMaxImageSize") & QUOTE & " />" & "</a>" 
  61.                             end if
  62.                             IsLink = true
  63.                         end if        
  64.                         ' Check for dbEMailFor setting
  65.                         strContainsURL = "dbemailfor" & CStr(x)
  66.                         if (Session(strContainsURL) > 0) and NOT(IsLink) then
  67.                             strURL = xrs(aFields(Session(strContainsURL),1))
  68.                             if Trim(strURL) & "x" <> "x" then
  69.                                 IsLink = true
  70.                                 strURL = Replace(strURL,"mailto:","")
  71.                                 strURL = "mailto:" & LTrim(strURL)
  72.                                 curVal = "<a href=" & QUOTE & strURL & QUOTE & ">" & curVal & "</a>"
  73.                             end if
  74.                         end if
  75.                         ' Check for dbURLFor or dbUpload setting
  76.                         strContainsURL = "dbURLfor" & CStr(x)
  77.                         strContainsUpload = "dbUpload" & CStr(x)
  78.                         if NOT(Session(strContainsUpload) & "x" = "x") and (NOT IsLink) then 
  79.                             ' Convert it as though it were a dbURLFor setting
  80.                             Session(strContainsURL) = x
  81.                         end if
  82.                         if (Session(strContainsURL)) > 0 AND (NOT IsLink) then
  83.                             strURL = xrs(aFields(Session(strContainsURL),1))
  84.                             if strURL & "x" <> "x" then
  85.                                 IsLink = true
  86.                                 curVal = "<a href=" & QUOTE & strURL & QUOTE & ">" & curVal & "</a>"
  87.         ' *** Uncomment the following line to strip all #'s from hyperlink fields
  88.         '                        curVal = Replace(curVal,"#","")
  89.                             end if
  90.                         else
  91.                             if (UCase(Left(curVal,7)) = "HTTP://") then
  92.                                 IsLink = true
  93.                                 curVal = LT & "a href=" & QUOTE & curVal & QUOTE & " target=" & QUOTE & "_blank" & QUOTE & GT & curVal & LT & "/a" & GT
  94.         ' *** Uncomment the following line to strip all #'s from Access hyperlink fields
  95.         '                        curVal = Replace(curVal,"#","")
  96.                             end if
  97.                          end if
  98.                         ' Check for other hyperlink setting (dbLinkField)
  99.                         strContainsURL = "dbLinkField" & CStr(x)
  100.                         if (Session(strContainsURL) & "x" <> "x") AND (NOT IsLink) then
  101.                             IsLink = true
  102.                             if curVal & "x" <> "x" then curVal = gdbBuildLink(strContainsURL) & curVal & "</a>"
  103.                             if left(curVal,5) = "EMPTY" then curVal = "&nbsp;"
  104.                         end if
  105.                         ' Replace potentially harmful code
  106.                         if (NOT IsLink) then curVal = gdbSterilizeText(curVal,CInt(Mid(strDispHTML, x, 1)))
  107.                 end select
  108.                 Response.Write curVal & "&nbsp;</td>"
  109.             end if 
  110.  
  111.         Next 
  112.  
  113.         ' Show links set by dbLink
  114.         x = 1
  115.         do while NOT(Session("dbLink" & x) & "x" = "x")    %>
  116.     <td bgcolor="<%=bgcolor%>" align="center"><font size="<%=intFontSize%>" face="<%=strFont%>"><%
  117.             curVal = gdbBuildLink("dbLink" & x)
  118.             if curVal = "EMPTY" then 
  119.                 Response.write "<a name=""BLANK"">"
  120.             else
  121.                 Response.write curval 
  122.             end if
  123.             response.write "</a></font>"
  124.             x = x + 1
  125.         loop
  126.  
  127.         if (Session("dbDispView") <> "")  and intKey > 0 then %>
  128.     <td bgcolor="<%=bgcolor%>" align="center"><font size="<%=intFontSize%>" face="<%=strFont%>"><a href="<%=Session("dbGenericPath")&strViewer%>?<%=strLink%>"><%=txtView%></a></td> <%
  129.         end if 
  130.         if (Session("dbCanEdit") = 1)  and intKey > 0 then %>
  131.     <td bgcolor="<%=bgcolor%>" align="center"><font size="<%=intFontSize%>" face="<%=strFont%>"><a href="<%=Session("dbGenericPath")%><%=strEditor%>?<%=strLink%>"><%=txtEdit%></a></td> <%
  132.         end if 
  133.         if (Session("dbCanCopy") = 1) and session("dbCanAdd") = 1 and intKey > 0 then %>
  134.     <td bgcolor="<%=bgcolor%>" align="center"><font size="<%=intFontSize%>" face="<%=strFont%>"><a href="<%=Session("dbGenericPath")%><%=strEditor%>?<%=strLink%>&CMD=COPY"><%=txtCopy%></a></td> <%
  135.         end if
  136.         if (Session("dbCanDelete") = 1)  and intKey > 0 then %>
  137.     <td bgcolor="<%=bgcolor%>" align="center"><font size="<%=intFontSize%>" face="<%=strFont%>"><a href="<%=Session("dbGenericPath")%>GenericDelete.asp?<%=strLink%>"><%=txtDelete%></a></td> <%
  138.         end if %>
  139. </tr> <%
  140.     end if
  141.     xrs.MoveNext
  142. Loop 
  143.  
  144.  
Thanks for your help.
Jose
Aug 17 '10 #4
jhardman
3,406 Expert 2GB
Jose, do you know the names of the db fields that you are talking about? What are the field names for the comment field and the numeric field that needs to be highlighted?

Jared
Aug 25 '10 #5
Hi Jared:
I got 34 of them. But for sample purposes let's use just the five of them as follows:

Numeric Field (in $):...........Comment Field (memo):
FederalAlloc....................C_FederalAlloc
StateAlloc .....................C_StateAlloc
CountyAlloc ....................C_CountyAlloc
NonNIFAAlloc....................C_NonNIFAAlloc
NIFAAlloc.......................C_NIFAAlloc

Thanks. I really appreciate you helping me on this.

Jose
Aug 25 '10 #6
Jose
You might want to look at my revised version of Genericdb
I just releasd GDBR4. It uses CSS style sheets, which is required. The Generic File are completely rewritten with somthings put into functions, but the concept is still the same.
I have a Session("dbFieldShowAs6") = "FONT,<font Color=#990000>
whis will display that field red

dbShowField as can be set to CONTAINS,FONT,TEXT and IMAGE

See my gdbHelp at "http://www.stauctions.com/GDBHelp/Default.asp

or here is the code i used.
'CAS Added for Session("dbFieldShowAsX")
if Session("dbFieldShowAs" & x) & "x" <> "x" then

arrFieldShowAs = split(Session("dbFieldShowAs" & x),",")

select case arrFieldShowAs(0) --------------------------------------

Case "FONT"
curVal = arrFieldShowAs(i+1) & curVal & "</font>"

Case "IMAGE"
for i = 1 to ubound(arrFieldShowAs) step 1
if ucase(trim(curVal)) = ucase(trim(arrFieldShowAs(i))) then curVal = "<img src=" & Quote & arrFieldShowAs(i+1) & Quote & ">"
next

Case "TEXT"
for i = 1 to ubound(arrFieldShowAs) step 2
if ucase(trim(curVal)) = ucase(trim(arrFieldShowAs(i))) then curVal = arrFieldShowAs(i+1) & curVal & "</font>"
next

Case "CONTAINS"

' To determine if a string contains a substring,
if ucase(Session("dbReplaceShowAs" & x)) = "YES" then curVal = replace(curVal," ","")

for i = 1 to ubound(arrFieldShowAs) step 2
If InStr(ucase(curVal),ucase(arrFieldShowAs(i))) <> 0 Then curVal = replace(curVal,arrFieldShowAs(i),arrFieldShowAs(i+ 1) & arrFieldShowAs(i) & "</font>")
next

Case "NOTNULL"
If curval


end select

end if
end if
Sep 28 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John | last post by:
var tmpelem; tmpelem=document.getElementById("MyTableId"); tmpelem.select(); doesnt work - any ideas how I can get around this? I only want to highlight the table and all child nodes. ...
3
by: Jay | last post by:
Hi ! I am writing a page that displays a list of records in a table. Each row for each record. Each row has a checkbox associated with it. Does anybody know how to highlight a row when I click...
1
by: john woo | last post by:
Hi I'm not good at JS, but want to get more about it. I want to use a JSP (the java code just used to get date, the rest are html and javascript), to display a table. the requirement is the...
6
by: Jim's wife | last post by:
Hi all I need to create a new table based on a source table. The new table is almost the same as the source table in that just some field names must change, and a few new fields added or...
3
by: Dabbler | last post by:
is there a way to show the header even when GridView is empty? the page looks kind of bare with just empydatatext or emptyrowtemplate. Thanks.
3
by: jmarr02s | last post by:
Hi, How do I replace with when the field is empty? Thanks! jmarr02s
4
by: rczuba | last post by:
Problem: Creating a Default Value for a field in a subform when a field in the subform & form match. I'm trying to create a payroll database for a small home business that I have that has had...
1
by: dixonjm | last post by:
Hi, I am adding a table dynamically using c# as below:- productCell = new TableCell(); KSSCheckBox checkBox = new KSSCheckBox(); checkBox.ID = string.Format("CheckBox|{0}|{1}", x,...
4
by: billa856 | last post by:
Hi, I want to know how can we set the value of Textbox = value of field in table when we select a value form combobx. example i have a table customer CID CNAME CSALARY 1 Billa ...
6
by: =?Utf-8?B?RGFu?= | last post by:
I am reposting a question from about 3 weeks ago ("sorting capability"). I have an aspx page in which I get the data from a database dynamically, through C# code, by creating a dynamic table...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.