locked
1-dimensional array of string cannont be converted to 2-dimensional array of string RRS feed

  • Question

  • User1014009466 posted

    I am having a problem understanding the following error message:

    ‘Value of type 1-dimensional array of string cannont be converted to 2-dimensional array of string because the array types have different numbers of dimensions’

     

    This line seems to be causing the error:

    New String((13) - 1) {}

     

    I did a Google search on this but didn’t come up with anything useful.  I didn’t even change the code.  I just found this example online and copied/pasted it into a project that I’m working on.  What do I need to do to get this working?

     

    All code is listed below!

     

    Calendar.aspx.vb

     

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    
    Public Class Calendar
        Inherits System.Web.UI.Page
        'array for 12 months and 31 days
        Private schedDay(,) As String = New String((13) - 1) {}
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' Prepare day(schedule) list before using it.
            schedDay(1, 1) = "Happy New Year's!!"
            schedDay(2, 27) = "Midtown South Beer Bar Crawl"
            schedDay(4, 1) = "April Fool's Day"
        End Sub
    
     
    
    Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)
            Dim day As CalendarDay = CType(e.Day, CalendarDay)
            Dim cell As TableCell = CType(e.Cell, TableCell)
            ' Check day being rendered is of given month or other.
            ' It is required because calander display you some day of previous month
            ' and next moth.
            If Not day.IsOtherMonth Then
                Dim dayStr As String = schedDay(day.Date.Month, day.Date.Day)
                If (Not (dayStr) Is Nothing) Then
                    ' Format the Cell
                    cell.BackColor = System.Drawing.Color.Tan
                    'Write some description about day
                    cell.Controls.Add(New LiteralControl(("<BR>" + dayStr)))
                End If
            End If
        End Sub
    End Class


    Calendar.aspx

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Calendar.aspx.vb" Inherits="Calendar" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body style="font-size: 12pt">
        <form id="form1" runat="server">
        <div style="font-size: 10pt; font-family: Verdana" title="PBPWorld">
            <span style="text-decoration: underline"><strong>customized Calander Control<br />
            </strong></span>
            <br />
            <asp:Calendar ID="Calendar1" runat="server" BackColor="White"
                BorderColor="Black" Font-Names="Verdana" Font-Size="9pt"
                ForeColor="Black" Height="489px" NextPrevFormat="ShortMonth"
                Width="803px" BorderStyle="Solid" CellSpacing="1"
                OnDayRender="Calendar1_DayRender">
                <SelectedDayStyle BackColor="#333399" ForeColor="White" />
                <TodayDayStyle BackColor="#999999" ForeColor="White" />
                <DayStyle BackColor="#CCCCCC" />
                <OtherMonthDayStyle ForeColor="#999999" />
                <NextPrevStyle Font-Size="8pt" ForeColor="White" Font-Bold="True" />
                <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333"
                    Height="8pt" />
                <TitleStyle BackColor="#333399" Font-Bold="True"
                    Font-Size="12pt" ForeColor="White"
                    Height="12pt" BorderStyle="Solid" />
            </asp:Calendar>
        </div>
        </form>
    </body>
    </html>


     

    Tuesday, February 9, 2010 1:19 PM

Answers

  • User1014009466 posted

    It turned out to be:

    Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) Handles Me.Load 

    Thanks, everyone who looked, especially Nick!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 11, 2010 1:03 PM

All replies

  • User472117617 posted

    lose the { } 

    Tuesday, February 9, 2010 2:44 PM
  • User1014009466 posted

    Thanks.  Now I have a new type of error:

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted to '1-dimensional array of Char'.

    This line is highlighted red:
    Private schedDay(,) As String = New String((13) - 1)


    I'm ot sure what changed, bcause the code worked fine in the other project.  I convered the C# to VB and popped it into my project and now I'm getting these errors with arrays, which AFAIK, VB handles just as well as C#.  Any thoughts on what may be wrong now?


    Thanks!

    Ryan-- 

    Tuesday, February 9, 2010 3:59 PM
  • User1014009466 posted

    I changed the first part of my code slightly.  I'm working with this now:

    Public Class Calendar
        Inherits System.Web.UI.Page
        'array for 12 months and 31 days
        Private schedDay(,) As String = New String(12, 31) {}
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' Prepare day(schedule) list before using it.
            schedDay(1, 1) = "Happy New Year's!!"
            schedDay(2, 27) = "Midtown South Beer Bar Crawl"
            schedDay(4, 1) = "April Fool's Day"
        End Sub
    
    ...more code down here...same as original post...

    I can see the calendar, but no strings are passed to the dates on the calendar.  Does anyone have any ideas on what could be wrong now?  I'm guessing that it has something to do with the array?  I'm not even sure how to debug this.  Everytime I hit F10 or F11, the project compiles just like I hit F5.  If I enter breakpoints, and hit F10 or F11, nothing seemes to happen.


    Hopefully I can get this resolved soon.


    Thanks everyone!!


    Thursday, February 11, 2010 12:08 AM
  • User1014009466 posted

    It turned out to be:

    Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) Handles Me.Load 

    Thanks, everyone who looked, especially Nick!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 11, 2010 1:03 PM