Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

3 way if statement...

Options
  • 08-12-2008 3:52pm
    #1
    Registered Users Posts: 224 ✭✭


    Hi,
    I am trying to get a 3 way if statement working. Basically i have acolumn called Currency that holds the following values "Euro","Sterling" or "Dollar".

    Here is what i have come up with (please dont laugh). I think i have the bones of right.


    ********************

    Function GetFlags(rs)
    Dim EuroFlag
    Dim SterlingFlag
    Dim DollarFlag

    EuroFlag="siteimgs/eu.gif"
    SterlingFlag="siteimgs/gb.gif"
    DollarFlag="siteimgs/us.gif"

    If recordset.Fields("Currency").Value = 'Euro'
    Then Response.Write EuroFlag

    Elseif recordset.Fields("Currency").Value = 'Sterling'
    Then Response.Write SterlingFlag

    Elseif recordset.Fields("Currency").Value = 'Dollar'
    Then Response.Write DollarFlag

    End IF
    End Funcion

    *******************

    And i use this to call the values from the asp page.

    <%response.write(GetFlags(rsAllQuotes))%>

    Can anyone help me to get the images returned?


Comments

  • Registered Users Posts: 2,494 ✭✭✭kayos


    ahhh maybe you could try writing out the img html tags


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    What kayos said. You could also use a Select Case (or switch in other languages) instead of the if statement.


  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    kayos wrote: »
    ahhh maybe you could try writing out the img html tags

    Are you referring to the Response.Write part as in

    If recordset.Fields("Currency").Value = 'Euro'
    Then Response.Write <img='EuroFlag'>

    or something like that.


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    Yeah that's what he means, it would be something like this though:

    <img src='EuroFlag.jpg' alt='Euro Flag'/>

    I'd agree with Phil on the case statement, you never know when you might add more flags/options and the If will get to be a pain then. Also, the case statement should perform slightly better when you add more options.


  • Registered Users Posts: 2,494 ✭✭✭kayos


    If adding other options at a later date would be likely I would honestly move the path to the images to the DB. Cuts out the need for any if or switch statements as you would just be pulling the whole lot from the DB so adding lets say the yen would involve an update to the DB and dropping the Japan flag into the images dir.

    If you where to add the Yen to the system as it stands it would be update DB, add image to dir and make a code change.


  • Advertisement
  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    kayos wrote: »
    If adding other options at a later date would be likely I would honestly move the path to the images to the DB. Cuts out the need for any if or switch statements as you would just be pulling the whole lot from the DB so adding lets say the yen would involve an update to the DB and dropping the Japan flag into the images dir.

    If you where to add the Yen to the system as it stands it would be update DB, add image to dir and make a code change.

    This is a good call, I would move the paths to a DB and write a stored proc that takes an id and returns the appropriate img uri.


  • Closed Accounts Posts: 2,268 ✭✭✭mountainyman


    Why don't you use a select case or multiple if statements?
    The statement will only fire if the condition is met so why the else ifs?

    EXAMPLE STORED PROCEDURE
    -- GETURL 1

    CREATE PROCEDURE dbo.GetURL (@URLID as INTEGER) AS
    (
    RETURN URL
    FROM Paths pa
    WHERE pa.ID=@URLID
    )


Advertisement