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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TDC (Tabular Data Control) Filters 1

Status
Not open for further replies.

DreamerZ

Programmer
Jul 11, 2001
254
US
Can anyone who knows TDC well enough tell me if the filter param supports variables or just exact numbers?

I have read nearly everything on TDC at MSDN and can't get a variable filter to work. Exact numbers work fine (i.e. filter value=&quot;Date < 4/25/2003&quot;). A variable does not (i.e. loggedDate=4/25/2003, filter value=&quot;Date < loggedDate&quot;)

Am I missing a quote or other symbol to get the variables to work?

Oh, I'm using TDC currently because it's easy to setup for what I need.

TIA

DreamerZ
 
Oh dear. You want to filter on date values in the TDC using the Filter property. And you want to set it at run-time.


To set the Filter at run-time to a variable value you must do it in script, not in the <param> tag. Leave that <param> out altogether.

But there is only one way to make Filter reliable for anything but simple strings and numbers. You must set the UseHeader property to True and use a header record in your CSV file that defines the fields and types. The typing of dates as... dates is critical.

Luckily, you may have already been doing this. I see you give an example of a Filter string &quot;Date < 4/25/2003&quot; so I have hope. Otherwise the string would look more like &quot;Column1 < 4/25/2003&quot; (TDC's default pattern for column names).

If you don't &quot;type&quot; the columns/fields in the header record, they'll all be strings. Relative magnitude comparisons become worthless using U.S. date formats and possibly suppressed leading zeros. I mean, is the &quot;date&quot; 03/01/1950 less than 3/1/1940 if these are compared as strings? Yep.

As you will recall, your header needs to look something like:
Code:
LastName:String,FirstName:String,BirthDate:Date
This defines three fields by name and type.

Ok.

So now your variable. Does it contain a variant string or a variant date? For a variant string use:
Code:
objTDC.Filter = &quot;BirthDate < &quot; & loggedDate
objTDC.Reset
For a variant date use:
Code:
objTDC.Filter = &quot;BirthDate < &quot; & FormatDateTime(loggedDate, vbShortDate)
objTDC.Reset
Note: This can be unreliable if somebody has set the computer's short-date format to something wacky. You can also use:
Code:
objTDC.Filter = &quot;BirthDate < &quot; & CStr(DatePart(loggedDate, &quot;m&quot;)) _
                         & &quot;/&quot; & CStr(DatePart(loggedDate, &quot;d&quot;)) _
                         & &quot;/&quot; & CStr(DatePart(loggedDate, &quot;yyyy&quot;))
objTDC.Reset
This of course all assumes the Locale setting on the computer is en-us or in some places 1033 depending on how you go about setting it.

Because the header defined BirthDate as a date-typed column, the converted-to-a-string variable value will be parsed as a date and you don't have to worry about leading zeros being there or not.

BTW: Don't use:
Code:
objTDC.Filter = &quot;BirthDate < &quot; & CStr(loggedDate)
objTDC.Reset
This will get you in trouble if there is a time part in the variable (a variant date is really a variant date & time value).

Also avoid trying:
Code:
objTDC.Filter = &quot;BirthDate < #&quot; & CStr(loggedDate) & &quot;#&quot;
objTDC.Reset
The TDC has no idea about the VB syntax for date literals. This will mess you up good.

Note the use of the Reset method after setting the Filter. Very important.

Also not that while an ADO Recordset's Filter property uses And and Or, the TDC's Filter property uses & and | respectively in complex filter expressions.


Hmm...

I guess the short answer to your direct question is &quot;Nope. You cannot use variables in the param tag.&quot; Script is not executed at the time tag attribute values are parsed. But there is a workaround, as shown here.

I hope this helps.
 
Okay, first dilettante, you get a star for this post. I didn't know if what I wanted was even possible, but with your code it appears that it is.

I have added the script that you've shown, but I might still be doing something wrong. While I'm not getting errors, the filter still doesn't work. Here is the full vb script:

<SCRIPT LANGUAGE=VBSCRIPT>
<!--
objTDC.Filter=&quot;FlashDate < &quot; & FormatDateTime(loggedDate, vbShortDate)
objTDC.Reset()

function FlashDate_onclick()
flashes.Sort = &quot;+FlashDate&quot;
flashes.Reset()
end function

function FlashName_onclick()
flashes.Sort = &quot;+FlashName&quot;
flashes.Reset()
end function

// -->
</script>

This script is in the <HEAD> section of the page. Also below is a sample of my txt file being used for the TDC:
Header--&quot;FlashID:Number&quot;,&quot;FlashDate:Date&quot;,&quot;FlashName:String&quot;
3,4/24/2003,&quot;<a href=&quot;&quot;>4/24/03</a>&quot;
4,4/25/2003,&quot;<a href=&quot;&quot;>4/25/03</a>&quot;
5, 4/29/2003,&quot;<a href=&quot;&quot;>4/29/03</a>&quot;

I've also include all the TDC code:
<object id=&quot;flashes&quot; classid=&quot;clsid:333C7BC4-460F-11D0-BC04-0080C7055A83&quot; width=&quot;96&quot; height=&quot;13&quot;>
<param name=&quot;RowDelim&quot; value=&quot;&quot;>
<param name=&quot;FieldDelim&quot; value=&quot;,&quot;>
<param name=&quot;TextQualifier&quot; value=&quot;&quot;&quot;>
<param name=&quot;EscapeChar&quot; value>
<param name=&quot;UseHeader&quot; value=&quot;True&quot;>
<param name=&quot;SortAscending&quot; value=&quot;-1&quot;>
<param name=&quot;SortColumn&quot; value>
<param name=&quot;FilterValue&quot; value>
<param name=&quot;FilterCriterion&quot; value=&quot;??&quot;>
<param name=&quot;FilterColumn&quot; value>
<param name=&quot;CharSet&quot; value>
<param name=&quot;Language&quot; value>
<param name=&quot;CaseSensitive&quot; value=&quot;-1&quot;>
<param name=&quot;Sort&quot; value=&quot;-FlashDate&quot;>
<param name=&quot;Filter&quot; value>
<param name=&quot;AppendData&quot; value=&quot;0&quot;>
<param name=&quot;DataURL&quot; value=&quot;PrintFlashes.txt&quot;>
<param name=&quot;ReadyState&quot; value=&quot;4&quot;>
</object>

<table datasrc=#flashes border=1>
<thead><tr>
<td width=&quot;25%&quot; align=&quot;center&quot;><div id=&quot;FlashDate&quot;><b><u><font size=4 color=&quot;blue&quot;>Flash Date</div></td>
<td width=&quot;75%&quot; align=&quot;center&quot;><div id=&quot;FlashName&quot;><b><u><font size=4 color=&quot;blue&quot;>Flash Name</div></td>
</tr></thead>
<tbody>
<col
<tr>
<td width=&quot;25%&quot;><font size=4><div datafld=&quot;FlashDate&quot;></div></td>
<td width=&quot;75%&quot;><font size=4><div datafld=&quot;FlashName&quot; DATAFORMATAS=&quot;HTML&quot;></div></td>
</tr></tbody></table>


The only thing I can think of is I am not setting the loggedDate variable properly. It's being set in JavaScript earlier in the <HEAD> section. Would that cause the filter not to work?

I'm at a loss here. This is over my head. Thx for all and any more help you can give.

DreamerZ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top