|
|
#1 |
|
New Member
Join Date: Oct 05
Posts: 15
![]() |
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 |
|
|
|
|
|
#2 |
|
Fanatic Member
Join Date: Jul 05
Location: The Resaurant At the End of The Universe
Posts: 633
![]() |
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. Kai Hirst - MSCE, MCDBA, MCSD, MCP, MCAP, MSCT |
|
|
|
|
|
#3 |
|
ASP.NET Moderator
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 37,382
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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? |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|