Click here to Skip to main content
15,920,438 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionRe: how to set parent window Pin
bony_baba7-Apr-06 18:26
bony_baba7-Apr-06 18:26 
AnswerRe: how to set parent window Pin
Dave Kreskowiak8-Apr-06 2:52
mveDave Kreskowiak8-Apr-06 2:52 
QuestionReuse DB connection Pin
alwinSCH6-Apr-06 1:09
alwinSCH6-Apr-06 1:09 
AnswerRe: Reuse DB connection Pin
ToddHileHoffer6-Apr-06 2:24
ToddHileHoffer6-Apr-06 2:24 
GeneralRe: Reuse DB connection Pin
alwinSCH6-Apr-06 2:51
alwinSCH6-Apr-06 2:51 
GeneralRe: Reuse DB connection Pin
Dave Kreskowiak6-Apr-06 10:37
mveDave Kreskowiak6-Apr-06 10:37 
QuestionHelp with Dynamic Casting Pin
hertz_j6-Apr-06 0:40
hertz_j6-Apr-06 0:40 
AnswerRe: Help with Dynamic Casting Pin
Dave Kreskowiak6-Apr-06 9:36
mveDave Kreskowiak6-Apr-06 9:36 
That's not going to work since there is no way to determine what the object type is from it's XML text representation. For example:
<xml version="1.0" encoding="utf-8" ?>
    <ComplexNumber>
        <R>3</R>
        <I>5</I>
    </ComplexNumber>

"3" can be anything. So you'll have to determine what that is SUPPOSED to be ahead of time before you attempt a conversion. Is that "3" really a string value containing a 3 character? Is it an Integer? Is it supposed to be a Double or a Decimal? How about a Byte? There's just no way to determine that.

You have to know ahead of time what that type is before you call CType, or any other conversion method, so you can supply the appropriate type name in the CType call. One method of doing this would be to attribute your XML elements with the Type name of the value, like this:
<xml version="1.0" encoding="utf-8" ?>
    <ComplexNumber>
        <R typename="System.Integer">3</R>
        <I typename="System.Integer">5</I>
    </ComplexNumber>

Retrieve the value of the typename attribute, then pass it into a conversion like this:
obj = Convert.ChangeType(xmldoc.SelectSingleNode(name).InnerText, Convert.GetTypeCode(typename))

But, you have another problem. What is defining obj??? Anything you return from this line of code will get boxed, if possible, by the Type that is obj, like if obj was defined as Object. This is a nice little performance hit if you're doing this many times...


Dave Kreskowiak
Microsoft MVP - Visual Basic



-- modified at 16:05 Thursday 6th April, 2006
GeneralRe: Help with Dynamic Casting Pin
hertz_j6-Apr-06 23:15
hertz_j6-Apr-06 23:15 
GeneralRe: Help with Dynamic Casting Pin
Dave Kreskowiak7-Apr-06 2:50
mveDave Kreskowiak7-Apr-06 2:50 
GeneralRe: Help with Dynamic Casting Pin
hertz_j9-Apr-06 22:24
hertz_j9-Apr-06 22:24 
Questionmdi child form connection with menu item of main form Pin
Sweet Virgo6-Apr-06 0:39
Sweet Virgo6-Apr-06 0:39 
AnswerRe: mdi child form connection with menu item of main form Pin
Dave Kreskowiak6-Apr-06 9:05
mveDave Kreskowiak6-Apr-06 9:05 
GeneralRe: mdi child form connection with menu item of main form Pin
Sweet Virgo6-Apr-06 18:07
Sweet Virgo6-Apr-06 18:07 
Questionhow to insert data in database(its urgent) Pin
Amit Agarrwal6-Apr-06 0:29
Amit Agarrwal6-Apr-06 0:29 
AnswerRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 1:01
daviiie6-Apr-06 1:01 
GeneralRe: how to insert data in database(its urgent) Pin
Amit Agarrwal6-Apr-06 1:56
Amit Agarrwal6-Apr-06 1:56 
GeneralRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 2:08
daviiie6-Apr-06 2:08 
GeneralRe: how to insert data in database(its urgent) Pin
Amit Agarrwal6-Apr-06 2:23
Amit Agarrwal6-Apr-06 2:23 
GeneralRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 2:29
daviiie6-Apr-06 2:29 
GeneralRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 2:35
daviiie6-Apr-06 2:35 
AnswerRe: how to insert data in database(its urgent) Pin
Guffa6-Apr-06 2:59
Guffa6-Apr-06 2:59 
QuestionSimple Question....background..... Pin
daviiie5-Apr-06 23:24
daviiie5-Apr-06 23:24 
AnswerRe: Simple Question....background..... Pin
Chatura Dilan6-Apr-06 0:00
Chatura Dilan6-Apr-06 0:00 
GeneralRe: Simple Question....background..... Pin
daviiie6-Apr-06 0:08
daviiie6-Apr-06 0:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.