Solved

VB.NET - Cannot initialize Byte() array

Posted on 2009-05-14
8
1,409 Views
Last Modified: 2012-05-07
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?

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

Open in new window

0
Comment
Question by:josephdaviskcrm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 24386356
Byte is a base type. You can't create instances of it.

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.



0
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 24386380
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];
0
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 24386433
Pretty sure you need square brackets in VB.NET too!

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:josephdaviskcrm
ID: 24386683
Sorry... using square brackets isn't doing the trick.
0
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 24386819
Surely changed the message you get?!

What's the new message and code?

0
 

Author Comment

by:josephdaviskcrm
ID: 24386868
Dim buf As Byte() = New Byte[8192]

Identifier Expected
The error underline is under the 8192 inside the square brackets.
0
 
LVL 32

Accepted Solution

by:
Jamie McAllister MVP earned 500 total points
ID: 24386997
Shouldn't it be this?;

Dim buf As Byte[] = New Byte[8192]
0
 

Author Closing Comment

by:josephdaviskcrm
ID: 31581510
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.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question