How to Get Local Time Using Zip Code in VB.NET

2
489

This tutorial is all about How to Get Local Time Using Zip Code in VB.NET.
Today, I will teach you how to get the local time by using a zip code in VB.NET. With this you will be able to identify what are the local time of all the countries using their zip codes. In here, I used the Web Service to get the local time in a certain country.

 

Let’s begin:

 

Open the Visual Basic, create a new Windows Form Application and do the Form just like this.
zipcodeform1
After setting up the Form, go the solution explorer, right click and hit “Add Service references”.
zipcodeform2

Then, right click the folder of “Service references” and hit again the “Add Service references”. Add this “http://www.ripedev.com/webservices/LocalTime.asmx” for the server’s address and hit ok.
zipcodeform3

You will now have a “Service References”.
zipcodeform4

 

Double click the “Go” Button on the Form. You have to set up the server to get the local time to their following Zip Codes in the click event handler of the Button.
[vbnet] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

‘SET THE VARIABLE TO CREATE AN INSTANCE OF THE WEB SERVICE PROXY CLASS
Dim local_time As New ServiceReference1.LocalTimeSoapClient
Dim format_time As Date
Dim add_time As Integer

‘SET THE PROPER CURSOR
Cursor = Cursors.WaitCursor
‘SET THE PROCESSES OF ALL THE WINDOWS MESSAGE THAT IS CURRENTLY IN THE MESSAGE QUEUE.
Application.DoEvents()

Try
‘FILTERING THE NUMERIC VALUE.
If IsNumeric(txtzipcode.Text) = True And txtzipcode.Text = “” Then
‘SET THE ServiceReference TO RETRIEVE THE LOCAL TIME FROM THE WEB SERVICE.
format_time = local_time.LocalTimeByZipCode(txtzipcode.Text)
‘SET A FORMULA THAT WILL BE ADDED 1 HOUR IN THE TIME
‘BECAUSE THE LOCAL TIME IN THE WEB SERVICE IS DELATED FOR 1 HOUR.
add_time = Format(format_time, “hh”) + 1
‘DISPLAY THE EXACT TIME IN THE TEXTBOX(txtlocaltime).
txttime.Text = add_time & “:” & Format(format_time, “mm:ss”)
Else
MsgBox(“Server was unable to process request. The zip code must be correct!”, MsgBoxStyle.Exclamation)
End If
Catch exp As Exception
MsgBox(“Server was unable to process request. The zip code must be correct!” & exp.Message, MsgBoxStyle.Exclamation)
Exit Sub
Finally

‘RESET THE CURSOR TO DEFAULT.
Cursor = Cursors.Default
End Try

End Sub
[/vbnet] Go to the design views and double click the Form. You have to disable the TextBox that the local time appears.
[vbnet] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘DISABLING THE TEXTBOX.
txtlocaltime.Enabled = False
End Sub
[/vbnet]

 

Download the complete source code here.

 

Readers might read also:

 

 

Facebook Comments

2 COMMENTS

  1. This website is completely awesome. I’ve looked these stuffs a whole lot and I view it that is good written, easy
    to understand. I congratulate you for this article that I
    am going to recommend to people around. I ask you to
    visit the gpa-calculator.co site where each learner or college student can find results grade
    point average levels. All good!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.