SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Variables

  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Variables

    Hi, what is a difference between:

    dim temp
    set temp = 1

    vs

    dim temp
    temp = 1

    Thanks

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Set is used for creating an instance of an Object, not a variable.

    If you use Option Explicit you'll probably find that the first example throws an error. Something like:
    Code:
    Microsoft VBScript runtime error '800a01a8'
    
    Object required: '[number: 1]'
    An example of setting an instance of an object is:
    Code:
    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for help.

    I have one more problem in my script:
    I declared variable:


    dim sqlCount, dynCount
    dim count
    dim maxCount

    count = 0
    maxCount = 7000


    next I execute sql for count records in table of my database:

    sqlCount = "select count(*) NUMROWS from table"
    set dynCount = session("OraDatabase").createdynaset(sqlCount, 0)
    count = dynCount.Fields("NUMROWS").Value
    set dynCount = nothing


    and in IF statement:

    if count>maxCount then ...

    always is true even variable "count" is smaller then maxCount. I make something wrong?

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Land of 10k Lakes
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alno View Post
    Thanks for help.

    I have one more problem in my script:
    I declared variable:


    dim sqlCount, dynCount
    dim count
    dim maxCount

    count = 0
    maxCount = 7000

    next I execute sql for count records in table of my database:

    sqlCount = "select count(*) NUMROWS from table"
    set dynCount = session("OraDatabase").createdynaset(sqlCount, 0)
    count = dynCount.Fields("NUMROWS").Value
    set dynCount = nothing

    and in IF statement:

    if count>maxCount then ...

    always is true even variable "count" is smaller then maxCount. I make something wrong?
    I believe it should be:

    Code:
    sqlCount = "select count(NUMROWS) AS NRows  from table"
    set dynCount = session("OraDatabase").createdynaset(sqlCount, 0)
    count = dynCount("NRows") 
    set dynCount = nothing
     
     
    if Cint(count)>Cint(maxCount) then ...
    Least thats how I would do it.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,250
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I'd be adverse to using "count" as a variable name. As it has special meaning in a db query I'm afraid I'd mess up somewhere and get unpredictable results if not outright errors. Worse case - I wouldn't notice right away

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Land of 10k Lakes
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    I'd be adverse to using "count" as a variable name. As it has special meaning in a db query I'm afraid I'd mess up somewhere and get unpredictable results if not outright errors. Worse case - I wouldn't notice right away
    I missed that and I agree, I usually name it something like "intCount".


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •