CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Weather Web Service

  1. #1
    Join Date
    Mar 2014

    Weather Web Service

    there are no errors showing on the code screen but when I debug it to test it and goes to receive, my message box saying "web service not available" pops up.
    It is built with a Text Box for Zip entry, Combo box for Weather or forecast, lblForecast for return. Three buttons Submit, Clear, and Exit. Submit is the one button not working.

    The methods are:
    GetCityForecastByZIP ( ZIP As string ) As ForecastReturn
    Allows you to get your City Forecast Over the Next 7 Days, which is updated hourly. U.S. Only

    GetCityWeatherByZIP ( ZIP As string ) As WeatherReturn
    Allows you to get your City's Weather, which is updated hourly. U.S. Only

    I need an example or step by step to correct. I am new to VB and hitting this wall and feel I'm so close. Thank you in advance for your help im really struggling here.

    At the" lblForecast.text = intZipCode.ToString & " " & strWeatherType " it is underlined with the hint variable intZipCode is used before it has been assigned a value. Same for strWeatherType.

    Option Strict On
    Public Class frmLocalWeather
        Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
            'Connects to Web Services to give either the weather, temperature, or both for the selected City.
            Dim wsWeatherReturn As New com.cdyne.wsf.Weather
            Dim wsWeather1 As New com.cdyne.wsf.WeatherReturn
            Dim intZipCode As String
            Dim strTempType As String
            Dim strWeatherType As String
                intZipCode = Convert.ToString(txtZip.Text)
                wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
            Catch Exception As FormatException
                'Detects if information is missing
                MsgBox("Select a Zip and Weather Type", , "Error")
            Catch Exception As OverflowException
                'This catch Block detects numbers that are to Large
                MsgBox("Please enter Zip Code")
            Catch Exception As SystemException
                'This catch block detects a generic exception.")
                MsgBox("Entry invalid. Please enter a valid Zip Code")
            End Try
            'Select Weather or Temperature 
            If (cboWeather.SelectedIndex > -1) Then
                strTempType = CStr(cboWeather.SelectedIndex)
                    Select Case strTempType
                        Case CStr(0)
                            wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
                            strWeatherType = " Temperature "
                        Case CStr(1)
                            wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
                            strWeatherType = " Weather "
                        Case CStr(2)
                            wsWeather1 = wsWeatherReturn.GetCityWeatherByZIP("37066")
                            strWeatherType = " Both "
                    End Select
                    'Produce Weather or temp
                    LblForecast.Text = intZipCode.ToString & " " & strWeatherType
                Catch Exception As SystemException
                    MsgBox("Web Service Not Available", , "Error")
                End Try
                MsgBox("Select a Zip and Weather type")
            End If
        End Sub
        Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
            txtZip.Text = ""
            LblForecast.Text = ""
            cboWeather.Text = ""
        End Sub
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        End Sub
        Private Sub frmLocalWeather_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Clear Forecast Label
            LblForecast.Text = ""
        End Sub
    End Class

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Weather Web Service

    In the MsgBox("Web Service Not Available", , "Error") line, display the actual error from the exception. It will probably give you more information on what is wrong.

    Another alternative (i.e. a better one) is add a couple of breakpoints and step through your code in the debugger. That way you can inspect the variables in your program at run time and figure out the exact line of the failure.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)