Value of type 'System.Array' cannot be converted to 'Integer'

 Hi,

I have a C# code sample that I ran through a C#-to-VB converter, and now Visual Studio gives me the following error for Line 3 of the VB code (Line 6 of the C# code) below:

Value of type 'System.Array' cannot be converted to 'Integer'

I'm new to VB and C# and could not figure out how to correct this. How can I modify the VB code so that it doesn't give this error?

 

--------------------------- Original Sample -------------------------------

 
1    public static class DataSources
2 {
3 public static StatusCode[] GetHttpStatusCodes()
4 {
5 string[] names = Enum.GetNames(typeof(HttpStatusCode));
6 int[] values = (int[])Enum.GetValues(typeof(HttpStatusCode));
7 StatusCode[] ret = new StatusCode[names.Length];
8 9 for (int i=0; i10 ret[i] = new StatusCode(values[i], names[i] + " - " + values[i].ToString());
11 return ret;
12 }
13 }
 

  

--------------------------- Converted to VB ---------------------------

  

1    Public Shared Function GetHttpStatusCodes() As StatusCode()
2 Dim names As String() = [Enum].GetNames(GetType(HttpStatusCode))
3 Dim values As Integer() = CInt([Enum].GetValues(GetType(HttpStatusCode)))
4 Dim ret As StatusCode() = New StatusCode(names.Length - 1) {}
5 For i As Integer = 0 To names.Length - 1
6 ret(i) = New StatusCode(values(i), names(i) + " - " + values(i).ToString())
7 Next
8 9 Return
ret
10 End Function
 

 
0
cmd_17
11/28/2007 3:23:57 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
957 Views

Similar Articles

[PageSpeed] 32
Get it on Google Play
Get it on Apple App Store

Try dropping the CInt function and see what happens.
Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
11/28/2007 3:36:56 PM
That did the trick. Thanks for your help.
0
cmd_17
11/28/2007 3:44:58 PM
Reply:

Similar Artilces:

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

Value of type '1-dimensional array of System.Object' cannot be converted to 'System.Collections.ArrayList'
I am getting this error Value of type '1-dimensional array of System.Object' cannot be converted to 'System.Collections.ArrayList'. I am implementing something similar to what is in starter kits. I have a getRoles() function that fetches a two dimensional array. AccessLevel and Region. I have to check the status of the user on every page to display data based on their AccessLevel and Region they belong to. I am trying to read these values from the ArrayList but it is giving me the above error.. Anybody knows what I may be doing wrong.. Thanks in advance Can you please show the ...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Value of type 'Integer' cannot be converted to 'System.Data.SqlClient.SqlDataReader'
Value of type 'Integer' cannot be converted to 'System.Data.SqlClient.SqlDataReader' I get the above error when I try to do this code: Dim dr As SqlDataReaderDim ID As Integer dr = oDeveloper.GetDeveloper(CllrID) anyone any ideas around this? macca   well obviously, GetDeveloper Takes a DataReader What do you mean Jeffrey? How can I get the values from GetDeveloper to my datareader dr then? macca Enable Strict for your project.  That will tell you exactly what's wrong. I think the error message already says what is wrong.If you haven't got a clue about something don...

Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'
My code is below:Protected Sub btnSendMsg_OnClick(ByVal Source As Object, ByVal E As EventArgs) Dim myMessage As New System.Net.Mail.MailMessage Dim myAttachment As System.Net.Mail.Attachment Dim myMail As System.Net.Mail.SmtpClient If Page.IsValid() Then myMessage.From = txtFromEmail.Text myMessage.To = txtToEmail.TextWhat can I do to fix this? MailMessage.To represents a collection that you Add addresses to.Dim recipient As MailAddress= new MailAddress(txtToEmail.Text) myMessage.To.Add(recipient)    Mike Banavige~~~~~~~~~~...

Value of type 'Integer' cannot be converted to 'Double'
 Hi,     I'm getting this error on my paging class "Value of type 'Integer' cannot be converted to 'Double'."    --error in bold--PaginatedList.vbPublic Class PaginatedList(Of T)    Inherits List(Of T)    Private _PageIndex As Integer    Public Property PageIndex() As Integer        Get            Return _PageIndex        End Get      ...

Value of type 'Integer' cannot converted to 'System.Web.UI.WebControls.Unit'
I'd like to dynamically change the size of controls such as panel.In the code I putmainPage.Height = 500  'mainPage is a PanelHowever, it failed to compile with message;Value of type 'Integer' cannot converted to 'System.Web.UI.WebControls.Unit'How can I change the code so that it compiles? mainPage.Height = Unit.Pixel(500)  'mainPage is a PanelSonu Kapoor [MVP] Feel free to ask me any .NET question | Ajax Data Controls Forum It works very well. Thanks a lot....

Cannot convert value of parameter 'Course_FK' from 'System.String' to 'System.Guid'
Hi, I'm building a site and I've been trying to accomplish something similar to what is talked about in "Working with Data in ASP.NET 2.0 :: Declarative Parameters" tutorial. Below is the code for my methods from the xsd. I tried to attach a screenshot of my xsd but for some reason I'm not allowed GetAllCourseNames() SELECT        CourseID, NameFROM            Course GetCourseScheduleByCourseID SELECT        ScheduleID, Course_FK, Date, TeeTime, NumberOfPlayersF...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

Cannot convert type 'type' to 'type'
I am learning all of this, so I am still fresh, so please bear with me :)I have a page that has some txtboxes in it, simple registration form, and I have a button that will save those txt boxes to the db. I am using:- I am using Visual Web Developer 2008 Express Edition- C# When I try to compile the project I get error: Cannot convert type 'System.Web.UI.WebControls' to 'String' This is content of my web.config    <profile> <properties> <add name="FirstName"/> <add name="LasttName"/>...

Error: Value of type 'System.Data.CommandBehavior' cannot be converted to 'System.IAsyncResult'.
  I wrote this code to retrieve data from the database using autocomplete extender control. Dim Dr As SqlDataReaderDim RtData As List(Of String) = New List(Of String) Dr = MysqlCmd.EndExecuteReader(Data.CommandBehavior.CloseConnection) While Dr.Read()RtData.Add(Dr("CustName").ToString()) End While   Plz Help!   regards   yamani     The EndExecuteReader does not take a CommandBehavior.  The BeginExecuteReader does.  Please follow the example on the MSDN documentation:http://msdn.microsoft.com/en-us/library/kddf8ah6....

Compiler Error Message: BC30311: Value of type 'System.Web.UI.DataSourceSelectArguments' cannot be converted to 'Integer'.
 Hello, I'm wondering if someone can help me figure out why I'm receiving the above error message..."Compiler Error Message: BC30311: Value of type 'System.Web.UI.DataSourceSelectArguments' cannot be converted to 'Integer'." In visual web developer, the blue line is pointing out the variables args, on line 15.   1 Imports System.Data 2 Partial Class POS_so_Default 3 Inherits System.Web.UI.Page 4 5 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 6 customer...

Web resources about - Value of type 'System.Array' cannot be converted to 'Integer' - asp.net.getting-started

Resources last updated: 1/21/2016 9:58:21 AM