|
-
Apr 13th, 2005, 10:30 PM
#1
returning a structure from a form
My code:
VB Code:
Private Sub SelectStrategy()
Dim f As New Strategies.SelectStrategyfrm
f.ShowDialog()
If Not f.SelectedStrategy Is Nothing Then '<====no good!!! ERROR! DANGER WILL ROBINSON!
' the error is 'Is' requires operands that have
' reference types, but this operand has the value type 'Globals.StrategyStruct'.
MyOptions.CurrentStrategy = f.SelectedStrategy
End If
f.Dispose()
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:
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
SelectedStrategy = Nothing
Me.Close()
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:
SelectedStrategy = Nothing
why can't I use
VB Code:
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
-
Apr 14th, 2005, 12:18 AM
#2
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!!
-
Apr 14th, 2005, 12:27 AM
#3
Re: returning a structure from a form
ok... so I changed
VB Code:
Public Structure StrategyStruct
to
VB Code:
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
-
Apr 14th, 2005, 02:31 AM
#4
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.
-
Apr 14th, 2005, 02:33 AM
#5
Re: returning a structure from a form
 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.
-
Apr 14th, 2005, 08:54 AM
#6
Re: returning a structure from a form
 Originally Posted by wossname
I do, bad choice of word I supose.
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|