Home All Groups Group Topic Archive Search About

cant assign variable values to property in Class file

Author
11 Dec 2006 1:36 PM
Avi
Hi

      I am creating web application in which i want to assign by
default values to the property which i had created my own. In that one
of the property is of type color and i am unable to assign any value to
that color type property..

     my code is

     Dim Col1Color as String

     vartable="------"
     vartable&= TDCOLOR1

    i got error:- & operator not defined for System.Object and
syste.Drawing.Color

    plz help me out

    Thanks in advance

Author
11 Dec 2006 1:49 PM
Patrice
Basically vartable looks like an object while TDCOLOR1 is a
System.Drawing.Color object and &= is the string concatenation operator. You
can't string concatenate an object and a Color object.

I would declare vartable as a color and would use Vartable=TDCOLOR1 but I'm
not sure this is what you are trying to do (vartable="-----" wouldn't work
any more but why are you doing this if vartable ios really supposed ton be a
color object ?)

--
Patrice

"Avi" <studymaterial.vis***@gmail.com> a écrit dans le message de news:
1165844174.210347.37***@j44g2000cwa.googlegroups.com...
Show quoteHide quote
> Hi
>
>      I am creating web application in which i want to assign by
> default values to the property which i had created my own. In that one
> of the property is of type color and i am unable to assign any value to
> that color type property..
>
>     my code is
>
>     Dim Col1Color as String
>
>     vartable="------"
>     vartable&= TDCOLOR1
>
>    i got error:- & operator not defined for System.Object and
> syste.Drawing.Color
>
>    plz help me out
>
>    Thanks in advance
>
Author
12 Dec 2006 5:37 AM
Avi
Hi Patrice,

   what i m doing is.

   I hav a one class file in which i had created some property and
assigning some default values to those property. in the NEW() function
OK. Again in this NEW() function i had created one dynamic table and
those property are related to that table.
  in the Page Load() funtion of .aspx file i want to give some new
values to those property

  now problem is that

  When application starts it call first NEW( ) function in which table
with default values get generated and now in Page Laod( ) function i
want to assign new values in place of those default values. which i
cant. so is there any way to call the NEW( ) from Page_Load( )
.......
Author
12 Dec 2006 9:17 AM
Patrice
I meant rather what is the final non technical goal. For example is vartable
supposed to store a color object ? Is this a list of colors as the
concatenation seems to imply ? etc...

For now :
- vartable is an object (but you assign first a string to it ?)
- TDCOLOR1 is a color object
- you try to string concatenate these two objects ?

So you can't string concatenate those two objects, hthis is as if you would
try to add a string and a date. It doesn't make sense.

So you have multiple solutions such as :
vartable=TDCOLOR1 (both being Color object)
vartable &= TDCOLOR1.ToString vartable being a string and converting
TDCOLOR1 to a string (but you would store multiple colors without any
separator ?)
vartable(i)=TDCOLOR vartable being an array of colors

For now the code exceprt doesn't make clear what your intent is :
- you provide the declaration for Col1Color but it is not used in your code
- we don"t know how vartbale TDCOLOR1 are declared though it is used in your
code
- from the message you try to string concatenate a color and an object (but
it looks weird you first put ----- in vartbale etc...)
etc...

--
Patrice

"Avi" <studymaterial.vis***@gmail.com> a écrit dans le message de news:
1165901843.815129.60***@79g2000cws.googlegroups.com...
Show quoteHide quote
> Hi Patrice,
>
>   what i m doing is.
>
>   I hav a one class file in which i had created some property and
> assigning some default values to those property. in the NEW() function
> OK. Again in this NEW() function i had created one dynamic table and
> those property are related to that table.
>  in the Page Load() funtion of .aspx file i want to give some new
> values to those property
>
>  now problem is that
>
>  When application starts it call first NEW( ) function in which table
> with default values get generated and now in Page Laod( ) function i
> want to assign new values in place of those default values. which i
> cant. so is there any way to call the NEW( ) from Page_Load( )
> ......
>
Author
12 Dec 2006 1:12 PM
Phill W.
Avi wrote:

>    I hav a one class file in which i had created some property and
> assigning some default values to those property. in the NEW() function
> OK. Again in this NEW() function i had created one dynamic table and
> those property are related to that table.
>   in the Page Load() funtion of .aspx file i want to give some new
> values to those property

Class X
    ' ?Inherits Y

    Public Sub New()
    End Sub

    Public Property TDBackground() as Color
       Get
          Return colorTD
       End Get
       Set( Value as Color )
          colorTD = Value
       End Set
    End Property

    Private colorTD as Color = Color.Black

End Class

Private oX As New X()

Sub Page_Load( ...
    oX.TDBackground = Color.Green
End Sub

> When application starts it call first NEW( ) function in which table
> with default values get generated and now in Page Laod( ) function i
> want to assign new values in place of those default values. which i
> cant. so is there any way to call the NEW( ) from Page_Load( )

No, but you could either create a "reload" method can you call from
New() and elsewhere or, perhaps better, add a "Render" method that
generates the HTML based on the properties you've set.

    Public Function Render() As String
       ' I'm guessing at what this needs to do ...
       ' I think the "x2" will work - haven't tried it
       Dim sColor as String _
          = colorTD.Red.ToString("x2") _
          & colorTD.Green.ToString("x2") _
          & colorTD.Blue.ToString("x2")
       Return "<td bgcolor='#" & sColor & "'>"
    End Function

HTH,
    Phill  W.