|
-
Oct 1st, 2005, 08:22 AM
#1
Thread Starter
New Member
[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
-
Oct 1st, 2005, 08:37 AM
#2
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?
Last edited by Keithuk; Oct 1st, 2005 at 08:40 AM.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Oct 1st, 2005, 09:48 AM
#3
Re: Help with VB6 code cleanup
Try using a Hungarian naming convention. Instead of:
VB Code:
Dim elat As Double 'geocentric latitude (degrees)
try:
VB Code:
Dim dbl_GeoCentricLatitude As Double
and get rid of the comment clutter.
Nobody knows what software they want until after you've delivered what they originally asked for.
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.
-
Oct 1st, 2005, 09:54 AM
#4
Fanatic Member
Re: Help with VB6 code cleanup
You can also use commas:
VB Code:
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:
Dim dblDay or Dim dbl_Day
-
Oct 1st, 2005, 10:21 AM
#5
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.
-
Oct 3rd, 2005, 01:42 AM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|