Solved

VB.NET - Cannot initialize Byte() array

Posted on 2009-05-14
8
1,405 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
disable data migrations in visual studio 2017 4 68
disadvantage of code behind appoarch in asp.net 3 48
Best book for Internet security 4 53
Data Analysis 7 59
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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