10 Replies - 787 Views - Last Post: 19 October 2013 - 10:22 PM Rate Topic: -----

#1 Dreamvash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-October 13

VB 2010 Weather Program

Posted 19 October 2013 - 07:54 PM

Trying to program my weather program with nested if coding. For some reason I can't get the code to function properly.
It correctly demands a name while in debugging phase but when I select a Radio button lets say "Cloudy" Radio button 4 the picture doesn't come up and the label msg doesn't either. Any help is appreciated thank you :)/>

 Private Sub WeatherGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WeatherGroupBox.Enter
        If NameTextBox.Text = "" Then
            MsgBox("You must enter a name to continue!", vbOKOnly, "Error: Enter " & _
                "your name please")

        Else

            If RadioButton4.Checked = True Then
                WeatherLabel.Text = "It appears it is going to be a Cloudy " & _
                   "day today, " & NameTextBox.Text
                PictureBox4.Visible = True
                PictureBox2.Visible = False
                PictureBox3.Visible = False
                PictureBox1.Visible = False

            ElseIf RadioButton3.Checked = True Then
                WeatherLabel.Text = "The forecast calls for Rain to prevail " & _
                   "until nightfall, " & NameTextBox.Text
                PictureBox3.Visible = True
                PictureBox1.Visible = False
                PictureBox2.Visible = False
                PictureBox4.Visible = False

            ElseIf RadioButton2.Checked = True Then
                WeatherLabel.Text = "We may be able to go skiing later on " & _
                   "today, " & NameTextBox.Text
                PictureBox2.Visible = True
                PictureBox1.Visible = False
                PictureBox3.Visible = False
                PictureBox4.Visible = False

            ElseIf RadioButton1.Checked = True Then
                WeatherLabel.Text = "The sun will prevail until nightfall " & _
                   NameTextBox.Text
                PictureBox1.Visible = True
                PictureBox2.Visible = False
                PictureBox3.Visible = False
                PictureBox4.Visible = False

            End If

        End If

    End Sub


This post has been edited by macosxnerd101: 19 October 2013 - 08:01 PM
Reason for edit:: Added code tags and moved to VB.NET.


Is This A Good Question/Topic? 0
  • +

Replies To: VB 2010 Weather Program

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: VB 2010 Weather Program

Posted 19 October 2013 - 08:17 PM

Take the time to rename the controls to something contextually meaningful, as you can see we can only see the source code and not the forms.
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,360
  • Joined: 03-December 12

Re: VB 2010 Weather Program

Posted 19 October 2013 - 08:40 PM

Completely agree with Adam. Is there a reason why you are using your groupbox.enter event to call this?
Was This Post Helpful? 0
  • +
  • -

#4 Dreamvash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-October 13

Re: VB 2010 Weather Program

Posted 19 October 2013 - 08:52 PM

Its because the radio buttons are under the group box so I had figured the object had to begin from there. The pictures have been renamed along with the other requests here is a picture of how the form looks in the files options :)
Was This Post Helpful? 0
  • +
  • -

#5 Dreamvash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-October 13

Re: VB 2010 Weather Program

Posted 19 October 2013 - 09:04 PM

My apologies fellow programmers that was clearly lacking. Here is a revised version of the code. Thank you for your patience with me.

Private Sub WeatherGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WeatherGroupBox.Enter
If NameTextBox.Text = "" Then
MsgBox("You must enter a name to continue!", vbOKOnly, "Error: Enter " & _
"your name please")

Else

If SunnyRadioButton.Checked = True Then
WeatherLabel.Text = "The sun will prevail until nightfall " & _
"day today, " & NameTextBox.Text
SunnyPictureBox.Visible = True
SnowyPictureBox.Visible = False
RainyPictureBox.Visible = False
CloudyPictureBox.Visible = False

ElseIf CloudyRadioButton.Checked = True Then
WeatherLabel.Text = "It appears it is going to be a Cloudy " & _
"until nightfall, " & NameTextBox.Text
CloudyPictureBox.Visible = True
SunnyPictureBox.Visible = False
SnowyPictureBox.Visible = False
RainyPictureBox.Visible = False


ElseIf RainyRadioButton.Checked = True Then
WeatherLabel.Text = "The forecast calls for Rain to prevail " & _
"today, " & NameTextBox.Text
RainyPictureBox.Visible = True
SunnyPictureBox.Visible = False
CloudyPictureBox.Visible = False
SnowyPictureBox.Visible = False



ElseIf SnowyRadioButton.Checked = True Then
WeatherLabel.Text = "We may be able to go skiing later on " & _
NameTextBox.Text
SnowyPictureBox.Visible = True
SunnyPictureBox.Visible = False
RainyPictureBox.Visible = False
CloudyPictureBox.Visible = False

End If

End If

End Sub

Included is an attachment so you can view the form.
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,360
  • Joined: 03-December 12

Re: VB 2010 Weather Program

Posted 19 October 2013 - 09:09 PM

When you enter the group box nothing will be checked, correct?

If that is the case, and not using a button.click event to call it, you would be better off using a checked change event to handle the call.
Was This Post Helpful? 0
  • +
  • -

#7 Dreamvash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-October 13

Re: VB 2010 Weather Program

Posted 19 October 2013 - 09:11 PM

Correct sir when I enter debugging and place my mouse over the group box Nothing is checked. How would I go about to converting it to a checked change event for the call?
Was This Post Helpful? 0
  • +
  • -

#8 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,360
  • Joined: 03-December 12

Re: VB 2010 Weather Program

Posted 19 October 2013 - 09:39 PM

With just learning, the easiest way would be using the form event comboboxes. Probably select the first radio button then on the events drop down pick checked change, after the handles clause add for the rest of the radio buttons.
Was This Post Helpful? 0
  • +
  • -

#9 Dreamvash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-October 13

Re: VB 2010 Weather Program

Posted 19 October 2013 - 10:02 PM

Yes I am aware of how to combo the checked boxes for event triggers, the key part here was the professor wanted Nested If statements to contain all the radio buttons. Not just one.
Was This Post Helpful? 0
  • +
  • -

#10 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,360
  • Joined: 03-December 12

Re: VB 2010 Weather Program

Posted 19 October 2013 - 10:14 PM

Added more useful post below

This post has been edited by astonecipher: 19 October 2013 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

#11 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,360
  • Joined: 03-December 12

Re: VB 2010 Weather Program

Posted 19 October 2013 - 10:22 PM

One event handler can deal with multiple controls

MSDN Reference
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1