To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Oct 1st, 2005, 09:22 AM   #1
Edward233
New Member
 
Join Date: Oct 05
Posts: 15
Edward233 is an unknown quantity at this point (<10)
Resolved [RESOLVED] Help with VB6 code cleanup

Hi all

I have this project that im doing and some of the code is from another real earlyer version and im trying to clean it up a bit or alot. Here is the code im working on.

Option Base 1
Dim zflag As Integer
Dim la As Integer 'latdir number
Dim lo As Integer 'longdir number
Dim elat As Double 'geocentric latitude (degrees)
Dim elon As Double 'geocentric longitude (degrees)
Dim iday As Integer 'day of ambient table
Dim imonth As Integer 'month of ambient table
Dim iyear As Integer 'year of ambient table
Dim slat As Double 'sine of geocentric latitude
Dim clat As Double 'cosine of geocentric latitude
Dim dis As Double 'geocentric distance (kms)
Dim wlon As Double 'western longitude (hours)
Dim ajd As Double 'astronomical julian day of the month
Dim aday As Double 'day of the year
Dim gast As Double 'correction for nutation and aberration
Dim jds As Double 'julian day for space
Dim lha0s 'local hour angle of sun (degrees)
Dim dhas As Double 'hour angle displacement of sun
Dim sdelta As Double 'declination of first day (sun)
Dim dsdec As Double 'dec. displacement of two days (sun)
Dim pcmoon As Integer 'percentage illumination of the moon
Dim lha0 As Double 'local hour angle of moon (degrees)
Dim dha As Double 'hour angle displacement of moon
Dim delta As Double 'declination of the first day (moon)
Dim ddec As Double 'dec. displacement of two days (moon)
Dim lha00 As Double 'initial value of lha0
Dim dha0 As Double 'initial value of dha
Dim delta0 As Double 'initial value of delta
Dim ddec0 As Double 'initial value of ddecdim
Dim id, im, iy As Long 'calender date from caldat
Dim idow As Integer ' day of the week number
Dim ut As Double
Dim sset As Double 'sunset (hours)
Dim srise As Double 'sunrise (hours)
Dim mrise As Double 'moonrise (hours)
Dim mset As Double 'moonset (hours)
Dim az1 As Double 'solar azimuth as sunset (degrees)
Dim az2 As Double 'solar azimuth as sunrise (degrees)
Dim el1 As Double 'solar elevation
Dim CTW(2) As Double ' civil twilight (eve,morn) (hours)
Dim NTW(2) As Double ' nautical twilight (eve,morn) (hours)
Dim ATW(2) As Double ' astronomical twilight (eve,morn) (hours)
Dim TOTAL As Integer ' number of pieces of data
Dim HR(50) As Integer ' array of hours
Dim mn(50) As Integer ' array of minute
Dim AZ(50) As Double ' array of lunar azimuths / half hour
Dim ELEV(50) As Double ' array of lunar elevations / half-hour (degrees)
Dim AZS(50) As Double ' array of solar azimuths / half hour
Dim ELEVS(50) As Double ' array of solar elevations / half-hour (degrees)
Dim WXFACT(50) As Integer ' WX forecast factors
Dim ILLM(50) As Double ' modified illuminance
Dim IRRM(50) As Double ' modified irradiance
Dim range As Double
Dim inputgood As Boolean 'dates and lat/long goodF
'for LIGHT
Dim moonrise(31) As Double 'hours
Dim moonset(31) As Double 'hours
Dim sunrise(31) As Double 'hours
Dim sunset(31) As Double 'hours
Dim dlhrs(31) As Double 'total daylight hours (hours)
Dim atw1(31) As Double 'evening astronomical twilight (hours)
Dim ntw1(31) As Double 'evening nautical twilight (hours)
Dim ctw1(31) As Double 'evening civil twilight (hours)
Dim ctw2(31) As Double 'morning civil twilight (hours)
Dim ntw2(31) As Double 'morning nautical twilight (hours)
Dim atw2(31) As Double 'morning astronomical twilight (hours)
Dim pcmoon2(31) As Integer 'percentage illumination of moon
Dim idow2(31) As Integer 'day of the week
Dim illum(50) As Double ' array of illum/half-hour
Dim irrad(50) As Double ' array of irrad/half-hour uw/m2)
'
Public tLocationName As String 'Station Information Variables
Public tStationID As String 'for info to be passed from
Public tPoliticalID As String 'StationAddition form to frmMain


I now it looks messey but any help is appreciated
Ed
Edward233 is offline   Reply With Quote
Old Oct 1st, 2005, 09:37 AM   #2
Keithuk
Frenzied Member
 
Keithuk's Avatar
 
Join Date: Jan 04
Location: Staffordshire, England
Posts: 1,867
Keithuk has a spectacular aura about (125+)Keithuk has a spectacular aura about (125+)
Re: Help with VB6 code cleanup

Your code will look better if you put it in a code window.

[ vbcode ]
'Your code
[ /vbcode ]

Remove the spaces either side of vbcode.

That code is only declaring the variables, are they all needed?
__________________
Keith

I've been programming with VB for 14 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.


Last edited by Keithuk; Oct 1st, 2005 at 09:40 AM.
Keithuk is offline   Reply With Quote
Old Oct 1st, 2005, 10:48 AM   #3
Dave Sell
Software Architect
 
Dave Sell's Avatar
 
Join Date: Mar 04
Location: /dev/null
Posts: 2,889
Dave Sell has a spectacular aura about (125+)Dave Sell has a spectacular aura about (125+)
Re: Help with VB6 code cleanup

Try using a Hungarian naming convention. Instead of:

VB Code:
  1. Dim elat As Double 'geocentric latitude (degrees)
  2.  

try:

VB Code:
  1. Dim dbl_GeoCentricLatitude As Double

and get rid of the comment clutter.
__________________
Don't solve problems which don't exist.

"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

2 idiots don't make a genius.
Dave Sell is offline   Reply With Quote
Old Oct 1st, 2005, 10:54 AM   #4
paralinx
Fanatic Member
 
paralinx's Avatar
 
Join Date: Jun 05
Location: Michigan
Posts: 982
paralinx  is on a distinguished road (40+)
Re: Help with VB6 code cleanup

You can also use commas:
VB Code:
  1. Dim slat As Double, clat As Double, dis As Double, dhas As Double, sdelta As Double
and yes i agree you should use hungarian notation and intercap method for your variables:

VB Code:
  1. Dim dblDay or Dim dbl_Day
paralinx is offline   Reply With Quote
Old Oct 1st, 2005, 11:21 AM   #5
Jacob Roman
Banned
 
Jacob Roman's Avatar
 
Join Date: Aug 04
Location: Cocoa Beach, FL Chit Chat Posts: 500+
Posts: 4,371
Jacob Roman is a jewel in the rough (200+)Jacob Roman is a jewel in the rough (200+)Jacob Roman is a jewel in the rough (200+)
Re: Help with VB6 code cleanup

My style with variables is real English. No abreviated words, or letters to represent
words. Like for example

slat would be Sin_Latitude
clat would be Cos_Latitude

It makes your code a lot more readable in the end.
Jacob Roman is offline   Reply With Quote
Old Oct 3rd, 2005, 02:42 AM   #6
penagate
Super Moderator
 
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)
Re: [RESOLVED] Help with VB6 code cleanup

Holy cow. Not only is that a truckload of variables, it looks like they are all Public too. That is extremely bad design. You should make sure all the variables have the smallest scope as possible. Usually this is local in a procedure or Private in a class/form. Only in a few cases would you want Public variables.

If you have lots of code in standard modules then move bits that perform specific tasks into classes and use instances of them instead of standard procedures. Use Properties and Private variables instead of Public variables. You could have a Moon class or Light class and have related properties in those.

Also, Option Base 1 slows array work down because there is an extra addition (+1 to the index) required when accessing elements.
penagate is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:52 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.