CASE help

J

Joey Martin

I am scanning an HTML file.
I need to gather certain data from areas that start with <SMALL> text.

Let me show the code, then explain more.
----
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(TheFilePath)

Set ts = f.OpenAsTextStream(1,-2)

Section = "Header"
Do While not ts.AtEndOfStream
Tmp_Line = ts.ReadLine
Select Case mid(Tmp_Line,48,2)
Case " "
Section = "TheMoney"
Case "Pi"
Section = "ThePick"
Case ">J"
Section = "TheDate"
End Select

Select Case Section
Case "TheMoney"
TheMoney = TheMoney & FixGrades(Tmp_Line) & CHR(13)
Case "ThePick"
ThePick = ThePick & FixGrades(Tmp_Line) & CHR(13)
Case "TheDate"
TheDate = TheDate & FixGrades(Tmp_Line) & CHR(13)
End Select

TextStreamTest = TextStreamTest & CHR(13) & FixGrades(Tmp_Line)
response.write TheMoney & "<BR>"
response.write ThePick & "<BR>"
response.write TheDate & "<BR>"

Loop
ts.Close
-----------

My end result is to be able to grab TheMoney,ThePick,TheDate and then insert
them into a sql db. Then to scan more html to find the next instance of the
information and insert into database. I can do all the db stuff. The data is
just not pulling correctly. And it scans EVERY LINE instead of only the
sections that start with the HTML code <SMALL>. How would I get it to do
this? Then, do you see anything else I am doing wrong for my end result?

I'd image seeing the text with my response.write displayed as:
TheMoney
ThePick
TheDate
then scanning the html and finding another instance
TheMoney
ThePick
TheDate
etc....
 
R

Ray at

Do you know for a fact that all lines will be at least 49 characters long?
You could do something like this:


Do While not ts.AtEndOfStream
sPart = Mid(ts.ReadLine & String(49," "), 48, 2)
Select Case sPart
Case " "
TheMoney = TheMoney & FixGrades(sPart) & CHR(13)
Case "Pi"
ThePick = ThePick & FixGrades(sPart) & CHR(13)
Case ">J"
TheDate = TheDate & FixGrades(sPart) & CHR(13)
End Select

I didn't really follow exactly what your goal is, so I figured I'd just trim
down your code a little. :]

Ray at work
 
A

Aaron [SQL Server MVP]

Do While not ts.AtEndOfStream
sPart = Mid(ts.ReadLine & String(49," "), 48, 2)

No offense Ray, but whenever I see this technique, I always try to correct
it. I think the following will be much more efficient (to a certain file
size threshold, at least), since you're not keeping a handle on the file
throughout your coding logic.

s = ts.ReadAll()
ts.close: set ts = nothing
s = split(s, VBCrLf)
for i = 0 to ubound(s)
sPart = Mid(s(i) & String(49, " "), 48, 2)
...
next


There will be an upper bound to the improved efficiency, as calling
readall() on a 50 MB file is not likely to be pretty. But I think in most
cases the above is a better technique than While not AtEndOfStream.

--
http://www.aspfaq.com/
(Reverse address to reply.)




Ray at said:
Do you know for a fact that all lines will be at least 49 characters long?
You could do something like this:


Do While not ts.AtEndOfStream
sPart = Mid(ts.ReadLine & String(49," "), 48, 2)
Select Case sPart
Case " "
TheMoney = TheMoney & FixGrades(sPart) & CHR(13)
Case "Pi"
ThePick = ThePick & FixGrades(sPart) & CHR(13)
Case ">J"
TheDate = TheDate & FixGrades(sPart) & CHR(13)
End Select

I didn't really follow exactly what your goal is, so I figured I'd just trim
down your code a little. :]

Ray at work



Joey Martin said:
I am scanning an HTML file.
I need to gather certain data from areas that start with <SMALL> text.

Let me show the code, then explain more.
----
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(TheFilePath)

Set ts = f.OpenAsTextStream(1,-2)

Section = "Header"
Do While not ts.AtEndOfStream
Tmp_Line = ts.ReadLine
Select Case mid(Tmp_Line,48,2)
Case " "
Section = "TheMoney"
Case "Pi"
Section = "ThePick"
Case ">J"
Section = "TheDate"
End Select

Select Case Section
Case "TheMoney"
TheMoney = TheMoney & FixGrades(Tmp_Line) & CHR(13)
Case "ThePick"
ThePick = ThePick & FixGrades(Tmp_Line) & CHR(13)
Case "TheDate"
TheDate = TheDate & FixGrades(Tmp_Line) & CHR(13)
End Select

TextStreamTest = TextStreamTest & CHR(13) & FixGrades(Tmp_Line)
response.write TheMoney & "<BR>"
response.write ThePick & "<BR>"
response.write TheDate & "<BR>"

Loop
ts.Close
-----------

My end result is to be able to grab TheMoney,ThePick,TheDate and then insert
them into a sql db. Then to scan more html to find the next instance of the
information and insert into database. I can do all the db stuff. The
data
is
just not pulling correctly. And it scans EVERY LINE instead of only the
sections that start with the HTML code <SMALL>. How would I get it to do
this? Then, do you see anything else I am doing wrong for my end result?

I'd image seeing the text with my response.write displayed as:
TheMoney
ThePick
TheDate
then scanning the html and finding another instance
TheMoney
ThePick
TheDate
etc....
 
J

Joey Martin

Ray and Aaron,
Thanks for your input...but it still does not help me get to my end result.
I only want it to start looking at blocks of code that start with <SMALL>


Aaron said:
Do While not ts.AtEndOfStream
sPart = Mid(ts.ReadLine & String(49," "), 48, 2)

No offense Ray, but whenever I see this technique, I always try to correct
it. I think the following will be much more efficient (to a certain file
size threshold, at least), since you're not keeping a handle on the file
throughout your coding logic.

s = ts.ReadAll()
ts.close: set ts = nothing
s = split(s, VBCrLf)
for i = 0 to ubound(s)
sPart = Mid(s(i) & String(49, " "), 48, 2)
...
next


There will be an upper bound to the improved efficiency, as calling
readall() on a 50 MB file is not likely to be pretty. But I think in most
cases the above is a better technique than While not AtEndOfStream.

--
http://www.aspfaq.com/
(Reverse address to reply.)




Ray at said:
Do you know for a fact that all lines will be at least 49 characters long?
You could do something like this:


Do While not ts.AtEndOfStream
sPart = Mid(ts.ReadLine & String(49," "), 48, 2)
Select Case sPart
Case " "
TheMoney = TheMoney & FixGrades(sPart) & CHR(13)
Case "Pi"
ThePick = ThePick & FixGrades(sPart) & CHR(13)
Case ">J"
TheDate = TheDate & FixGrades(sPart) & CHR(13)
End Select

I didn't really follow exactly what your goal is, so I figured I'd just trim
down your code a little. :]

Ray at work



Joey Martin said:
I am scanning an HTML file.
I need to gather certain data from areas that start with <SMALL> text.

Let me show the code, then explain more.
----
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(TheFilePath)

Set ts = f.OpenAsTextStream(1,-2)

Section = "Header"
Do While not ts.AtEndOfStream
Tmp_Line = ts.ReadLine
Select Case mid(Tmp_Line,48,2)
Case " "
Section = "TheMoney"
Case "Pi"
Section = "ThePick"
Case ">J"
Section = "TheDate"
End Select

Select Case Section
Case "TheMoney"
TheMoney = TheMoney & FixGrades(Tmp_Line) & CHR(13)
Case "ThePick"
ThePick = ThePick & FixGrades(Tmp_Line) & CHR(13)
Case "TheDate"
TheDate = TheDate & FixGrades(Tmp_Line) & CHR(13)
End Select

TextStreamTest = TextStreamTest & CHR(13) & FixGrades(Tmp_Line)
response.write TheMoney & "<BR>"
response.write ThePick & "<BR>"
response.write TheDate & "<BR>"

Loop
ts.Close
of
the
information and insert into database. I can do all the db stuff. The
data
is
just not pulling correctly. And it scans EVERY LINE instead of only the
sections that start with the HTML code <SMALL>. How would I get it to do
this? Then, do you see anything else I am doing wrong for my end result?

I'd image seeing the text with my response.write displayed as:
TheMoney
ThePick
TheDate
then scanning the html and finding another instance
TheMoney
ThePick
TheDate
etc....
 
R

Ray at

Joey Martin said:
Ray and Aaron,
Thanks for your input...but it still does not help me get to my end result.
I only want it to start looking at blocks of code that start with <SMALL>


Blocks of code? Lines in the file? Can you post a snippet from a sample
file that you're reading or something so we can try to understand what
you're trying to do?

Ray at work
 
J

Joey Martin

Here is a sample of the file I am importing:

<small>
<TR>
<TD ALIGN="right" BGCOLOR="FFFFFF"><small> $4,962</small></TD>
<TD BGCOLOR="FFFFFF" ALIGN="CENTER"><small>Pick 6</small></TD>

<TD BGCOLOR="FFFFFF" ALIGN="CENTER"><small>Hastings</small></TD>
<TD BGCOLOR="FFFFFF" ALIGN="CENTER"><small>June 12, 2004</small></td>
</tr></small>


There is additional html before the first <small> that I want to ignore. I
pretty much want to bring in each piece of information that is within that
block of text minus the html codes, for each INSTANCE of that section that
appears.

Thanks for the help!
 
R

Ray at

This probably isn't the best method around, as they're may be a better way
using regular expressions and what not, but it will give basic
functionality.


Function SuckSmall(theLine)
Dim iStart, iEnd
SuckSmall = ""
iStart = InStr(1, theLine, "<small>", 1)
If iStart = 0 Then Exit Function
iEnd = InStr(iStart, theLine, "</small>", 1)
If iEnd = 0 Then Exit Function
SuckSmall = Mid(theLine, iStart + 7, iEnd - iStart - 7)
''''7 is the length of "<small>" which is where the iStart will be
End Function


''(see Aaron's post)
s = ts.ReadAll()
ts.close: set ts = nothing
s = split(s, VBCrLf)
for i = 0 to ubound(s)
sData = SuckSmall(s(i))
If sData <> "" Then Response.write sData & "<br>"
next


Ray at work
 
A

Aaron [SQL Server MVP]

Sheesh, why don't you store information in a database instead of a text
file?

Or have you considered using CSS, and some kind of marker to indicate a
valid data row? Imagine how much easier it would be if you had this:

<crap HTML we don't care about>blah</crap>
<TR>
<!-- start -->
<TD Class=right>$4,962</TD>
<TD Class=mid>Pick 6</TD>
<TD Class=mid>Hastings</TD>
<TD Class=mid>June 12, 2004</TD>
<!-- end -->
</TR>
<TR>
<!-- start -->
<TD Class=right>$200</TD>
<TD Class=mid>Pick 4</TD>
<TD Class=mid>New York</TD>
<TD Class=mid>June 18, 2004</TD>
<!-- end -->
</TR>

Anyway, I won't produce the code for that, because the typical response is
"pointy-haired boss won't let me change the format of the file." So,

....

s = ts.ReadAll()
ts.close: set ts = nothing

s = split(s, VBCrLf)
for i = 0 to ubound(s)
s(i) = trim(s(i))
bg = instr(s(i), "BGCOLOR")
s1 = instr(s(i), "<small>")
s2 = instr(s(i), "</small>")
if s1 = 1 then response.write "-------<br>"
if bg > 0 then
if s1 > bg and s2 > s1 then
response.write mid(s(i), s1+7, s2-(s1+7))
response.write "<br>"
end if
end if
next
response.write "-------<br>"
 
J

Joey Martin

Wow...that was perfect...I know the first thing I was doing wrong was the
use of the INSTR function.

Anyways...thanks so much!
 
J

Joey Martin

Hmmm....trying to figure out how to insert each block into database field,
themoney,thepick,thetrack,thedate
 
J

Joey Martin

Your code returns the following:

$8,394
Pick 6
Bay Meadows
June 10, 2004
-------
$7,496
Pick 6
Los Alamitos
June 10, 2004

I would like to enter the 1st grouping into a db table called co_results.
line 1 is TheMoney field, line 2 is ThePick field, line 3 is TheTrack field,
and line 4 is TheDate field.

Then go to the next grouping and insert a new row of data. And on and on....
 
J

Joey Martin

Columns...
TheMoney
ThePick
TheTrack
TheDate

Aaron said:
Now, does co_results have any specific data structure? Just one column?
What is the column called?
 
A

Aaron [SQL Server MVP]

What the heck purpose does the "The" prefix serve? Also, what are the
datatypes (is TheMoney a money datatype, a string... is TheDate a datetime,
a string, ...)?

--
http://www.aspfaq.com/
(Reverse address to reply.)
 
A

Aaron [SQL Server MVP]

Thanks. It is much easier to create a solution when we have actual
specifications!


s = ts.ReadAll()
ts.close: set ts = nothing

prefix = "INSERT co_results(TheMoney, The Pick, TheTrack, TheDate) SELECT "

s = split(s, VBCrLf)
for i = 0 to ubound(s)
s(i) = trim(s(i))
bg = instr(s(i), "BGCOLOR")
s1 = instr(s(i), "<small>")
s2 = instr(s(i), "</small>")
if s1 = 1 then sql = prefix: c = 0
if bg > 0 then
if s1 > bg and s2 > s1 then
c = c + 1
data = mid(s(i), s1+7, s2-(s1+7))
if c > 1 then data = ",'" & replace(data, "'", "''") & "'"
sql = sql & data
end if
end if
if c = 4 then response.write(sql) & "<br>": c = 0
next



If you're happy with the results, change response.write to conn.execute.
And consider demanding that this information come to you in a more usable
way.



--
http://www.aspfaq.com/
(Reverse address to reply.)
 
J

Joey Martin

Aaron,

Where does the 7 come into play?
I downloaded a new copy of the file I am using this code against and each
section is moved over 3 tab spaces.

Old copy:
<small>
<TR>
<TD ALIGN="right" BGCOLOR="82B0A0"><small> $16,102</small></TD>
<TD BGCOLOR="82B0A0" ALIGN="CENTER"><small>Tri Super</small></TD>

<TD BGCOLOR="82B0A0" ALIGN="CENTER"><small>Ruidoso Downs</small></TD>
<TD BGCOLOR="82B0A0" ALIGN="CENTER"><small>June 10, 2004</small></td>

<TD BGCOLOR="FFFFFF" ALIGN="CENTER"><A
HREF="eebMultipleProductPurchase.cfm?track_id=RUI"><IMG
SRC="images/buyproducts.gif" BORDER="0"></A></TD>


</TR></small>


New copy is exactly the same except the whole block is moved over 3 tabs and
the code is no longer bringing it in correctly. I'm hoping the 7 has to do
with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with code 0
Help with my responsive home page 2
Collect Excel Data from Website 5
Idk need help in editing this source code 0
ASP FileSystem Object 9
Serious help needed - Calendar! 7
ADD RECORDS 14
Error 7

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top