Hello,
I have a class (Class.vb) that has a variable dimmed (newOption) as a String.
I've created a Form with 3 radio button options and OK/Cancel buttons.
The form code has Subs for each option as follows:

Friend Class dialogArraySelection
    Public Event notifycomplete()
    Public bgaSelection As String
   Public Sub radFullArray_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radFullArray.CheckedChanged
        newOption = "Full"
    End Sub

    Public Sub radFullNoCorners_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radFullNoCorners.CheckedChanged
        newOption = "Partial"
    End Sub

    Public Sub radDwgInput_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radDwgInput.CheckedChanged
        newOption = "DWG"
    End Sub

    Public Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK

        RaiseEvent notifycomplete()
        Me.Close()
    End Sub

The Class code calls the dialog box:

    newOption = ""
    Dim diaOption As New dialogArraySelection
    diaOption.ShowDialog()

How do I get the value of newOption from the form code into the class code? I've looked all over for an answer, so thanks in advance for any help.
Thanks,
Mark

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Oops, the very top of the code has "Public bgaSelection As String" it should be "Public newOption As String"

This should do what you want.

Just set the ok_button's dialog result to ok on the desinger. You can then show the dialog and get the result of the selection by accessing the NewOption Property.

Friend Class dialogArraySelection 
   Private _newOption as string

   ReadOnly Property NewOption() As String
        Get
            Return _newOption
        End Get
    End Property

   Private Sub rdo_CheckChanged(ByVal sender As Object, ByVal e As EventArgs) Handles radDwgInput.CheckedChanged, radFullArray.CheckedChanged, radFullNoCorners.CheckedChanged
        If sender Is Nothing OrElse Not TypeOf sender Is RadioButton Then Exit Sub

        _newOption = String.Empty

        If CType(sender, RadioButton).Checked Then
            If sender.Equals(radDwgInput) Then
                _newOption = "DWG"
            ElseIf sender.Equals(radFullArray) Then
                _newOption = "Full"
            ElseIf sender.Equals(radFullNoCorners) Then
                _newOption = "Partial"
            End If
        End If

    End Sub
End Class
Dim diaOption As New dialogArraySelection
diaOption.ShowDialog()
dim newOption as string = diaOption.NewOption
diaoption.dispose

if string.isnullorempty(newoption) then
'nothing selected
endif

Edited 5 Years Ago by Unhnd_Exception: n/a

Hello and thanks for the help. It seems to work, the only problem is that when I pick the "OK" button it just sits there. The dialog box stays, so I picked the "Cancel" button and the program runs. I'll keep looking into it, but if you have any advice, I'd be glad to take it.

Thanks again,
Mark

You have to handle the ok button like you originally did

or

on the form designer click on the button and in the properties window set the buttons dialog result to ok.

Its an easy way of not having to code anything when the form is always going to be a shown with showdialog.

and the code i posted should actually be

dim newOption as string = string.empty
if diaOption.showdialog = ok then
   newoption = diaOption.NewOption
endif

Thank you for your help. I hate to keep bugging you, but it seems I have to hit the "OK" button twice for it to start running the program. I've changed some variables for my own clarification, but here's the code.
In the diaArraySelection Form code:

Imports System.Windows.Forms

Friend Class dialogArraySelection
    Private bgaOption As String

    ReadOnly Property NewOption() As String
        Get
            Return bgaOption
        End Get
    End Property

    Private Sub rdo_CheckChanged(ByVal sender As Object, ByVal e As EventArgs) Handles radDwgInput.CheckedChanged, radFullArray.CheckedChanged, radFullNoCorners.CheckedChanged
        If sender Is Nothing OrElse Not TypeOf sender Is RadioButton Then Exit Sub

        bgaOption = String.Empty

        If CType(sender, RadioButton).Checked Then
            If sender.Equals(radFullArray) Then
                bgaOption = "Full"
            ElseIf sender.Equals(radFullNoCorners) Then
                bgaOption = "Partial"
            ElseIf sender.Equals(radDwgInput) Then
                bgaOption = "DWG"
            End If
        End If

    End Sub

    Private Sub dialogArraySelection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

In the main Class code:

' Use the dialog box to determine BGA type
        Dim diaArraySel As New dialogArraySelection
        diaArraySel.ShowDialog()
        Dim bgaOption As String = String.Empty
        If diaArraySel.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            bgaOption = diaArraySel.NewOption
        End If

I did as you said and changed the property of the "OK" button to have the dialog result of "OK".

Thanks again,
Mark

Dim diaArraySel As New dialogArraySelection
'diaArraySel.ShowDialog()
Dim bgaOption As String = String.Empty
If diaArraySel.ShowDialog = System.Windows.Forms.DialogResult.OK Then
     bgaOption = diaArraySel.NewOption
End If

The form was being called twice

Thank you very much. I really appreciate your time and expertise.

This question has already been answered. Start a new discussion instead.