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
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > ASP, VB Script

Reply Post New Thread
 
Thread Tools Display Modes
Old Oct 1st, 2005, 08:18 AM   #1
Edward233
New Member
 
Join Date: Oct 05
Posts: 15
Edward233 is an unknown quantity at this point (<10)
Resolved [RESOLVED] VB 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:34 AM   #2
kaihirst
Fanatic Member
 
kaihirst's Avatar
 
Join Date: Jul 05
Location: The Resaurant At the End of The Universe
Posts: 633
kaihirst will become famous soon enough (80+)
Re: VB code cleanup

Hi,

The first thing I would do is get rid of the AS keywords, you dont need it and it actually uses memory (sight amount, but still more that you should be using...) and use something like this.

1. dim intVariable
' int signifies to the programmer that it is integer. good practice and makes easier for reading

2. dim intVariable : variable value
' use the colon to assign values to the variable before commening. even if it is a logical boolean operator statemetn, still do it. sves on space and easier to read, and no need to call the valieable again just to assign a simpole form value, variable value, boolean command, test command etc.

3. dim strArray(31)
'if you are using arrays, declare the aray details below the array declaration, makes forf eaiser referenceing and reading. In addition to this, what you could do is you can be arrissed restructureing your code, is use dynamic arrays called by the Scripting model and JIT complier, therewby saving space but the first thing I would do, is decalre the array contents directly below the instancde decalration.

4. public variables.
' really, all these variables should be in a private functions, not an option base, and set all your variables within this framework, not just three of them ( unless very specific circumstances overrules this, but rarely such an occurrence does.) then all your code within functions, subs cal call on them when neeed. It also makes for good housekeeping.
So it should look like this

private function var-declaration

' al variavbles decalred within this

end function

then at the bottom of your code.

private function var_destroy

'all nothing and null declarations set here

end function

you could use classes if you wanted to, this is also a visable option, but requires a good knowledge of VBScript coding to create a new instance, then use it.

with the amount of variables you have, you can get rid of the size of the coding, but you can make it for easier followign reading and parsing for the compiler.

If you follow these guidelines, the applicaiton should actually run faster, as it has less to trawl thorough.

one other thing. It is the best policy for this type of code to be inputted into an asp page, then use a virtual SSI to include it. such like this

<!-- #include virtual="//include/app_code.asp" -->
<doc type blah blah blah>
the code will be given prioroty to toe parser and compiler, and will be instanced into the page before any Transactable objects (HTML, ASP, Javascript, Jscript, ECMA and CGI raw code.) are initiated into the page.

Mkes for very good practice, if not aadvanced page page building.

hope tjhis helps

Kai
__________________
As the information I give is useful in its nature, consider using the RATE POST feature located on the bottom left of this post please..

A few things that make a good Developer a Great One.
Methodical and a thorough approach to research and design inevitably leads to success.
Forward thinking is the key to Flow of control.
Never test in the design environment, always test in real time, you get the REAL results.
CBSE & OOSE are the same animal, they just require different techniques, and thinking.
SEO is a globe of objectives, SE rankings is an end to a means for these objectives, not part of them.
The key to good design is explicit attention to both detail and response.
Think Freely out of the "Box" you're in..... You will soar to better heights.

Kai Hirst - MSCE, MCDBA, MCSD, MCP, MCAP, MSCT

kaihirst is offline   Reply With Quote
Old Oct 2nd, 2005, 04:33 AM   #3
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,161
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Re: VB code cleanup

For some reason, I get a feeling that this is not ASP... but is VB6.

Edward, is this a web app or a VB6 app?
mendhak is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > ASP, VB Script


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 05:09 AM.





Acceptable Use Policy

Internet.com
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.