Solved

VB.NET - Cannot initialize Byte() array

Posted on 2009-05-14
8
1,389 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 31

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 31

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 31

Expert Comment

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

0
 

Author Comment

by:josephdaviskcrm
ID: 24386683
Sorry... using square brackets isn't doing the trick.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 31

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 31

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now