|
-
Jan 24th, 2005, 12:57 PM
#1
Thread Starter
Member
[RESOLVED]RichTextBox to Listbox? or Inet HTML Source to .txt?
How could I take data from a RichTextBox line by line and add it to a listbox?
Any help is greatly apreciated...
Last edited by Computer_Wiz; Jan 24th, 2005 at 03:15 PM.
' Comments go here...
~ Computer_Wiz ~
-
Jan 24th, 2005, 01:25 PM
#2
Re: RichTextBox to Listbox?
Here is what I have so far. In my test it isn't stripping the last line correctly though.
VB Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1
Private Const EM_GETLINECOUNT = &HBA
Private Sub Command1_Click()
Dim strBuffer As String
Dim lngLength As Long
Dim intCurrentLine As Integer
Dim lngLines As Long
Dim lngIndex As Long
RichTextBox1.SelStart = 1
lngLines = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0)
For lngIndex = 1 To lngLines
intCurrentLine = RichTextBox1.GetLineFromChar(RichTextBox1.SelStart)
'get line length
lngLength = SendMessage(RichTextBox1.hwnd, EM_LINELENGTH, intCurrentLine, 0)
'resize buffer
strBuffer = Space(lngLength)
'get line text
Call SendMessage(RichTextBox1.hwnd, EM_GETLINE, intCurrentLine, ByVal strBuffer)
List1.AddItem strBuffer
RichTextBox1.SelStart = RichTextBox1.SelStart + lngLength
Next
End Sub
Private Sub Form_Load()
RichTextBox1.Text = "This is a test of the quick brown fox running off with the dog"
End Sub
-
Jan 24th, 2005, 02:04 PM
#3
Thread Starter
Member
Re: RichTextBox to Listbox?
Ok well that doesnt really work for what I'm attempting..
Cause I'm trying to receive the source code from a html document using the INet and I get display it in a textbox because of bold lines which the source returns.
Otherwise I could easily save the textbox to a .txt and the input line by line and kill the file.
The listbox is crucial to what I have to do, if the source can be added to a .txt I can easily import the source code, just I can't get the source code without the bold lines, without using a RichTextBox
' Comments go here...
~ Computer_Wiz ~
-
Jan 24th, 2005, 02:12 PM
#4
Re: RichTextBox to Listbox? or Inet HTML Source to .txt?
So, you want the source code for any input web page. Is this what you are after?
-
Jan 24th, 2005, 02:21 PM
#5
Thread Starter
Member
Re: RichTextBox to Listbox? or Inet HTML Source to .txt?
Pretty much, but it returns vbcr and vblf. And when I remove these, the source stays to one line. In which will counter react when I attempt to add the source to a listbox.
Edit: Well I've gotten closer to what I need, now I just need to remove 1 char... not sure which one it is as of yet.
Last edited by Computer_Wiz; Jan 24th, 2005 at 02:30 PM.
' Comments go here...
~ Computer_Wiz ~
-
Jan 24th, 2005, 02:30 PM
#6
Re: RichTextBox to Listbox? or Inet HTML Source to .txt?
 Originally Posted by Computer_Wiz
Pretty much, but it returns vbcr and vblf. And when I remove these, the source stays to one line. In which will counter react when I attempt to add the source to a listbox.
Well, this should get you whatever source code is available on the page, and dump it to a richtextbox. From there, I guess you would dump it to a text file, load the listbox, and kill the text file. It should all be pretty much transparent to the user, just a little more coding on your part.
VB Code:
Option Explicit
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Const IF_FROM_CACHE = &H1000000
Private Const IF_MAKE_PERSISTENT = &H2000000
Private Const IF_NO_CACHE_WRITE = &H4000000
Private Const BUFFER_LEN = 256
Private Function GetUrlSource(sURL As String) As String
Dim sBuffer As String * BUFFER_LEN
Dim Result As Integer
Dim sData As String
Dim hInternet As Long
Dim hSession As Long
Dim lReturn As Long
hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0)
If hInternet Then
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sBuffer
Do While lReturn <> 0
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sData + Mid(sBuffer, 1, lReturn)
Loop
End If
iResult = InternetCloseHandle(hInternet)
GetUrlSource = sData
End Function
Private Sub Command1_Click()
Dim strURL As String
Dim HTMLSource As String
strURL = "http://www.google.com/"
HTMLSource = Inet1.OpenURL(strURL, icString)
RichTextBox1.Text = HTMLSource
End Sub
-
Jan 24th, 2005, 02:34 PM
#7
Thread Starter
Member
Re: RichTextBox to Listbox? or Inet HTML Source to .txt?
Well thanks Hack, but you made it more complicated then it really needed to be. I figured it out and for feature reference to any other beginners. Here's my source.
VB Code:
Dim strRemVBCRLF() As String
Dim strArray As String
With Inet1
strsource = .OpenURL(txtURL.Text, icString) 'Open url according to what user entered
End With
strsource = Replace(strsource, vbLf, vbCrLf) 'Remove bad chars
strsource = Replace(strsource, vbCr, vbCrLf) ' ""
strRemVBCRLF() = Split(strsource, vbCrLf & vbLf) 'Split each line
strArray = UBound(strRemVBCRLF) - LBound(strRemVBCRLF) 'Find Out Array Count
For x = 0 To strArray
lstWebSource.AddItem strRemVBCRLF(x) 'Add each line
Next
End Sub
The less complicated coding, the smaller the application and greater the speed
' Comments go here...
~ Computer_Wiz ~
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
|