|
From: ll on 3 Mar 2008 17:13 Hi, I'm having a little trouble with the following code. For some reason, when x=true, both parts of the If Then...Else statement are followed, and the data winds up being in the Data Source in the Else section, even though x tests positive as true (the response.write statement). Could this be a problem with the variable or perhaps grouping? Thanks, Louis ======================== 'begin conditional connection section x=true If x=true Then Function GetConnection() dim Conn: Set Conn = CreateObject("ADODB.Connection") Conn.open "Provider=SQLOLEDB.1;" &_ "Persist Security Info=False;" &_ "User ID=CopRandW;Password=Pharm_1110;" &_ "Initial Catalog=cop_pcms;" &_ "Data Source=COP-CPB-DAT" set GetConnection = Conn end function response.write("hi - x is true!") Else Function GetConnection() dim Conn: Set Conn = CreateObject("ADODB.Connection") Conn.open "Provider=SQLOLEDB.1;" &_ "Persist Security Info=False;" &_ "User ID=CopRandW;Password=Pharm_1110;" &_ "Initial Catalog=cop;" &_ "Data Source=COP-CPB-DAT" set GetConnection = Conn end function response.write("hi - x is false!") End If 'end conditional connection section
From: Bob Barrows [MVP] on 3 Mar 2008 20:27 ll wrote: > Hi, > I'm having a little trouble with the following code. For some reason, > when x=true, both parts of the If Then...Else statement are followed, > and the data winds up being in the Data Source in the Else section, > even though x tests positive as true (the response.write statement). > Could this be a problem with the variable or perhaps grouping? > > Thanks, > Louis > > ======================== > 'begin conditional connection section > x=true > If x=true Then > Function GetConnection() Your subject is misleading: you should have said "conditional function declarations" which is not possible in vbscript (http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx). Both functions get declared and probably cause an "already declared" error. You need to create a single function with arguments whose values get set when you call it in the if construct. -- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
From: ll on 4 Mar 2008 10:14 On Mar 3, 7:27 pm, "Bob Barrows [MVP]" <reb01...(a)NOyahoo.SPAMcom> wrote: > ll wrote: > > Hi, > > I'm having a little trouble with the following code. For some reason, > > when x=true, both parts of the If Then...Else statement are followed, > > and the data winds up being in the Data Source in the Else section, > > even though x tests positive as true (the response.write statement). > > Could this be a problem with the variable or perhaps grouping? > > > Thanks, > > Louis > > > ======================== > > 'begin conditional connection section > > x=true > > If x=true Then > > Function GetConnection() > > Your subject is misleading: you should have said "conditional function > declarations" which is not possible in vbscript > (http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx). Both > functions get declared and probably cause an "already declared" error. You > need to create a single function with arguments whose values get set when > you call it in the if construct. > > -- > Microsoft MVP - ASP/ASP.NET > Please reply to the newsgroup. This email account is my spam trap so I > don't check it very often. If you must reply off-line, then remove the > "NO SPAM" Thanks for the leads! Yes, now that the arguments are within one function, it works much better.
|
Pages: 1 Prev: Collect SQL String using script Next: Dave Clarke Presents Red Three download free MP3 |