Results 1 to 6 of 6

Thread: returning a structure from a form

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Resolved returning a structure from a form

    My code:
    VB Code:
    1. Private Sub SelectStrategy()
    2.         Dim f As New Strategies.SelectStrategyfrm      
    3.         f.ShowDialog()
    4.         If Not f.SelectedStrategy Is Nothing Then  '<====no good!!! ERROR! DANGER WILL ROBINSON!
    5. '                                                      the error is  'Is' requires operands that have
    6. '                                                        reference types, but this operand has the value type 'Globals.StrategyStruct'.
    7.             MyOptions.CurrentStrategy = f.SelectedStrategy
    8.         End If
    9.         f.Dispose()
    10.     End Sub
    My goal:
    The form being created prompts the user for information. If the user selects something a public structure is populated and the form closes, no problem. If however, the user selects Cancel, the public structure is set to Nothing and the form closes.
    VB Code:
    1. Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
    2.         SelectedStrategy = Nothing
    3.         Me.Close()
    4.     End Sub

    But as you see in the first code segment, I have pointed out that I get an error.

    I don't understand the error. If I can use
    VB Code:
    1. SelectedStrategy = Nothing
    why can't I use
    VB Code:
    1. If Not f.SelectedStrategy Is Nothing Then
    and how do I propery do what I am trying to do?
    thanks
    kevin
    Last edited by kebo; Apr 14th, 2005 at 08:55 AM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: returning a structure from a form

    structures are "value types" and you cant use IS with them. It's like having an integer and trying to check to see if the integeger Is Nothing.... it just wont work

    either make it a class instead of a structure, or write a function that'd check to see if the fields in the structure have their default values
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: returning a structure from a form

    ok... so I changed
    VB Code:
    1. Public Structure StrategyStruct
    to
    VB Code:
    1. Public Class StrategyStruct
    and it fixed the problem. I don't really understand why
    but with most OOP stuff if I hack hard enough, eventually it works.
    thanks MrPolite
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: returning a structure from a form

    Why not just create a dialog that returns a new class instance instead of populating one that already exists?

    http://www.vbforums.com/showthread.php?t=331386
    I don't live here any more.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: returning a structure from a form

    Quote Originally Posted by kebo
    with most OOP stuff if I hack hard enough, eventually it works.
    Trial and error is not good coding practice. You should see MSDN for the differences between structures and classes, there is an article about it.
    I don't live here any more.

  6. #6

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: returning a structure from a form

    Quote Originally Posted by wossname
    Why not just create a dialog that returns a new class instance instead of populating one that already exists?

    http://www.vbforums.com/showthread.php?t=331386
    I do, bad choice of word I supose.

    Quote Originally Posted by wossname
    Trial and error is not good coding practice. You should see MSDN for the differences between structures and classes, there is an article about it.
    That was meant mostly tongue in cheek if you know what I mean (I couldn't find a tonue in cheek smilely) but I will look for the article.
    thanks for the input
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width