Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.NET - Cannot initialize Byte() array

Posted on 2009-05-14
8
Medium Priority
?
1,421 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
  • 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 2000 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

Technology Partners: 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!

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

877 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