SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to pull string data into single vairable using for next or do while in array

    Thought about putting into array image, than doing split function. Have a counter set up to cnt number of files that was uploaded to file.
    In this case cnt = 4. I want to make this dynamic as I have know idea how many images will be loaded. Want to control all data going into database.

    strimage = Elaine.jpg , Elaine2.jpg , Elaine4.jpg , Elaine12.jpg

    cnt = 4

    imagear = strimage

    for x = 0 to cnt - 1

    a = Split(imagear, ",")
    image(x) = a(x)
    image(x+1) = a(x+1)
    .
    .
    next

    Any help here would be greatly appreciated.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <%
    Dim strimage,arrimage
    
    strimage = "Elaine.jpg, Elaine2.jpg, Elaine4.jpg, Elaine12.jpg"
    
    arrimage = split(strimage,",")
    
    Response.write "Total Images: " & UBound(arrimage)+1 & "<br />"
    
    for x = 0 to UBound(arrimage)
    	Response.write "Image " & (x+1) & " : " & arrimage(x) & "<br />"
    next
    
    %>

    Ref:

    Split Function: http://www.w3schools.com/vbscript/func_split.asp

    UBound Function: http://www.w3schools.com/vbscript/func_ubound.asp
    Last edited by Flakes; May 20, 2013 at 04:37. Reason: added reference

  3. #3
    SitePoint Member
    Join Date
    May 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Flakes, thanks a lot. Another question, I'm curious if i wanted to assign session variable to this like Session("Image " & (x+1)) & " = " & arrimage(x). What would the correct syntax be? Also to store this array into sql database would you just loop thou it? Again thanks for your help.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <%Dim strimage,arrimage
    strimage = "Elaine.jpg, Elaine2.jpg, Elaine4.jpg, Elaine12.jpg"
    
    arrimage = split(strimage,",")
    for x = 0 to UBound(arrimage)
        Session("Image" & (x+1)) = arrimage(x)
    next
    %>
    No Response.write or anything ... Session calls are "header" functions and so must be made before anything is output to the web browser.

    http://www5.brinkster.com/hiflyer/db/dbtest.asp will give you some help with ASP and SQL. It is based around MS Access, but the principles are the same for any database.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Member
    Join Date
    May 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANK YOU GUYS, This saved me a lot of research time. ASP has some different rules when it comes to syntax. I guess its gonna take some time to learn it. Again thanks.


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
  •