-
March 13th, 2010, 03:12 AM
#16
Re: Recordset Counting problem
Originally Posted by DataMiser
Actually you would need to use the class name as well since your linessent variable is part of a class and is public.
Code:
NewCount=Count-MyClass.LinesSent
Right, and I tried that and I still get the object error. the class name is SearchResult
-
March 13th, 2010, 05:08 AM
#17
Re: Recordset Counting problem
You better post the code where this line is. Best the entire sub. Else I can only guess.
You never use the name of a class to address one of its public variables. You always must have an object of a class to use its properties (variables).
Only from within the class you can use the classname or the keyword Me to refer to the runtime object of the class.
If it is a missing object you might have made a mistake with the scope of that object variable.
-
March 13th, 2010, 10:23 AM
#18
Re: Recordset Counting problem
I guess my post was not clear. When I said name of the class I meant the Declared Name.
Public MyClass as New TheClassWeAreUsing
Then later we could call MyClass.Variable
-
March 13th, 2010, 11:32 AM
#19
Re: Recordset Counting problem
Originally Posted by WoF
You better post the code where this line is. Best the entire sub. Else I can only guess.
You never use the name of a class to address one of its public variables. You always must have an object of a class to use its properties (variables).
Only from within the class you can use the classname or the keyword Me to refer to the runtime object of the class.
If it is a missing object you might have made a mistake with the scope of that object variable.
Here is the SearchResult Class Module
Code:
Private Lines() As String
Public LinesCount As Integer
Public LinesLeft As Integer
Public LinesSent As Integer
Private colSearches As New Collection
Public Sub Add(NewLine As String)
ReDim Preserve Lines(LinesCount)
Lines(LinesCount) = NewLine
LinesCount = LinesCount + 1
End Sub
Public Property Get NextLine() As String
If LinesSent < LinesCount Then
NextLine = Lines(LinesSent)
LinesSent = LinesSent + 1
LinesLeft = LinesCount - LinesSent
Else
NextLine = "End of Results. Please Type $stop to Clear Your Search" + vbCrLf
LinesSent = LinesCount
End If
End Property
This is the SendMore Sub that is called from the More Sub:
Code:
Private Sub SendMore(UserName As String, NumLines As Integer)
Dim r$, i%
Dim a$, sr As SearchResult
If UserName = "" Then Exit Sub
On Error GoTo NoResultsForThisUserName
Set sr = colSearches(UserName)
For i = 1 To NumLines
a$ = sr.NextLine
r$ = r$ + a$ + " $$ "
If InStr(a$, "End of Results.") = 1 Then Exit For
Next
RichTextBox1.Text = r$
NoResultsForThisUserName:
Exit Sub
End Sub
And here is the More Sub
Code:
Private Sub MoreVer()
Dim iHnd As Long
iHnd = getPalSubForm(WindowClass, Combo1.Text, RoomOutboundTextBoxClass, SendTxtIndex)
iHnd = SendTextHnd
Dim u$
If colSearches.Count = 0 Then
RTB5 = Text1.Text & ": You Dont Have Any More Search Results To Display."
RTB5.SelLength = Len(RTB5.Text)
With RTB5
.SelBold = True
.SelFontSize = 10
.SelColor = RGB(101, 0, 192)
End With
Call SendMessageByString(iHnd, WM_SETTEXT, 0&, RTB5)
Call SendMessage(iHnd, WM_KEYDOWN, 13, 0)
Exit Sub
Else
End If
u$ = Text1.Text
If u$ <> "" Then SendMore u$, 10
RTB5 = Text1.Text & " Your Keyword or Phrase Search Results Are: " & Count & " Verse(s) " & RichTextBox1.Text & " Type $more for more results, "
RTB5.SelLength = Len(RTB5.Text)
With RTB5
.SelBold = True
.SelFontSize = 8
.SelColor = RGB(101, 0, 192)
End With
Call SendMessageByString(iHnd, WM_SETTEXT, 0&, RTB5)
Call SendMessage(iHnd, WM_KEYDOWN, 13, 0)
RichTextBox1.Text = ""
End Sub
I was origionally going to ask if you all would need to see the Keyword Search sub but I think I will just post it.
Code:
Private Sub KeyWordSearch()
Dim SQLStr, sString, UserName As String
Dim sPath As String
Dim Counter As Long
Dim tmpStr As String
Dim Count As Integer
Dim iHnd As Long
iHnd = getPalSubForm(WindowClass, Combo1.Text, RoomOutboundTextBoxClass, SendTxtIndex)
iHnd = SendTextHnd
Trigger = "$key"
On Error GoTo KeyWordError
cmdPos = InStr(1, RichTextBox2.Text, Trigger, vbBinaryCompare)
If cmdPos = 0 Then Exit Sub
cmdVer = Trim$(Right$(RichTextBox2.Text, (Len(RichTextBox2.Text) - cmdPos) - 4))
RichTextBox4.Text = Right(cmdVer, Len(cmdVer))
sString = RichTextBox4.Text
SQLStr = "Select tblBook.*,tblQUOTE.* From tblBook,tblQUOTE Where (tblQUOTE.Quote Like '%" & sString & "%') And tblBook.Book_ID=tblQUOTE.Book_ID Order by tblQUOTE.Book_ID,tblQUOTE.Chapter ASC"
Dim db1 As Connection
Set db1 = New Connection
db1.CursorLocation = adUseClient
sPath = App.Path & "\kjvbible.mdb"
db1.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath
Set adoPrimaryRS1 = New Recordset
Set adoPrimaryRS1 = db1.Execute(SQLStr, , adCmdText)
Dim sr As New SearchResult
Dim a$
UserName = Text1.Text
colSearches.Add sr, UserName
While Not adoPrimaryRS1.EOF
tmpStr = adoPrimaryRS1!Book_Title & " " & adoPrimaryRS1!Chapter & ":" & adoPrimaryRS1!Verse
a$ = tmpStr
sr.Add a$
adoPrimaryRS1.MoveNext
RichTextBox1.Text = RichTextBox1.Text & tmpStr & " $$ "
Wend
Count = sr.LinesCount
If Count > 12 Then
Call SendMore((Text1.Text), 10)
RTB5 = Text1.Text & " Your Keyword or Phrase Search Results Are: " & Count & " Verse(s) " & RichTextBox1.Text & " Type $more For More Results "
RTB5.SelLength = Len(RTB5.Text)
With RTB5
.SelBold = True
.SelFontSize = 8
.SelColor = RGB(101, 0, 192)
End With
Call SendMessageByString(iHnd, WM_SETTEXT, 0&, RTB5)
Call SendMessage(iHnd, WM_KEYDOWN, 13, 0)
' Close RecordSet and Database
adoPrimaryRS1.Close
db1.Close
RTB5 = ""
Trigger = ""
RichTextBox1.Text = ""
RichTextBox2.Text = ""
RichTextBox4.Text = ""
Exit Sub
Else
End If
Count = sr.LinesLeft
RTB5 = Text1.Text & " Your Keyword or Phrase Search Results Are: " & Count & " Verse(s) " & RichTextBox1.Text
RTB5.SelLength = Len(RTB5.Text)
With RTB5
.SelBold = True
.SelFontSize = 8
.SelColor = RGB(101, 0, 192)
End With
Call SendMessageByString(iHnd, WM_SETTEXT, 0&, RTB5)
Call SendMessage(iHnd, WM_KEYDOWN, 13, 0)
Close Recordset And Database
adoPrimaryRS1.Close
db1.Close
RTB5 = ""
Trigger = ""
RichTextBox1.Text = ""
RichTextBox2.Text = ""
RichTextBox4.Text = ""
Exit Sub
KeyWordError:
RTB5 = Text1.Text & ": You Have A Search Pending and Cannot do Another Search. Please Type $more for Additional Results or $stop to Clear Your Search"
RTB5.SelLength = Len(RTB5.Text)
With RTB5
.SelBold = True
.SelFontSize = 10
.SelColor = RGB(101, 0, 192)
End With
Call SendMessageByString(iHnd, WM_SETTEXT, 0&, RTB5)
Call SendMessage(iHnd, WM_KEYDOWN, 13, 0)
' Close RecordSet and Database
adoPrimaryRS1.Close
db1.Close
RTB5 = ""
Trigger = ""
RichTextBox1.Text = ""
RichTextBox2.Text = ""
RichTextBox4.Text = ""
Exit Sub
End Sub
Last edited by intercepter; March 13th, 2010 at 11:39 AM.
-
March 13th, 2010, 05:34 PM
#20
Re: Recordset Counting problem
Look at this, for a better way?
Code:
Option Explicit
' Add a reference to Riched20.dll. Browse for it!
' This will select TOM. You only need to do this once!
'
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400&
Private Const EM_GETOLEINTERFACE = (WM_USER + 60)
Dim tomDoc As ITextDocument
Private Enum Direction
Forward = 1
Backward = -1
End Enum
Private Sub Command1_Click()
RTFindText Text1.Text, Forward
End Sub
Private Sub Command2_Click()
RTFindText Text1.Text, Backward
End Sub
' All the hard work done here
Private Sub RTFindText(strText As String, Optional RequiredDirection As Direction = Forward)
Dim flags As Long
flags = 2 * Check1 + 4 * Check2 ' + 8 * Check3 sadly, RegExp functionality is not available on a RichTextBox
tomDoc.Selection.FindText Text1.Text, RequiredDirection * tomDoc.Selection.StoryLength, flags
End Sub
Private Sub Form_Load()
Dim myIUnknown As IUnknown ' Bet you didn't know that VB actually knows about IUnknown ...
' Get alternative TOM interface to RTB
SendMessage RichTextBox1.hwnd, EM_GETOLEINTERFACE, 0&, myIUnknown
Set tomDoc = myIUnknown ' We're doing a QueryInterface!
' Ok, set up our RTB with some text
RichTextBox1.Text = "hello and Hello and hEllo or hello with another hello just for luck saying hello there"
RichTextBox1.HideSelection = False 'Always show highlight, whether RTB has focus or not
Text1.Text = "Hello" ' Default word to search for
Command1.Caption = "Find Next"
Command2.Caption = "Find Previous"
Check1.Caption = "Whole word"
Check2.Caption = "Case"
' Check3.Caption = "RegExp" 'Sadly RegExp functionality is not available on a RichTextBox
End Sub
I just EDITED an app, using .Find, and then Replacing text, and formatting it
-
March 13th, 2010, 08:44 PM
#21
Re: Recordset Counting problem
-
March 14th, 2010, 01:01 AM
#22
Re: Recordset Counting problem
Ok, from the beginning.
The scope is this: I can generate a recordset collection based on which user (which could be a number of them) requests this search be done. I can in the first initial go around do a count on the resulting recordset and find out how many items are listed in the recordset. I can only send out 10 to 12 at a time. So, to just make it easier, i chose 10 records to display. The subs I posted get the information fine, they assemble them and allow me to send the first group formatted properly fine. They are also counting fine the first go around. But if there are more than 12 then I have set up a function to go get the next 10 out of the recordset. I also want to give the user an expectation of how many records matched their request. And show whats left each time the user takes out another 10 to look at. I just want to count whats left in that recordset and display it.
I am wondering now if maybe I should put sendmore and more together as one big sub?
-
March 14th, 2010, 07:05 AM
#23
Re: Recordset Counting problem
I have read all your posted subs.
The KeyWordSearch() walks through all the records of the set and puts the matching records in the collection object of type SearchResult()
Inspecting the Class SearchResult, it provides a property which returns the next line, keeping a counter which line was read last.
The SendMore() will read NumLines lines from the SearchResult object and put them in an rtb for display.
So far everything seems quite comprehensive and I'd suppose it'd work properly.
You said, the first ten lines come in ok, then the count would not anymore go down...
I'd suggest: add a property to the SearchResult class, which returns the total number of lines in the collection and another one which is the number of lines waiting (being LinesCount - LinesSent)
As we suspect some error there, we might derive the total number of lines from colSearches.Count.
As I say, from theory everything looks as if it should work. I cannot spot any bug, mistake or logical error there. The only chance of finding out now is debugging in single steps.
-
March 14th, 2010, 12:41 PM
#24
Re: Recordset Counting problem
I spent some minutes to make a little testing program.
I implemented the SearchResultClass as posted, and used a Form for a testing code.
I use a textbox txtMore and a button btnMore, which calls the SendMore() sub.
In Form_Load() I create a dummy search result.
The textbox shows exactly what is expected.
Code:
Option Explicit
Private colSearches As New Collection
Private Sub SendMore(UserName As String, NumLines As Integer)
Dim r$, i%
Dim a$, sr As SearchResult
If UserName = "" Then Exit Sub
'On Error GoTo NoResultsForThisUserName
Set sr = colSearches(UserName)
For i = 1 To NumLines
a$ = sr.NextLine
r$ = r$ + a$ + " $$ "
If InStr(a$, "End of Results.") = 1 Then Exit For
Next
txtResult.Text = r$
NoResultsForThisUserName:
Exit Sub
End Sub
Private Sub btnMore_Click()
SendMore "Wof", 10
End Sub
Private Sub Form_Load()
Dim sr As New SearchResult
Dim i%
For i = 1 To 72
sr.Add "Search result No. " + Format(i, "000") + vbCrLf
Next
colSearches.Add sr, "Wof"
End Sub
The error must lie elsewhere. Repeated calls to SendMore moves the read-pointer up until all lines were sent. Works perfectly.
-
March 14th, 2010, 12:48 PM
#25
Re: Recordset Counting problem
And the funny thing is I overlooked one thing that maybe the root of my problem. I kept trying to use the values in the class module SearchResult. Saying object required.
So I added this to my more sub:
Code:
Dim sr As SearchResult
Set sr = colSearches(Text1.Text)
So now I can access all the values in SearchResult.
Going to now try a new sub and report back.
-
March 14th, 2010, 01:02 PM
#26
Re: Recordset Counting problem
And this is the resulting sub that works now:
Code:
Private Sub MoreVer()
Dim iHnd As Long
iHnd = getPalSubForm(WindowClass, Combo1.Text, RoomOutboundTextBoxClass, SendTxtIndex)
iHnd = SendTextHnd
Dim sr As SearchResult
Set sr = colSearches(Text1.Text)
Dim tempCount As String
Dim u$
If colSearches.Count = 0 Then
RTB5 = Text1.Text & ": You Dont Have Any More Search Results To Display."
RTB5.SelLength = Len(RTB5.Text)
With RTB5
.SelBold = True
.SelFontSize = 10
.SelColor = RGB(101, 0, 192)
End With
Call SendMessageByString(iHnd, WM_SETTEXT, 0&, RTB5)
Call SendMessage(iHnd, WM_KEYDOWN, 13, 0)
Exit Sub
Else
End If
tempCount = sr.LinesLeft
u$ = Text1.Text
If u$ <> "" Then SendMore u$, 10
RTB5 = Text1.Text & " Your Keyword or Phrase Search Results Are: " & tempCount & " Verse(s) " & RichTextBox1.Text & " Type $more for more results, "
RTB5.SelLength = Len(RTB5.Text)
With RTB5
.SelBold = True
.SelFontSize = 8
.SelColor = RGB(101, 0, 192)
End With
Call SendMessageByString(iHnd, WM_SETTEXT, 0&, RTB5)
Call SendMessage(iHnd, WM_KEYDOWN, 13, 0)
RichTextBox1.Text = ""
End Sub
-
March 14th, 2010, 02:20 PM
#27
Re: Recordset Counting problem
Congrats on figuring it out. I've been following along and kind of busy with my own project. I've learned a thing or two from this dialog as well.
-
March 14th, 2010, 04:21 PM
#28
Re: Recordset Counting problem
Thank you to all who contributed to helping me. I learned a thing or 2 along the way too. Lessons not soon forgotten either.
-
March 15th, 2010, 08:57 AM
#29
Re: [RESOLVED] Recordset Counting problem
Glad to hear that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|