CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 11/14/2003 1:42:54 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 12 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
MarvinFrederick
Asp.Net User
help.... anyone have an answer to this...11/14/2003 1:42:54 PM

0/0

I have a class (called Location) that has three properties and I want to be able to use it as a
regular type elsewhere in my code, such as assigning a string to it and getting a string from
it. Similar to the following:

Dim a as Location
a = "112|nyk|new york"

I have tried writing a TypeConverter for it (shown below) but when I try the statements
above, it gives me Value of type 'String' cannot be conerted to 'sandbox4.Location'.

I thought the TypeConverter would allow that to happen. Am I missing something? (And
yes, I have read the docs regarding Implementing a TypeConverter for a point (and one
for a circle, but that did not help...)

Thanks.

LocationConverter.vb



Imports System.Globalization
Imports System.ComponentModel

Public Class LocationConverter
Inherits TypeConverter

Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
If sourceType Is GetType(String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function

Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
If TypeOf value Is String Then
Dim v As String() = CStr(value).Split("|")
Return New Location(Integer.Parse(v(0)), v(1), v(2))
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function

Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
If destinationType Is GetType(String) Then
Return CType(value, Location).LocNum & "|" & CType(value, Location).Abbrv & _
"|" & CType(value, Location).Name
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
End Class


Location.vb



Imports System.ComponentModel

<TypeConverter(GetType(LocationConverter))> _
Public Class Location
Private _locNum As Integer
Private _Abbrv As String
Private _Name As String

Property LocNum() As Integer
Get
LocNum = _locNum
End Get
Set(ByVal Value As Integer)
_locNum = Value
End Set
End Property

Property Name() As String
Get
Name = _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property

Property Abbrv() As String
Get
Abbrv = _Abbrv
End Get
Set(ByVal Value As String)
_Abbrv = Value
End Set
End Property

Public Sub New()
End Sub

Public Sub New(ByVal locNumber As Integer, ByVal Abbrev As String, ByVal LocName As String)
_locNum = locNumber
_Abbrv = Abbrev
_Name = LocName
End Sub

Public Sub New(ByVal str As String)
Dim v() As String = str.Split(ControlChars.Tab)
_locNum = CInt(v(0))
_Abbrv = v(1)
_Name = v(2)
End Sub
End Class


Sample.vb



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Location
a = New Location(1, "a", "alba")
' other code here .....

' THIS IS THE LINE THAT GIVES ME THE ERROR MESSAGE
a = "112|NYK|NEW YORK"

' other code here .....
End Sub

joteke
Asp.Net User
Re: help.... anyone have an answer to this...11/14/2003 4:28:16 PM

0/0

If you use the converter that way, you need to get instance of it and convert the string into instance using converter's methods:

Dim a As Location

Dim LocationConv As LocationConverter = TypeDescriptor.GetConverter(GetType(Location))
a = LocationConv.ConvertFromInvariantString("112|NYK|NEW YORK")


TypeDescriptor exists in System.ComponentModel namespace.


Thanks,

Teemu Keiski
Finland, EU
MarvinFrederick
Asp.Net User
Re: help.... anyone have an answer to this...11/14/2003 4:43:30 PM

0/0

Is there any way to do it via variables/literals/assignment operator and have the system just "know" how to do the conversion without specifying the TypeConverter stuff?
joteke
Asp.Net User
Re: help.... anyone have an answer to this...11/14/2003 6:02:50 PM

0/0

This works when page parser builds page from declarative syntax or when designer (say VS.NET) shows control's properties at design.time, but not just by assignment. There needs to be a step which involves the conversion from string to instance and vice versa.
Thanks,

Teemu Keiski
Finland, EU
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Telling Lies: Clues to Deceit in the Marketplace, Politics, and Marriage Authors: Paul Ekman, Pages: 390, Published: 2001
Your Pregnancy Questions & Answers: Questions and Answers Authors: Glade B. Curtis, Judith Schuler, Pages: 416, Published: 2004
The Brothers Karamazov Authors: Fyodor Dostoyevsky, Constance Black Garnett, Manuel Komroff, Pages: 736, Published: 1999
The Way of All Flesh Authors: Samuel Butler, Pages: 464, Published: 2007
Wizard's First Rule Authors: Terry Goodkind, Pages: 573, Published: 2001
I Don't Want to Talk about It: Overcoming the Secret Legacy of Male Depression Authors: Terrence Real, Pages: 0, Published: 1997
Heartbreaker Authors: Julie Garwood, Pages: 432, Published: 2001
Roots: The Saga of an American Family Authors: Alex Haley, Michael Eric Dyson, Pages: 912, Published: 2007
1 Dead in Attic: After Katrina Authors: Chris Rose, Pages: 364, Published: 2005
The Far Pavilions Authors: M. M. Kaye, Pages: 960, Published: 1997

Web:
Anyone have an answer to this problem? - CNET Computer help Forums Looking forward to receiving your kind reply & help Thanks in advance .... In reply to: Anyone have an answer to this problem? by Marv Frankel ...
Computer and Software Help > anyone have an answer how to fix an ... anyone have an answer how to fix an error message that is 0x003977ED tried to read from 0xFFFFFFFF program terminated. or how to find a repair tool for this ...
Wizz RSS/Sage-Too Forum • View topic - Anyone have an answer to this? Anyone have an answer to this? Post by mikek123 on Fri Jun 20, .... To help isolate the problem I decided to run Portable Firefox on my HP ...
Can anyone help/have an answer?? - Gnutella Forums Been using sharaza for quite some time...never no problems. I can connect to all networks, but to resume a download, I am being asked to ...
Doesn't anyone have an answer or some help? Please!!!! - FixYa Uniden TRU8885-2 Cordless Phone > User Guide EXPANDINGYOURPHONE ww w...
What do I do? Does anyone have an answer? - Yahoo! Answers Does anyone have an answer? Ok so here's the thing. I'm in college but I'm pregnant, .... Help us improve Yahoo! Answers. Tell us what you think. ...
Bipolar - Does anyone have an answer to this? Seroquel substitute ... Jul 20, 2008 ... Does anyone have an answer to this? ... Maybe this pdoc if we can find one that takes medicaid will help me find the right cocktail. ...
Anyone have an answer for an electric pass door on a 2003 Ford... Anyone have an answer for an electric pass door on a 2003 Ford Windstar that ... Sign up now to ask a question or help someone else by giving an answer! ...
Anyone have an answer for this one? anyone have an answer for this one? ... Welcome search, glossary, subscribe, help, library, PubCon, announcements , recent posts, ...
Bereavement Forum: Does anyone have an Answer for this Stranget ... Has anyone else out there had the samething happen to them? I still find dimes but not ... Im not sure that I have an answer for you as so much as my story. ...

Videos:
Have you Ever Heard of Google? http://live.pirillo.com - James writes: "Recently doing a project for school, I have decided to compose a Top 5 List of ways to find information. I f...
Bullies Everyone seems to have a lot of bad advice when it comes to dealing with bullies. Does anyone have the RIGHT answer? Josh and Jordan don't.
Muck or no Muck S-Cell !!!!! This is a video response to a post from cvid309 where he or she claimed I must have muck in my cell.....Well you would be wrong! I have video proof t...
Streamyx capped port 80 too?? anyone have this answer?
Help find a Cure-My Wish for Christmas Maddie is a 6 year old funny little girl that has an Arnold Chiari brain malformation, her cerebellum, back part of the brain, is squeezed down into ...
SPEED READING has EVOLVED - See the new Reading Genius 2.0 Infomercial The Planet’s Most advanced speed reading system which enables just about anyone to boos their career, improve themselves, get things done fast, overc...
Graphic Design Portfolio **Portfolio Preview** My name is Trent and here is some of the work from my College Portfolio....I graduated in December 2006 from Texas Tech Univer...
[RSMV Short]Breaking The Habit Well this is probaly my first music video i didn't make him original ill work on it when u subscribe :] so if u wanna know the end subscribe! I'm ...
In the beginning. the beginning of supergirl, boxerman, and ms.pillowcase. does anyone have the answer to boxerman having a pink room and jesse mcartney posters? ema...
SEPTEMBER 11: Evidence to the Contrary REDUX 2006 SEPTEMBER 11: Evidence to the Contrary REDUX 2006 It is a new year and many new developments have occurred in the unfolding case for September 11. ...




Search This Site:










problem with panels inside usercontrols

page template and pop up calendar control problem

how to detect causesvalidation on postback

usercontrol problem

free web hosting for asp .net 1.1

ultima hosts problems

custom gridview

server visible controls inside a template container??

syntax for registering non-namespaced custom server control in beta 1

major ie complaint (re:htc's) for ms ears

top-notch hosting?

solution : webcontrol & collections & imageurleditor & design time

stuck without multiple inheritance

multiple websites?

controls handling events of parent page

hosting asp.net web application with odbc connections

custom control

process or progress bar

properties issue within composite control

thread on ads problems

asp.net 2.0 and tele2 web-server

timer control?

calendar control

drop down control that allows editing

accessing control properties from another form

who is right.=?

msdn chat - windows 2003 hosting - october 19

need a new webhost ...i think

control ids in control tree

how can i create webcontrol property of type class?

  Privacy | Contact Us
All Times Are GMT