josephdaviskcrm
asked on
VB.NET - Cannot initialize Byte() array
I'm trying to do an HTTP web request with the code shown below...
But I'm getting an error saying: Type 'Byte' has no constructors.
What do I need to do to make this work?
But I'm getting an error saying: Type 'Byte' has no constructors.
What do I need to do to make this work?
Private Sub BuildReportHTML()
Dim sb As StringBuilder = New StringBuilder
Dim buf As Byte() = New Byte(8192)
Dim count As Integer = 0
Dim request As HttpWebRequest = CType(WebRequest.Create("http://www.google.com"), HttpWebRequest)
Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
Dim strm As Stream = response.GetResponseStream
Do
count = strm.Read(buf, 0, buf.Length)
If (count <> 0) Then
sb.Append(Encoding.ASCII.GetString(buf, 0, count))
End If
Loop While count > 0
Dim strTemp As String = sb.ToString
End Sub
Sorry! I'm a C# guy and see I misread your code.
If I was creating a byte array it'd be like this in C#;
Byte[] array = new Byte[8192];
If I was creating a byte array it'd be like this in C#;
Byte[] array = new Byte[8192];
Pretty sure you need square brackets in VB.NET too!
ASKER
Sorry... using square brackets isn't doing the trick.
Surely changed the message you get?!
What's the new message and code?
What's the new message and code?
ASKER
Dim buf As Byte() = New Byte[8192]
Identifier Expected
The error underline is under the 8192 inside the square brackets.
Identifier Expected
The error underline is under the 8192 inside the square brackets.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is not correct syntax in VB.
I found a different way to produce the desired result on my web appliation that has nothing to do with the http web request. So I'm dropping the questionl.
I found a different way to produce the desired result on my web appliation that has nothing to do with the http web request. So I'm dropping the questionl.
Dim buf As Byte = New Byte(8192) is wrong.
Dim buf As Byte = (Byte)8192
or
Dim buf As Byte() = Byte.Parse("8192")
May be closer to what you need.