Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if statement 1

Status
Not open for further replies.

aarellano

MIS
Oct 22, 2007
168
US
Hello,

I have an asp page, that builds an xml file.

I would like to insert an if statement but it does not seem to be working. I am not really sure what i am doing wrong
any help is always appreciated!!!
Here is my code
Code:
mo =  rs("mo")


dddpva = rs("dddpva")
act.WriteLine"<item month=""" & mo & """ value= """ & dddpva & """/>" 

& vbcrlf




' move to the next record
rs.movenext
loop

' All non repetitive xml on bottom goes here
act.WriteLine("</items>")


' close the object (xml)
act.close


' Writes a link to the newly created xml document in the browser
response.write "<a href='rev.xml'>revenue</a> (.xml) has been 

created <br>"
response.write "on  " & now() & "<br>"
%>

I tried to insert
Code:
<% if rs("mo").value = 1 then response.write "January"  end if%>
after mo=
but that is not really working
 
nix the .value

Code:
if rs("mo")[s].value[/s] = 1 then response.write "January"  end if

or, since you already have the value in a variable called "mo" (your first line), just use it

Code:
mo =  rs("mo")
if mo = 1 then response.write "January"  end if


--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
that did work on the webpage

Julyrevenue (.xml) has been created

but not in my xml page
Code:
'Loop to output all the query results to the xml document
do while not rs.eof


mo =  rs("month")
if mo = 07 then response.write "July" end if

dddpva = rs("dddpva")
act.WriteLine"<item month="""[COLOR=red]&  mo &[/color] """ value= """ & dddpva & """/>" 

& vbcrlf




' move to the next record
rs.movenext
loop

' All non repetitive xml on bottom goes here
act.WriteLine("</items>")


' close the object (xml)
act.close
 
Code:
if mo = 07 then response.write "July" end if

what do you get if you output the value of "mo" to the screen?

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
if I try
Code:
if mo = 07 then response.write "July" end if
the page loads and it gives me
Julyrevenue (.xml) has been created
on 7/14/2009 11:19:14 AM
it adds the July part next to the revenue

but the xml looks like this
Code:
<?xml version="1.0" ?> 
- <items>
  <item month="07" value="260119.84" /> 
  </items>
what I am going for is to get the 07 or any other number to say the Month
 
I even tried

Code:
act.WriteLine"<item month=""" &  <%if mo = 07 then response.write "July" end if %> & """ 

value= """ & dddpva & """/>" & vbcrlf

but I get the below error

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/xmldata/revenue.asp, line 47, column 33
act.WriteLine"<item month=""" & <%if mo = 07 then response.write "July" end if
--------------------------------^
 
I also tried


Code:
mo = if rs("month") = 07 then "July" end if

but get the following error
Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/xmldata/revenue.asp, line 42, column 5
mo = if rs("month") = 07 then "July" end if
----^
 
your code is all over the place...

first of all you can't do this in ASP

Code:
myValue = if condition then a end if

you need to split it up into two statments

Code:
if condition then
	myVal = a
end if


or you can write an inline if statement as follows

Code:
function iif(c,t,f)
	if c then ' if condition is true
		return t ' return true value
	else 
		return f ' return false value
	end if
end function

and use it as follows

Code:
	myVal = iif(condition,truevalue,falsevalue)


also, vbscript has a built in function to get the name of the month, called monthName so

Code:
	response.write monthName(07)

would output July

So, with that said (or read), the following
Code:
act.WriteLine"<item month=""" &  <%if mo = 07 then response.write "July" end if %> & """ value= """ & dddpva & """/>" & vbcrlf

should work with

Code:
act.WriteLine"<item month=""" &  monthName(mo) & """ value= """ & dddpva & """/>" & vbcrlf

if you only want to show items for July, then put an if before it

Code:
if mo = 7 then
	act.WriteLine"<item month=""" &  monthName(mo) & """ value= """ & dddpva & """/>" & vbcrlf
end if

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
that is awsome!!! thank you so very, very much!!! I really appreciate the help. I used monthName that did the trick. But in the process I learned functions!!!!! thanks!!!!
I am building a dashboard in adobe flex and the most inexpensive fastest way to get the data out of my db to xml was asp.

again thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top