Visual Basic Page

| Home Page| Delphi Code | Visual Basic Code

Code Snippets


Simple Visual Basic Clock and UTC

Delphi and Visual Basic have controls that simplify time keeping in your logging and other programs. The computer should add the date and time of each contact automatically in your logging program. The Timer control is the basis for an easy to use station clock. The clock's display can be formatted in a variety of ways using some manual code.

Most radio amateur's keep the time on their station computers in Universal Time Coordinated (UTC) although some operators may use local time. A computer's clock can be set to UTC programmatically or by using the Windows Date/Time settings through Control Panel. Windows can be used to set the computer’s time or date by clicking on Start --> Settings --> Control Panel --> Date and Time.

Your amateur radio software can add or subtract the time difference between local time and UTC. This allows a computer’s clock to be kept on the local time and use UTC within the logging environment. You don’t want to reset the difference between UTC and local time every time the program is run. Provide a preferences menu item in your logger to ling to a procedure to save a time difference value to a configuration file. The variable that represents the time zone difference at run time can be loaded from the configuration file. Making and using configuration files will be discussed in a future snippet.

Visual Basic Clock

Use the code and methodology described in the following discussion to retrieve simple date and time information for your logging program from your computer’s clock. The code snippets that are the basis for programming a simple clock utility can also update the date and time for each contact.

Build your logger's clock in Visual Basic by putting a Timer control from the Tool Box on an empty form. Place two Labels on the form. The Labels are used to report the date and current time. The Timer control is invisible to the user but the current time can be monitored using the two Labels and the code shown below in the Timer event handler. Set the Interval property of the Timer from the Properties window to 1000 to allow the clock to change every second while the code is running. The Interval unit is the millisecond. Exactly 1000 milliseconds equals 1 second. To increment the clock once a minute, use a value of 60000.

Now that the form is set up, put the following code snippet in the Timer's event handler.

Private Sub Timer1_Timer() 'updates log clock each second

DateNum = Format(Date, "Short Date")
Timenow = Format(Time$, "Short Time")

Label1.Caption = DateNum

Label2.Caption = Timenow

VBClock.Caption = Timenow ‘VBClock is the name given to the form. This places the clock in the caption.

End Sub

The formatting directive "Short Date" sets the date in the form like "10/5/02". The formatting directive "Short Time" sets the clock’s time in the format "14:04:00." if the time has been previously set to a 24-hour clock by using Window's control settings. The directive Format(Time$, "HH:mm:ss")might be required to force your application to adopt a 24-hour format. Visual Basic’s documentation shows other ways to output time information.

The strings containing the time and date information can pass the current date and time to your log database along with station contacted and other information you want recorded in your log if the DateNum and Timenow variables are declared globally. In the snippet shown, those variables were never declared. Visual Basic treats them as variants. This is inefficient but makes the above code listing simple. When you put the code into your program, declare the variables.

The following snippet shows additional ways to manipulate time. The routine requires A text box, six labels and a Timer control and may give you some ideas about how to handle UTC in a program.

Private Sub Timer1_Timer()
''remember to set interval of Timer to 1000 in Properties window (fire once/second)
TimeDiff = Text1.Text 'UTC offset, if PC is set to UTC this is 0. Can be negative
'or positive
If TimeDiff = "" Then 'avoid case where TimeDiff is not defined
TimeDiff = 0
UTCTime = DateAdd("h", TimeDiff, TimeNum)
End If

' Label1 = Format(Time$, "Short Time") & " Time Now Local"
' Label1 = Format(Time$, "Long Time") & " Time Now Local" 'gives AM/PM
Label1 = Format(Time$, "hh:mm:ss") & " Time Now Local" 'gives AM/PM
'the Long Time only works if your PC's clock is set by the
'Windows regional settings at the default value, if it is set as
'I set my PC, one cannot get AM/PM but it appears everything
'else is OK. the hh:mm:ss appears to work if in all instances to get AM/PM etc.

Label2 = Format(Date, "Short Date") & " Today's date local"
Label3.Caption = Format(Time$, "HH:mm:ss") & " 24 hour Time now"

newdate = DateAdd("h", TimeDiff, Date + Time)
'This function might not be valid in VB3

'you can use the the next two lines
'Label5.Caption = Format(newdate, "HH:mm:ss")
'Label4.Caption = Format(newdate, "MM/dd/yyyy")


'for more flexibility use the following four lines
newdateTime = Format(newdate, "HH:mm:ss")
newdateDate = Format(newdate, "MM/dd/yyyy")
Label4.Caption = newdateTime + " UTC"
Label5.Caption = newdateDate

'you can parse newdate into a date and time
' Label6.Caption = Mid$(newdate, 1, 10) 'if you have changed
'your PC regional time settings the way I did
'but the following should work on all PCs (I hope)
Label6.Caption = newdateDate + " " + newdateTime + " UTC"

End Sub

Thanks to Joe, KE4TV for pointing out my original UTC conversion code did not work in all instances. This is simple code, you should define all your variables and put in some error control (i.e. the text box should not accept anything than the values in the range -12 to + 12 , including 0) for instance.



OmniRig is an excellent COM control that makes programming CAT for multiple rigs relatively easy. It is usable with Delphi, VB, C++ etc. It is developed by Alex, VE3NEA. It's a great tool! Get a copy at

LU7DID ActiveX and AGWPE

LU7DID's ActiveX control can control SV2AGW's Packet Engine with Delphi, Visual Basic and C++. (Pedro's control appears to have some bugs when used with Delphi 5 Pro). It is an interesting way to experiment with AGWPE, ordinary packet or APRS.

The ActiveX control works with Visual Basic 5 Professional and probably will work with other versions of VB, including standard. The code at the LU7DID's site and at the Yahoo SV2AGW forum gets you started. The demos show how to output the raw packets from the Soundcard TNC. You need to parse the output strings to get the specific information you need from individual packets. (You must join Yahoo groups to get to the SV2AGW forum-- search for SV2AGW for the example code at Yahoo using the URL described in the Links Section below).

VB users can not use the VCL that is also on Pedro's web page. Delphi 5 users should be able to use Pedro's provided VCL but my experience indicates it may only be possible to do this if you use Delphi 5 Enterprise. The VCL appears to load OK in Delphi 5 Pro but it keeps looking for a library that is not distributed with Delphi 5 Professional. The VCL does not work with D7. I haven't been able to contact Pedro, so I don't really know what the problem is. The Delphi problems continue. The ActiveX does not load properly into Delphi 5 Professional but appears to work just fine on D6! The ActiveX difficulty with D5P could be a problem on my end or related to the fact the control was developed with Delphi 5 Enterprise. So, back to VB.


LU7DID's control gives you access to high level programming techniques. I tried some low level techniques to communicate with AGWPE and had limited success.

I successfully used the agwpedll32 DLL to access AGWPE with VB. The DLL is in the package on SV2AGW's web site. The DLLdemoVB folder source code works. The command set is limited but the DLL does make a raw packet stream available you can manipulate with your own code. First find the files on SV2AGW's web site. Go to the folder agwdll. When you compile your program, note the agwdll32.dll needs to be in the same directory as your source code. George regards this a legacy technique and would rather new users use TCP.

I have not tried using VB's DDE to communicate with AGWPE. My DDE efforts with Delphi have not been successful.

I have not tried TCP to communicate using VB. My efforts with Delphi have been successful using K0QED's control.

I do not expect that Pedro or George will make any improvements to these tools. George has a new shareware version of AGWPE and Pedro does not answer e-mail to the address I have for him. Regardless, even as the controls are, there is significant potential to successfully use soundcard packet with your project instead of a hardware TNC.

If you have been successful using either Pedro's or Georges techniques to control AGWPE with either Delhi or VB, I would appreciate hearing from you.


Copyright 2003 Stephen J. Gradijan, WB5KIA Back to Top

Here are some links to applications:

Map by WB5KIA
Program to find latitude/longitude and determine simple bearing/distance information from a flat map. Example uses map of Europe. This is more elaborate than the example shown in 2003 QST magazine and is easily used with other flat maps provide the latitude of the top and base of the map are known and the longitude of the left and right side of the maps is known. Copyright 2007 Stephen J. Gradijan, WB5KIA

Download VB5 Source Code , executable and Europe map with Maidenhead grids 930Kb


Globe Plotter by KD7UI
John and Jim, W7FKI, integrated several of the modules described in QST into a very nice package.
Go to the bottom of the page and click on KD7UI's VB programming link.


WS7R's Transline A very neat 'translation' adapted from DOS (HamCalc -by George, VE3ERP). Steve converted the transmission line source code into VB. Coax and open line.

Download Transline VB3 Source Code 190Kb

Download Transline VB6 Source Code 195Kb

General Exam/Theory Course I wrote a program several years ago in CA Realizer to help my son learn the theory to pass his FCC General test. It worked. I converted the source code into VB.The Beta source and the program are available. Send me an e-mail with the words General Exam in the subject line to obtain a copy of the General course (277KB) via e-mail.Yes, it is free for personal use but it is copyrighted.
(General questions expire mid 2004.)

The program contains an HTML theory 'course', a copy of FCC regulations and the following random quiz. Will someone adapt it for the latest Tech./General question pools?

WS7R WIREPROP Wireprop allows the user to input the diameter of an unknown size of wire (0.0010 to 0.5000 inches) and to make a best guess as to the nearest standard sizes in the AWG (American Wire Gauge) and SWG (Standard [British] Wire Gauge) systems (AWG3_0.EXE for AWG system only). They also display various tables showing the diameters, areas, resistances (copper and aluminum), and weights (copper and aluminum) of sizes #4/0 thru #50 (AWG) and #7/0 thru #50 (SWG). Keep in mind that the resistances and weights are only approximate as these values vary with the alloy and the "hardness" (soft-drawn vs hard-drawn) of the conductor.

If WIREPROP is run on a video system with a resolution less than 1024 x 768, some of the forms will be only partially visible. If it is desired to modify this program for 640 x 480 or 800 x 600, maximum form dimensions are given in the text file WIREPROP.BAS. If problems are encountered I would appreciate knowing about them.

[email protected]

(Steve (WS7R) coded this in VB3. I have included a VB5/6 version with his VB3 easy conversion made possible because WS7R saved his VB3 files using the text option instead of VB3's default binary save option! --WB5KIA)

Download WIREPROP Source Code 80Kb

WS7R GRIDLOC Gridloc is a compilation of the location/azmuth routines discussed in the March and April issues of QST. Steve has added additional features (use degrees, minututes, GPS etc. in addition to decimal degree input) and has provided more error control. GRIDLOC1.1 is an update Nov. 2003.

WS7R COAXDAT Coaxdat contains info/specifications about coaxial cable as compiled from the ARRL handbook.

WS7R COAXDAT2 Coaxdat2 contains info/specifications about coaxial cable as compiled from the ARRL handbook updated Nov. 2003 to automatically expand to your current PC screen size.

WS7R COLORTST Colortst identifies the color codes that define Windows colors. Neat program and aid for the computer programmer. New features added 5/2004.

WS7R BASECONV Change the base of numbers. A programmer's aide.

LIMITS Screen limits utility.

[email protected]

(Steve (WS7R) coded GRIDLOC, COAXDAT, COLORTST & BASECONV in VB3. I have included a VB5/6 version with his VB3 easy conversion made possible because WS7R saved his VB3 files using the text option instead of VB3's default binary save option! The conversions are not totally complete. One might want to tidy up some of the forms. --WB5KIA)

Download GRIDLOC< COAXDAT< COLORTST and BASECONV Source in VB3 & VB5/6 130Kb

Download GRIDLOC1.1, LIMITS and COAXDAT2 Source in VB3 & VB5/6 156kB

WB5KIA Bearing/List Combine the Bearing/Distance and List utilities from March and April QST. This utility uses the SMALOC.TXT database described in April QST. If you didn't download the little database at that is included in the file, it is included here. For more coordinate information to populate the SMALOC.TXT file you might try:
2Fmisc%2Fqiblih%2Flatlong.html or a standard atlas (be sure to change the deg,min,sec format to decimal deg. and use the correct sign!)

The country file that is used with the shareware CT DOS logging program is a text file. It has coordinate information that can be used if one modifies the file or the source code. K1EA recently (Summer 2003) released the CT program into the public domain

Download Bearing/List Source Code 8Kb

Here are links to snippets and Amateur Radio oriented code on other sites:


LU7DID ActiveX Pedro's site with AGWPE ActiveX and Delphi VCL. The example code at SV2AGW's Yahoo forum has some useful VB code.

AGWPE (Soundcard Packet Engine) George's site. Get the latest packet engine here and look for the file which contains some example code in VB for the using the DLL. Of course, download the latest version of the standard AGWPE.

The SV2AGW Yahoo stuff is at or something like that.

Morse Code Madness This is an attempt at a morse code 'transceiver' (receive & keyboard CW) using a soundcard & transceiver. Interesting project. The FFT routine is written in VB so it is a surprise the program can copy anything. Adjusting the received audio to copy coherently is tricky (tune on the signal until until you see some characters printing; then tune some more until copy is more or less solid). At this state, the program seems capable of copying a strong signal of machine sent CW on a clear frequency as long as the speed is less than about 13 wpm. I couldn't get it to copy anything faster, despite having a fairly fast PC with lots of memory. Some unusual techniques are used in the development of the application. With a link to a C++ dll or Delphi dll (for a faster FFT) and a slightly different character identification routine, the application will be more useful and lots of fun to experiment with. This is an in progress programming activity that has not been updated since May and may possibly be abandoned. The send part needs a speed control and an interface to key the serial port DTR line. The send CW part presently keys an audio tone using DirectX7.

VB3 Morse code interface using serial RTS by K9WIS/AE9K-- This Cwkeyer was well done.

VB3 callsign to country "decoder" called DXChecker by K9WIS/AE9K -- Does a fairly nice job

Mapping conversion algorithms Geodesy by KC2GUI-- Original routines and routines converted from John Snyder's Map Projections... are available by e-mailing Victor Fraenckel at [email protected] Note: the last letter in vfraenc1 is the numeral one, not the letter ell. Put the words GEODESY VB or GEODESY DELPHI somewhere on the subject line.

Dave, AA6YQ, published source code that demonstrates the use of the public DDE interfaces in his DXLab Suite of programs at Useful if you use any of his free DXLab Suite applications. Shows how one can use dynamic data exchange (DDE), a means to communicate between Windows applications. DDE exchanges unformatted data. Error routines are nicely done. The source lacks in-code comment statements that would make it easy to understand for a beginner, a more experienced programmer shouldn't have much of a problem understanding the code and how to handle the several modules included in the code.

Back to Top

Suggestions from other Programmers


From Steve, WS7R: "I found an error in the list box click procedure in the April QST (page 43). The "end if" statement is misplaced. If this procedure is used "verbatim," the last item in the list will always be selected. I moved things around a bit to the following:
For I = 0 to ...
If List1.Selected(I) Then
label = List1.List(I)
End If
Next I
Then the various statements parsing the label follow as they don't have to be in the for-next loop. This little boo-boo might really bug a beginning programmer."

The text in the download file at QST is:
For I = 0 To List1.ListCount - 1
If List1.Selected(I) Then 'get the highlighted line
Label = List1.List(I)
Label1 = Left(Label, 29) 'get the prefix and area
lon = Right(Label, 6) 'get degrees west longitude
lat = Mid(Label, 30, 7) 'get degrees north/south latitude
Text2.Text = lon 'put in text box so it can be used
Text1.Text = lat 'put in text box so it can be used
End If

and it also works fine. The 'End If' following 'If List1.Selected(I) Then' got misplaced in the QST listing...sorry -- Steve, WB5KIA. WS7R's code works fine too.

What I did find however, is the code in the VB5LISTS folder keeps looking for the FRM file in a directory on my computer when the code is double clicked to load it into VB5 (or 4 or 6). Here is the cure:

1)Double-click the ListsVB5.vbp file to load VB and to load the project.
2)A path not found statement appears--answer YES.
3)From the Project Menu, click Add Form.
4)Click on the Existing Tab and double-click on LISTFORM.FRM.
5)Now, go to the Project Window and double click on Project(ListsVB5.vbp) and ListForm(LISTFORM.FRM) will appear.
6)Click on ListForm(LISTFORM.FRM) and the project appears correctly.
7)When you leave the project, you'll be asked to Save changes to the following files, say YES.

This situation where artifact directories appears happens when one moves a project between folders. I don't not believe it is a problem with any of the other files but if it is, you can use this technique to "correct" the problem.


FROM Jim, W2IMK/G0CKE "I have the professional version of VB 5 and about a year ago, I came across a package entitled "Sams Teach Yourself Visual Basic 6 in 21 Days Training Kit" ( As the differences between VB5 and 6 are not that great, I bought this package to improve my programming capabilities. This package consists of two large manuals and a CD with VB 6. As best I can tell, the software is complete except for the capability to make executable programs. The list price on this package is only $39.99 US ($57.95 CAN). I think this is an excellent way to become familiar with VB and decide if it is worth the extra cost to step up to a complete software package that can create executable programs."

Jim also says it works fine with Windows XP. I have a copy of the VB5 version but have not tried the disk. The text is pretty good. ( Note: Sams no longer carries it at their site but it is still available from some retailers on the web around $20-30.--WB5KIA.)

REGARDING Simple Dipole ----FROM ROB, AB8PW "I changed around your program a little to be able to convert from feet to Mhz. This was my first attempt at programming anything really usefull. Now that I know the basic function there are endless possibilities to build off of your initial code."----FROM JIM, WA6UZP "One time I wrote a neat little program for calculating and printing antenna lengths from a low frequency to a high frequency with called out step rates. You know it as:

For a=b to c step f
Next a"

Instead of outputing with the Text2.text box, try this with VB: put a picture box on your form. Use this code:

Dim Length As Double
MHz = Val(Text1.Text)
For a = MHz To (MHz + 1) Step (0.1)
Length = 468 / a
Picture1.Print a, Format(Length, "###0.00")
Next a

FROM JOHN, KD8VK "I wanted to pass this on as a quick and easy dupe checker. If someone has MS Access, create a table for each band and mode. Since the key would be the callsign, and you do not want duplicates, a simple entry in each table for a given contest would be easy to keep track of unique qsos. Of course one can make forms to log all the details and make it as complex as you want."

Back to Top

updated 1 October 2007