VB COM (web app) Critique 
Author Message
 VB COM (web app) Critique

Hello folks,
I am still a beginner at VB, so I am ever-so concerned with code efficiency.
Below is my code, and if some of you could be so kind, I would greatly
appreciate any help with streamlining the syntax.  I have it doing what I
want it to, but I am sure there are many things that I could have done
better.  Also, I am pretty sure that objRs(2) should be set up as an
enumeration.  Right now it just returns an integer value from the database
that should be translated to its proper string, but I am not really sure how
to set that up (should it be an array?).
For example:
    1 = red
    2 = blue
    3 = green
    etc.
Thanks in andvance for any help.

<code begins>
Option Explicit

Private objConn As New ADODB.Connection
Private objCmd As New ADODB.Command
Private objRs As New ADODB.Recordset
'Private objErrors As New ADODB.Errors
'Private objErr As New ADODB.Error

Public Sub OnStartPage(ByRef rScriptingcontext As ScriptingContext)
    Set gAspAppl = rScriptingcontext.Application
    Set gAspReq = rScriptingcontext.Request
    Set gAspResp = rScriptingcontext.Response
    Set gAspServer = rScriptingcontext.Server
    Set gAspSession = rScriptingcontext.Session
End Sub

Public Sub OnEndPage()
    Set gAspAppl = Nothing
    Set gAspReq = Nothing
    Set gAspResp = Nothing
    Set gAspServer = Nothing
    Set gAspSession = Nothing
End Sub

Public Sub WebMain(SQL, database, flag)

    Dim style, cityCounty, city, county, zipCode, bed, bath, anyprice, min,
max As String
    Dim pool, water, garage, security, {*filter*}, acreage As String

    Dim strConn, sqlString As String
    Dim count As Integer

    strConn = database
    sqlString = SQL

    With objConn
        .ConnectionTimeout = 30
        .CommandTimeout = 30
        .Open (database)
    End With

    style = gAspReq.Form("style")
    cityCounty = gAspReq.Form("cityCounty")
    city = gAspReq.Form("city")
    county = gAspReq.Form("county")
    zipCode = gAspReq.Form("zipCode")
    bed = gAspReq.Form("bed")
    bath = gAspReq.Form("bath")
    anyprice = gAspReq.Form("anyprice")
    min = gAspReq.Form("min")
    max = gAspReq.Form("max")
    pool = gAspReq.Form("pool")
    water = gAspReq.Form("water")
    garage = gAspReq.Form("garage")
    security = gAspReq.Form("security")
    {*filter*} = gAspReq.Form("{*filter*}")
    acreage = gAspReq.Form("acreage")

    objRs.Open sqlString, objConn, adOpenDynamic

    Do While Not objRs.EOF
         count = count + 1
         flag = True
         gAspResp.Write "<br><p>" & count & ".<strong>&nbsp;&nbsp;Property
Type:</strong> " & objRs(2) <-- this is the array value
         gAspResp.Write " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Listing
Date:</strong> " & objRs(3)
         gAspResp.Write "
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Address:</strong> " & objRs(5) & " " &
objRs(6) & " " & objRs(7) & "&nbsp;&nbsp;&nbsp;" & objRs(8) & "</p>"
         objRs.MoveNext
    Loop

    If (count = 0) Then
        gAspResp.Write "Your search returned <strong>0</strong> results."
    End If

    objRs.Close

    Set objRs.ActiveConnection = Nothing

    If (count = 0) Then
        flag = False
    End If

End Sub
<end of code>



Tue, 21 Oct 2003 22:27:47 GMT  
 VB COM (web app) Critique
hi.

Some fast answers (doing very little for speed):

Quote:
>     Dim pool, water, garage, security, {*filter*}, acreage As String

Only acreage is a string.  The others are variants.  Write As string for
everyone.

Quote:
>     With objConn

Good.
Use it for gAspReq and the others too.

Strings concatenations are slow.
For instance create a long enough string and insert text with Mid$ (don't
forget the dollar sign).

/OF


Quote:
> Hello folks,
> I am still a beginner at VB, so I am ever-so concerned with code
efficiency.
> Below is my code, and if some of you could be so kind, I would greatly
> appreciate any help with streamlining the syntax.  I have it doing what I
> want it to, but I am sure there are many things that I could have done
> better.  Also, I am pretty sure that objRs(2) should be set up as an
> enumeration.  Right now it just returns an integer value from the database
> that should be translated to its proper string, but I am not really sure
how
> to set that up (should it be an array?).
> For example:
>     1 = red
>     2 = blue
>     3 = green
>     etc.
> Thanks in andvance for any help.

> <code begins>
> Option Explicit

> Private objConn As New ADODB.Connection
> Private objCmd As New ADODB.Command
> Private objRs As New ADODB.Recordset
> 'Private objErrors As New ADODB.Errors
> 'Private objErr As New ADODB.Error

> Public Sub OnStartPage(ByRef rScriptingcontext As ScriptingContext)
>     Set gAspAppl = rScriptingcontext.Application
>     Set gAspReq = rScriptingcontext.Request
>     Set gAspResp = rScriptingcontext.Response
>     Set gAspServer = rScriptingcontext.Server
>     Set gAspSession = rScriptingcontext.Session
> End Sub

> Public Sub OnEndPage()
>     Set gAspAppl = Nothing
>     Set gAspReq = Nothing
>     Set gAspResp = Nothing
>     Set gAspServer = Nothing
>     Set gAspSession = Nothing
> End Sub

> Public Sub WebMain(SQL, database, flag)

>     Dim style, cityCounty, city, county, zipCode, bed, bath, anyprice,
min,
> max As String
>     Dim pool, water, garage, security, {*filter*}, acreage As String

>     Dim strConn, sqlString As String
>     Dim count As Integer

>     strConn = database
>     sqlString = SQL

>     With objConn
>         .ConnectionTimeout = 30
>         .CommandTimeout = 30
>         .Open (database)
>     End With

>     style = gAspReq.Form("style")
>     cityCounty = gAspReq.Form("cityCounty")
>     city = gAspReq.Form("city")
>     county = gAspReq.Form("county")
>     zipCode = gAspReq.Form("zipCode")
>     bed = gAspReq.Form("bed")
>     bath = gAspReq.Form("bath")
>     anyprice = gAspReq.Form("anyprice")
>     min = gAspReq.Form("min")
>     max = gAspReq.Form("max")
>     pool = gAspReq.Form("pool")
>     water = gAspReq.Form("water")
>     garage = gAspReq.Form("garage")
>     security = gAspReq.Form("security")
>     {*filter*} = gAspReq.Form("{*filter*}")
>     acreage = gAspReq.Form("acreage")

>     objRs.Open sqlString, objConn, adOpenDynamic

>     Do While Not objRs.EOF
>          count = count + 1
>          flag = True
>          gAspResp.Write "<br><p>" & count & ".<strong>&nbsp;&nbsp;Property
> Type:</strong> " & objRs(2) <-- this is the array value
>          gAspResp.Write " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Listing
> Date:</strong> " & objRs(3)
>          gAspResp.Write "
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Address:</strong> " & objRs(5) & " "
&
> objRs(6) & " " & objRs(7) & "&nbsp;&nbsp;&nbsp;" & objRs(8) & "</p>"
>          objRs.MoveNext
>     Loop

>     If (count = 0) Then
>         gAspResp.Write "Your search returned <strong>0</strong> results."
>     End If

>     objRs.Close

>     Set objRs.ActiveConnection = Nothing

>     If (count = 0) Then
>         flag = False
>     End If

> End Sub
> <end of code>



Sat, 25 Oct 2003 21:40:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB COM Critique

2. Upgrade COM + App on Web Server

3. COM and Web App

4. Passing structures from C++ app to a VB client app through Network connection using COM

5. COM and Web App

6. VB COM Objects from a VB App

7. Besoin de critiques sur mon appli' VB

8. Problem passing VB COM+ ASP Request object to .NET component System.Web.HTTPRequest through COM interop

9. VB COM object causing web site to fail

10. vb app over internet with SQL or com?

11. Help-- Problem with Sharing data betweeb a VC++ COM and a VB app

12. convert VB app to com

 

 
Powered by phpBB® Forum Software