|
-
Oct 2nd, 2001, 06:32 PM
#1
Thread Starter
Lively Member
Reading a web page......
Alright,
I need a bit of help here. I need to read a file online (the address is http://www.angelfire.com/ca2/TJTurtle/textfile.txt and I want to read the "y" and store it. For 3 points and a Tim-Bit, how would I go about doing this?
BONUS: For triple points and a snack-pack of the Tim-Bits, how would I read http://xml.imood.org/moods.cgi and only store the stuff between <count> and </count>?
SUPER BONUS!!!! I'll bump the points to 50 and toss you 100 Tim-Bits if you can tell me how to store all of the stuff between each of the <base> and </base> tags too.
Let me know!
To err is human, to really mess up, you need a computer.
-
Oct 2nd, 2001, 06:37 PM
#2
PowerPoster
For 3 points and a Tim-Bit:
Slap an Inet control on a form, and use this
VB Code:
Private Sub Command1_Click()
Text1.Text = Inet1.OpenURL("http://www.angelfire.com/ca2/TJTurtle/textfile.txt")
End Sub
'm going for the triple points and a snack-pack of the Tim-Bits, but for 100 Tim-Bits, you must be joking!
-
Oct 2nd, 2001, 06:46 PM
#3
PowerPoster
Right, where's my triple points and a snack-pack of the Tim-Bits?!
VB Code:
Dim strFile As String
Dim strCount As String
Dim intPos As Long
Dim intPos1 As Long
strFile = Inet1.OpenURL("http://xml.imood.org/moods.cgi")
'extract <count></count>
intPos = InStr(1, strFile, "<count>", vbTextCompare)
If intPos > 0 Then
intPos1 = InStr(intPos + 7, strFile, "</count>", vbTextCompare)
If intPos1 > 0 Then
'extract info
strCount = Mid$(strFile, intPos + 7, intPos1 - (intPos + 7))
End If
End If
Text1.Text = strCount
-
Oct 2nd, 2001, 06:55 PM
#4
Looks like I win it all;
VB Code:
Dim M%,N%,strText$,CurBase$
strText = Inet1.OpenURL("http://xml.imood.org/moods.cgi")
Do While Inet1.StillExecuting
DoEvents
Loop
startInt = 1
Do
M = InStr(startInt, strText, "<base>")
If M = 0 Then Exit Do
M = M + Len("<base>")
N = InStr(M, strText, "</base>")
CurBase$ = Mid$(strText, M, N - M)
Debug.Print CurBase$
startInt = M
Loop
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Oct 2nd, 2001, 07:15 PM
#5
They have an API to do it without Inet control.
-
Oct 2nd, 2001, 07:17 PM
#6
PowerPoster
Originally posted by DaoK
They have an API to do it without Inet control.
Care to grace us with the name of that API?
-
Oct 2nd, 2001, 07:19 PM
#7
Mathew Gates gave me that code few month ago:
VB Code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As _
String, ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Function DownloadFile(URL As String, _
LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Command1_Click()
DownloadFile "http://www.mypage.com/txtfile.txt", "c:\txtfile.txt"
Open "C:\txtfile.txt" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
End Sub
-
Oct 2nd, 2001, 07:20 PM
#8
I really like that api because you dont need the Inet OCX and it more stable ( that what Matthew told me ).
-
Oct 2nd, 2001, 07:36 PM
#9
DO you know how to add a progress bar on that code ?
-
Oct 2nd, 2001, 08:01 PM
#10
Thread Starter
Lively Member
Wow!
I guess the Tim-Bits helped! Now, you non-Canadians, what ARE Tim-Bits?
Oh, and you Canadians cann fill 'em in.
Last edited by Jigabug; Oct 2nd, 2001 at 08:07 PM.
To err is human, to really mess up, you need a computer.
-
Oct 2nd, 2001, 08:02 PM
#11
PowerPoster
Originally posted by Jigabug
Now, you non-Canadians, what ARE Tim-Bits?
Haven't got a clue
-
Oct 2nd, 2001, 08:10 PM
#12
-
Oct 2nd, 2001, 08:12 PM
#13
Thread Starter
Lively Member
Of COURSE we do! We have them on every other corner almost!
To err is human, to really mess up, you need a computer.
-
Oct 2nd, 2001, 08:15 PM
#14
-
Oct 2nd, 2001, 08:29 PM
#15
Thread Starter
Lively Member
For some extra fun, how would I get an Image/Picture box to open an online picture?
To err is human, to really mess up, you need a computer.
-
Oct 2nd, 2001, 08:32 PM
#16
PowerPoster
by
a) using a webbrowser control instead
b) saving the file to a local disk using inet or that API code and displaying it from there
-
Oct 2nd, 2001, 08:38 PM
#17
VB Code:
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL _
As String, ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Function DownloadFile(URL As String, _
LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Command1_Click()
Dim Success As Boolean
Success = DownloadFile("http://www.vbsquare.com/images/vbsquare.gif", "C:\vbsquare.gif")
If Success = True Then
Picture1.Picture = LoadPicture("C:\vbsquare.gif")
Else
Msgbox "Could not load image!", 16
End If
End Sub
-
Oct 2nd, 2001, 08:39 PM
#18
Matthew Gates CopyRight for that code two.
-
Oct 2nd, 2001, 08:44 PM
#19
Thread Starter
Lively Member
Now, is there any way for it to be put RIGHT up against the top and left edges? It seems to like putting itself in a bit.
To err is human, to really mess up, you need a computer.
-
Oct 2nd, 2001, 08:48 PM
#20
I do not understand you ?
-
Oct 3rd, 2001, 05:19 AM
#21
Fanatic Member
Winsock Code...
Originally posted by Jigabug
For some extra fun, how would I get an Image/Picture box to open an online picture?
Here's the fun. Using Winsock to download the file... Then load it into a picture box. See the code below. You will need to add a Picture Box control named Picture1 to a form, along with a Winsock control named Winsock1.
VB Code:
'Coded by [Digital-X-Treme]
Option Explicit
Private m_strWebPageData As String
Private Sub Form_Load()
'Establish connection.
Winsock1.Connect "vbforums.com", 80
End Sub
Private Sub Winsock1_Close()
Dim i As Long
Debug.Print "Closed..."
Debug.Print "Transfer complete..."
'Now you have the web page data, including the header.
'The header, if HTTP compliant, is trminated by the first blank line... vbCrlf & vbCrlf
'Trim the header, if any, out.
i = InStr(1, m_strWebPageData, vbCrLf & vbCrLf)
If i <> 0 Then
m_strWebPageData = Mid(m_strWebPageData, i + 4)
End If
'm_strWebPageData now contains the file contents.
'Save it to file...
Open "C:\Temp.tmp_" For Binary As #1
Put #1, , m_strWebPageData
Close #1
'Load picture from file...
Picture1.Picture = LoadPicture("C:\Temp.tmp_")
End Sub
Private Sub Winsock1_Connect()
Debug.Print "Connected..."
Debug.Print "Sending request..."
'Include the header field "Connection: close"
'This indicates to HTTP/1.1 compliant servers that we want to close the connection
'after downloading this page...
'A trick that lets us know when the download is complete (winsock will close), so we
'don't need to parse the header fields and find a content-length field...
Winsock1.SendData "GET /images/layout/top_left.gif HTTP/1.0" & vbCrLf & "Connection: close" & vbCrLf & vbCrLf
'If the server you are using is HTTP/1.0 compliant, then you shouldn't send the 'connection'
'header field.
'You will need to parse the response header, and grab the content length field, then
'just keep recieveing data until the content has been downloaded...
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData, vbString
m_strWebPageData = m_strWebPageData & strData
End Sub
Hope this helps 
Laterz
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Oct 3rd, 2001, 05:41 AM
#22
Conquistador
Originally posted by DaoK
Mathew Gates gave me that code few month ago:
VB Code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As _
String, ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Function DownloadFile(URL As String, _
LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Command1_Click()
DownloadFile "http://www.mypage.com/txtfile.txt", "c:\txtfile.txt"
Open "C:\txtfile.txt" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
End Sub
Just a bit but wouldn't that code process for example a cgi script?
-
Oct 3rd, 2001, 07:41 PM
#23
it's an api...i do not know about the cgi...
-
Oct 11th, 2001, 07:35 AM
#24
Thread Starter
Lively Member
Alright,
Now, how would i read out EVERY item inside <base> and </base> and add them to a list box? The list is at http://xml.imood.org/moods.cgi
I'm using the code posted by chrisjk, he wanted his triple points and the tim-bits.
Last edited by Jigabug; Oct 11th, 2001 at 08:07 AM.
To err is human, to really mess up, you need a computer.
-
Oct 11th, 2001, 09:07 AM
#25
-
Oct 11th, 2001, 02:07 PM
#26
Check the code I posted up above. Replace debug.print with MyList.Additem.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Oct 11th, 2001, 02:39 PM
#27
Something like this
If you were using the oldest version of the XML parser:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim objXML As New MSXML.DOMDocument
Dim blnSuccess As Boolean
objXML.async = False
blnSuccess = objXML.Load("http://xml.imood.org/moods.cgi")
If Not blnSuccess Then
MsgBox _
"XML Error #" & objXML.parseError.errorCode & ": " & _
objXML.parseError.reason & vbCrLf & _
"Line " & objXML.parseError.Line & _
", Position " & objXML.parseError.linepos & vbCrLf & _
objXML.parseError.srcText
Exit Sub
End If
Dim xmlList As IXMLDOMNodeList
Dim x As IXMLDOMNode
Set xmlList = objXML.getElementsByTagName("imood/bundle/mood/base")
For Each x In xmlList
Debug.Print x.Text
Me.Combo1.AddItem x.Text
Next
End Sub
This code works for me!
-
Oct 11th, 2001, 02:41 PM
#28
Thread Starter
Lively Member
Alright, I'm now using the sunburnt code, any ideas why it would stop at "desperate"?
To err is human, to really mess up, you need a computer.
-
Oct 11th, 2001, 02:52 PM
#29
-
Oct 11th, 2001, 03:07 PM
#30
For the count...
Use my code above and change the parameter in getElementsByTagName to:
"imood/bundle/count"
You probably don't have to bother iterating (looping) through the results since you know there's only ever going to be one count.
You can also reuse the same objXML object without going out and getting the same data again. the .xml property of that object stayed the same.
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
|