Josh Crowe Josh Crowe - 6 months ago 31 Question

SelectedItem not Passing to Property

I'm trying to assign the

to a
on a secondary form that can be used by my main form, though despite a
clearly outlining the variable has been set, my
Select Case
switches to
Case Else
and another
shows the same variable but as

(Secondary Form)

Public Class Setup

Public Property HomePage As String
Public Property WindowSize As String

Private Sub Setup_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim SizePoss() As String = {"Desktop", "Tablet", "Mobile"}

cmbSizeSetting.MaxDropDownItems = SizePoss.Length
For Each column As String In SizePoss

' Initialize Appropriate Settings

cmbSizeSetting.SelectedIndex = cmbSizeSetting.FindStringExact("Tablet")
End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
HomePage = txtHomepageSetting.Text
WindowSize = cmbSizeSetting.SelectedItem
MessageBox.Show("Size chosen was " + WindowSize + ", which is a " + TypeName(WindowSize))

End Sub
End Class

(Primary Form)

Public Class Croweb

Private Sub btnSetup_Click(sender As Object, e As EventArgs) Handles btnSetup.Click
Dim setupForm As New Setup

If Not String.IsNullOrEmpty(setupForm.HomePage) Then
WebBrowser1.Url = New Uri(setupForm.HomePage)
End If

Select Case Setup.WindowSize
Case "Desktop"
Me.Size = New Size(1280, 730)
Case "Tablet"
Me.Size = New Size(891, 564)
Case "Phone"
Me.Size = New Size(400, 900)
Case Else
MessageBox.Show("Error: Chosen Size is " + Setup.WindowSize + ", which is a " + TypeName(Setup.WindowSize))
End Select

End Sub

End Class

Am I passing it incorrectly?


Default form instances strike again. No surprise there. You start by explicitly creating an instance and displaying that:

Dim setupForm As New Setup

Later though, you ignore that instance and use the default instance:

Select Case Setup.WindowSize

You never displayed the default instance so you never set that property in the default instance. That line should have referred to the instance you actually did display:

Select Case setupForm.WindowSize