473,836 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about VB program results...

I have the following two button click procedures to retrieve html code from
web sites.

The code for Button1 seems to work fine. Button2 works fine for
http://yahoo.com but not for http://groups.google.com. When trying the
Google site, iContentLength is -1 after it is set to
myResponse.Cont entLength. Any ideas why? If I uncomment the lines in
Button2's event handler then that part of it will work with Google's site,
using the same technique that Button1 uses.

I'm trying to learn VB while working on this so that's why I'm interested in
why Button2 works for some sites but not for all...

It seems like iContentLength = myResponse.Cont entLength doesn't work
properly. I am not sure how to look at the myResponse stream object using
the debugger so I don't know how to make heads or tails of this.

Thanks for any help,

David
May 26 '07 #1
1 1126
"David" <da*********@yo owhoo.comwrote in message
news:Bq******** *************** *******@comcast .com...
>I have the following two button click procedures to retrieve html code from
web sites.

The code for Button1 seems to work fine. Button2 works fine for
http://yahoo.com but not for http://groups.google.com. When trying the
Google site, iContentLength is -1 after it is set to
myResponse.Cont entLength. Any ideas why? If I uncomment the lines in
Button2's event handler then that part of it will work with Google's site,
using the same technique that Button1 uses.

I'm trying to learn VB while working on this so that's why I'm interested
in why Button2 works for some sites but not for all...

It seems like iContentLength = myResponse.Cont entLength doesn't work
properly. I am not sure how to look at the myResponse stream object using
the debugger so I don't know how to make heads or tails of this.

Thanks for any help,

David
The code might help a bit...

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim myChar As Char
Dim myRequest As HttpWebRequest =
HttpWebRequest. Create(Me.textU RL.Text)
Dim webResponse As HttpWebResponse = myRequest.GetRe sponse
Dim responseStream As IO.Stream = webResponse.Get ResponseStream
Dim responseReader As StreamReader = New
StreamReader(re sponseStream)
Dim writer As StreamWriter = New StreamWriter("c :\textStream.tx t",
Me.ckAppend.Che cked)
writer.WriteLin e("Dumping HTML stream...")
Do Until responseReader. EndOfStream = True
myChar = ChrW(responseRe ader.Read)
If Asc(myChar) = 10 Then writer.Write(Ch r(13))
writer.Write(my Char)
Loop
writer.Close()
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim myRequest As HttpWebRequest =
HttpWebRequest. Create(Me.textU RL.Text)
Dim myResponse As HttpWebResponse = myRequest.GetRe sponse
Dim m_sPageResponde d As String = myResponse.Resp onseUri.ToStrin g
Dim iContentLength As Integer
Dim sTotalBuffer() As Byte
Dim br As New BinaryReader(my Response.GetRes ponseStream)
Dim sBuffer() As Byte
Dim m_iBytesRead As Integer
Dim iTotalBytes As Integer
Dim myChar As Char
Dim i As Integer
iContentLength = myResponse.Cont entLength
' Dim responseStream As IO.Stream = myResponse.GetR esponseStream
' Dim responseReader As StreamReader = New
StreamReader(re sponseStream)
' Dim writer2 As StreamWriter = New
StreamWriter("c :\textStream2.t xt", Me.ckAppend.Che cked)
' writer2.Write(r esponseReader.R eadToEnd)
' writer2.Close()

ReDim sTotalBuffer(iC ontentLength - 1)
m_iBytesRead = 1
iTotalBytes = 0
Do Until m_iBytesRead = 0
ReDim sBuffer(iConten tLength - 1)
m_iBytesRead = br.Read(sBuffer , 0, iContentLength)
ReDim Preserve sBuffer(m_iByte sRead - 1)
If m_iBytesRead 0 Then Array.Copy(sBuf fer, 0, sTotalBuffer,
iTotalBytes, sBuffer.Length)
iTotalBytes += m_iBytesRead
Loop
Dim writer As StreamWriter = New StreamWriter("c :\textStream.tx t",
Me.ckAppend.Che cked)
writer.WriteLin e("Dumping HTML stream...")
For i = LBound(sTotalBu ffer) To UBound(sTotalBu ffer)
myChar = ChrW(sTotalBuff er(i))
If sTotalBuffer(i) = 10 Then writer.Write(Ch r(13))
writer.Write(my Char)
Next
writer.Close()
End Sub
May 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
1233
by: Karl Pech | last post by:
Hi, I'm currently working on the following exercise: --- You have given the following function: def f2(i, j, k): return ((i | j) & k) | (i & j) Find a useful utilization for this function. ---
11
6922
by: Sweety | last post by:
hello to all members, i have strange question in C. main() { printf("%d",main) ; } here o/p is same for all m/c in TC++ version 3.0 i.e 657. I think this is not garbage.
7
7420
by: Bo Sun | last post by:
hi: please take a look at the following code fragment: char* hello = "Hello World\n"; hello = 's'; why I cannot modify hello?
83
3084
by: user | last post by:
Hello, Here is the program #include stdio int main(void) { const int num = 100; int *ip;
5
6405
by: jchludzinski | last post by:
I'm using strtok() to parse thru a line and read different numbers: float value; char *token; token = strtok( line, " " ); .... sscanf( token, "%f", &value ); These results are less precise than I had expected:
3
395
by: sophie_newbie | last post by:
I was wondering if there was a way to extract everyting in the url after the "?" question mark in one go. I have a search page and a results page, and I want the results page to be able to keep a history of what searches have been performed, but there is always a different number of search terms so there is always a differnet number of parameters, ie. ...
4
1438
by: pcnerd | last post by:
I originally asked this question in the "classic" VB forum. It occured to me after I had sent it that I sent it to the wrong forum. Anyway! Here's the situation. I have VB.NET 2005 Express Edition. I have a 19" LCD monitor with the resolution set at 1280 by 1024. I want to create a graphics program, say, displaying fractals that will run with the form maximized. Are the XY coordinates on the form independent of the size & resolution of...
5
1917
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the main class whenever it is needed: class shop_main { var $prices = null; function &get_prices() {
10
1889
by: bullockbefriending bard | last post by:
first, regex part: I am new to regexes and have come up with the following expression: ((1|),(1|)/){5}(1|),(1|) to exactly match strings which look like this: 1,2/3,4/5,6/7,8/9,10/11,12 i.e. 6 comma-delimited pairs of integer numbers separated by the
5
1795
by: Ryan Krauss | last post by:
I need to parse the following string: $$\pmatrix{{\it x_2}\cr 0\cr 1\cr }=\pmatrix{\left({{{\it m_2}\,s^2 }\over{k}}+1\right)\,{\it x_1}-{{F}\over{k}}\cr -{{{\it m_2}\,s^2\,F }\over{k}}-F+\left({\it m_2}\,s^2\,\left({{{\it m_2}\,s^2}\over{k}}+1 \right)+{\it m_2}\,s^2\right)\,{\it x_1}\cr 1\cr }$$ The first thing I need to do is extract the arguments to \pmatrix{ } on both the left and right hand sides of the equal sign, so that the...
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9656
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10819
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10526
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9349
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7771
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5811
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3100
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.