Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change colour of font it right 2 characters = "06" 2

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi I am trying to change the font of a recordset value based on the value of the right 2 characters.

I have tried using thsi code but obviously it does not work, can someone point me in the right direction please

Code:
<td><%if Right(rsDebt.fields.item("RevisionMAP").value, 2,"06") then%>
          <font color="#FF0000"><strong><%=(rsDebt.Fields.Item("RevisionMAP").Value)%></strong></font>
          <%else%>
          <font color="#000000"><%=(rsDebt.Fields.Item("RevisionMAP").Value)%></font>
          <%end if%></td>

Regards

Paul

 
I'd do something along these lines:

Code:
<%

If Right(rsDebt.fields.item("RevisionMAP").value, 2) = "06" Then
    strColor = "#FF0000"
Else
    strcolor = "#000000"
End If

%>

<td><font color="<%= strColor %>"><strong><%= rsDebt.Fields.Item("RevisionMAP").Value %></strong></font>
</td>

%>



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I'm not from VBScript but I think this should work

Code:
><%if (Right(rsDebt.fields.item("RevisionMAP").value, 2) = "06") then%>

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
Thanks for your posts guys, I was still working on it after posting the question and came up with something very similar to both of you

Code:
<td><%if (Right(rsDebt.fields.item("RevisionMAP"), 2)="06") then%>
          <font color="#FF0000"><strong><%=(rsDebt.Fields.Item("RevisionMAP").Value)%></strong></font>
          <%else%>
          <font color="#000000"><%=(rsDebt.Fields.Item("RevisionMAP").Value)%></font>
          <%end if%></td>
      <td><%=(rsDebt.Fields.Item("RevisionSOP_ESP").Value)%></td>

"Stars" on their way

Regards

Paul

 
Well if I were being very specific and picky, I'd write it like this:
Code:
<%
If Right(rsDebt.fields.item("RevisionMAP").value, 2) = "06" Then
    strColor = "#ff0000"
Else
    strcolor = "#000000"
End If
%>
<td><strong style="color:<%=strColor%>"><%=rsDebt.Fields.Item("RevisionMAP").Value%></strong>
</td>

I'd use a terniary operator, but I'm not sure of the syntax with VBScript.

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
Since we're playing, "my code is smaller than your code". How about this...

Code:
<%
If Right(rsDebt.fields.item("RevisionMAP").value, 2) = "06" Then
    strColor = "color: #ff0000; font-weight:bold;"
Else
    strcolor = "color: #000000; font-weight:normal;"
End If
%>
<td style="<% =strcolor%>"><%=rsDebt.Fields.Item("RevisionMAP").Value%></td>

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
HMMMMM George, font-weight:bold and <strong> aren't quite the same [pipe]

and with my terniary operator my code could be on one line SO THEREEEEEEEEE!!


[neutral]

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
OK. My ASP skills aren't the greatest. So, can you explain to me the difference between font-weight:bold and strong?



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
First off, my bad, it's TERNARY operator.

Second, no I can't explain the difference in visual output.
So I'm going to go to a corner now and cry.



[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
hmmmm....

Code:
Dim str : str = "106234567068964506312378606"
Set Reg = New RegExp
Reg.Pattern = "06$"

str = Reg.Replace(str,"<font color=""#FF0000""><strong>06</strong></font>")
Response.Write(str)

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
I'm not sure how good it will sound but Mines shorter ;-)

and more reusable and less redundant and.....[lol]

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
BTW...kiwieur

I recommend regex for this task for a few reasons (some noted above)

BUT if you go that way you have to code the pattern to handle some dirty data (as some call it). A good example would be a white space. The $ states the string will have to occur at the end of the string in simply terms. So it has to! So if you have "06 " then that pattern fails. A easy way around that would be the \s which will match white space. so "06\s{0,}$" that up nicely. Point I'm trying to make I guess is the power is in regex in string manipulation and even knowing there is a cost on the object creation you are going to gain speed over vast amounts of endless validating and conditional statements because when you code for the user you have to catch it all and that can get very long winded and hard to maintain.

So try RegEx. You'll never turn back

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
As monksnake admitted to being picky, I might as well be too and point out that font tags shouldn't be used either (the styling should be done via CSS). [smile]


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hey Guys,

did not realise my question would open up so much debate, as you are probably aware from my initial question i am really an asp novice [ponder].

Thank you all for your input unforunately onpnt i do not fully understand your explanation but, i will do some research and try to understand

Regards

Paul

 
ok. Just remember you'll be a novice as long as you allow yourself to be one ;-)

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top