#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    24
    Rep Power
    0

    Should be 2 simple questions, variables and random


    1) Does ASP have functionality to assign a large block of HTML to a variable? What I am doing is emailing large reports in the body of an email. I am trying to set it up so that all i have to do is assign the body of the email to a variable. I could assign each line of the table to a variale I suppose but is there a way of doing it in one large block? I know PHP has this function, does ASP?

    2) I am using the ASPFAQS.COm Shuffle Function but the random numbers generated are the same each time I refresh the page. Is there something wrong with my functions?

    PHP Code:
        <%    
        Function 
    ShuffleinArrayneeded )
            
    ' find out how many input elements there are...
            incnt = UBound( inArray )
            ' 
    then create the output array to be the size requested via the "needed" argument
            dim outArray
            redim outArray
    needed )
            
    ' now we will select the number of values specified as "needed"...
            For i = 1 To needed
                ' 
    choose a random number from 1 to our current input array usage size...
                
    choose Intincnt Rnd(1) ) + 1
        
                
    ' put that chosen element into the next slot in the output array...
                outArray( i ) = inArray( choose )
                
                ' 
    here's the tricky part: Since we just used the "choose" element, we don't need
                
    ' it any more...we replace it with the last element of the in-use part of the array!
                inArray( choose ) = inArray( incnt )
                
                ' 
    and then we (effectivelyshrink the array!
                
    ' Next time through the loop, there will be
                ' 
    one fewer elements in the array to choose
                
    ' from...because we have (effectively) deleted
                ' 
    the one just chosen!
                
    incnt incnt 1
        
            Next
            
    ' return the shuffled output
            Shuffle = outArray
        End Function
        
        
        
        Dim pooladdress (10)
        pooladdress(0)="1314 3rd street"
        pooladdress(1)="1314 4th street" 
        pooladdress(2)="1314 5th street" 
        pooladdress(3)="1314 6th street" 
        pooladdress(4)="1314 7th street" 
        pooladdress(5)="1314 8th street" 
        pooladdress(6)="1314 9th street" 
        pooladdress(7)="1314 10th street" 
        pooladdress(8)="1314 11th street" 
        pooladdress(9)="1314 12th street" 
        
        sh = Shuffle( pooladdress, 5 )
        
        correctaddress="TEST"
        
        response.write Int( 5 * Rnd(1) ) + 1
        
        For i = 1 to 5
            Response.Write "<LI>" & i & " " & sh(i) & vbNewLine
        Next 
        
        %> 
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    24
    Rep Power
    0
    Bingo, i forgot the randomize function. Can you figure out why someties it displays blank values? the output is www.13datacenter.com/test.asp

    As for question 1, i am looking for an asp equivalent to
    HEREDOC so that I can assign a table to a variable. and then print that variable.
    Last edited by ejrhodes; May 22nd, 2003 at 04:30 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    24
    Rep Power
    0
    Got it working
    PHP Code:
        <%
        
    Randomize        
        
    Function ShuffleinArrayneeded )
            
    ' find out how many input elements there are...
            incnt = UBound( inArray ) -1  ' 
    I added the minus 1
            
    ' then create the output array to be the size requested via the "needed" argument
            dim outArray
            redim outArray( needed )
            ' 
    now we will select the number of values specified as "needed"...
            For 
    1 To needed
                
    ' choose a random number from 1 to our current input array usage size...
                choose = Int( incnt * Rnd(1) ) + 1
                response.write choose
                ' 
    put that chosen element into the next slot in the output array...
                
    outArray) = inArraychoose )
                
                
    ' here's the tricky partSince we just used the "choose" elementwe don't need
                ' 
    it any more...we replace it with the last element of the in-use part of the array!
                
    inArraychoose ) = inArrayincnt )
                
                
    ' and then we (effectively) shrink the array!
                ' 
    Next time through the loopthere will be
                
    ' one fewer elements in the array to choose
                ' 
    from...because we have (effectivelydeleted
                
    ' the one just chosen!
                incnt = incnt - 1
        
            Next
            ' 
    return the shuffled output
            Shuffle 
    outArray
        End 
    Function
        
        
        
        
    Dim pooladdress (10)
        
    pooladdress(0)="1314 3rd street"
        
    pooladdress(1)="1314 4th street" 
        
    pooladdress(2)="1314 5th street" 
        
    pooladdress(3)="1314 6th street" 
        
    pooladdress(4)="1314 7th street" 
        
    pooladdress(5)="1314 8th street" 
        
    pooladdress(6)="1314 9th street" 
        
    pooladdress(7)="1314 10th street" 
        
    pooladdress(8)="1314 11th street" 
        
    pooladdress(9)="1314 12th street" 

        
    sh Shufflepooladdress)
        
    correctaddress="TEST"
        
        
    randomize
        sh
    (IntRnd(1) ) + 1)= cstr(correctaddress)
        
    response.write "<SELECT NAME='serviceprovider'>"
        
    For 1 to 5
            Response
    .Write "<option value='" sh(i) & "'>" sh(i) & "</option>"
        
    Next 
        response
    .write "</select>"
        
    %> 

IMN logo majestic logo threadwatch logo seochat tools logo