I have a program which takes the html from a web page, removes the formatting and leaves a list of conjugations for the verb. A sample of the result is here:
Barrer : sweep
*present indicative
Yo barro
Tú barres
Él/usted barre
Nosotros barremos
Vosotros barréis
Ellos/ustedes barren
*Imperfect:
Yo barría
Tú barrías
Él/usted barría
Nosotros barríamos
Vostros barríais
Ellos/ustedes barrían
*preterite:
Yo barrí
Etc . . .
etc . . .
I entered the "*"s because I want to ignore them when I write them to the database.
It starts off fine with the first record "barrer : sweep"
for the second record (the first one encountered which needs to be ignored), iPos is 1, sFirst is "*" and it executes the code in CASE "*"
so far so good.
It also works fine for the next 6 lines that I need and adds them to the database record.
The problem comes with "*Imperfect:"
iPos = 3, sItem = "" and sFirst = "".
The same happens with every line from then on which starts with "*" and iPos =3 for all of them.
WHY 3!!!!!!
What am I missing?
PLEASE HELP This is driving me batty!
Code:Option Explicit Private cn As ADODB.Connection Private rs As ADODB.Recordset Private sHTML As String Private sItem() As StringCode:Private Sub LoadDatabase() Dim strConn As String Dim iBasePtr As Integer Dim iLoopCtr As Integer Dim sFirst As String Dim iPos As Integer Set cn = New ADODB.Connection ' strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\hp\Documents\VBProgs\Get From Web\SpanishVerbs.mdb;Persist Security Info=False" cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\hp\Documents\VBProgs\Get From Web\SpanishVerbs.mdb;Persist Security Info=False" Set rs = New ADODB.Recordset rs.Open "verblist", cn, adOpenKeyset, adLockPessimistic, adCmdTable rs.AddNew 'adding new record 'here we need two counts so that when we encounter a field with a * at the beginning 'it doesn't add it to the database iBasePtr = 1 For iLoopCtr = 0 To UBound(sItem) iPos = InStr(1, sItem(iLoopCtr), "*", vbTextCompare) If iPos > 1 Then sItem(iLoopCtr) = Left(sItem(iLoopCtr), iPos - 1) End If sFirst = Left(sItem(iLoopCtr), 1) Select Case sFirst Case "*" iBasePtr = iBasePtr 'do nothing and DONT increase iBaseCtr Case Else rs.Fields(iBasePtr).Value = sItem(iLoopCtr) iBasePtr = iBasePtr + 1 End Select Next iLoopCtr rs.Update 'this updates the recordset rs.Close Set rs = Nothing Set cn = Nothing End Sub




Reply With Quote