Announcement

Collapse
No announcement yet.

Working in VB but not in C#

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Working in VB but not in C#

    This works (VB):
    Code:
    script runat="server">
    
        ' Insert page code here
        '
        dim hs as object
        Sub Page_Load(Sender As Object, E As EventArgs)
            ' for use with the HS web server
            hs = Context.Items("Content")
            If hs Is Nothing Then
                ' maybe running under IIS
                hs = Global.ASP.global_asax.hs
                If hs Is Nothing Then
                    Response.Write("Could not get access to HomeSeer object, is HomeSeer running?")
                End If
            End If
            Label1.Text = "HomeSeer Ver: " & hs.version
        end sub
        
        Sub ButSpeak_Click(sender As Object, e As EventArgs)
            hs.speak(txtspeak.text)
        End Sub
    This does not (code behind, c#):
    Code:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Runtime.InteropServices;
    
    public partial class c : System.Web.UI.Page
    {
        private object hs;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            hs = Context.Items["Content"];
    
            if (hs == null)
            {
                hs = global::ASP.global_asax.hs;
    
                if (hs == null)
                {
                    Response.Write("Could not get access to HomeSeer object, is HomeSeer running?");
                }
            }
            else
            {
                label1.Text = "Homeseer Versions: " + hs.version;
            }
        }
    
        public void ButSpeak_Click(object sender, EventArgs e)
        {
            hs.speak(txtspeak.text);
        }
    }
    The problem is the
    label1.Text = "Homeseer Versions: " + hs.version;
    call, compiler barfs and says there is no definition for version in type object. I don't understand how that command works in VB either... Please enlighten!
    Regards,
    Tim

    #2
    c# is case sensitive and does not use late binding like VB.NET

    You did declare your variable as Object (private object hs). This is wrong and compiler is right: The object type does not have any property called "version".

    Best regards,
    --
    stipus

    Comment


      #3
      Not the answer...

      I've found the answer. It has nothing to do with case sensitivity.
      The cast I was missing (Scheduler.hsapplication) for the object hs.
      Now its declared as Scheduler.hsapplication hs;
      Last edited by ; May 29, 2008, 11:06 AM. Reason: Fixed.

      Comment

      Working...
      X