Flakes Posted March 26, 2010 Posted March 26, 2010 hi all, i currently in the process of writing up an electronic system for logging toner usage through out the school and have hit a snag with some of my code: if fault = fault and black = true Then response.write("faulty black") 'test clause response.end 'test clause rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 ElseIf fault = null and black = true Then response.write("faulty null, black replaced") 'test clause response.end ' test clause rsAddRoom.fields("usedblack") = rsAddRoom("usedblack") + 1 End if the above if statement is the part of my code that is not working, for some strange reason the code within the if statement is not executed even when the values for fault and black correspond to the if statement criteria. i tested these values further up to see if i could identify the problem but i cant see anything wrong with the code. Dim fault Dim black fault = Request.Form("fault") black = Request.Form("black") response.write ("val fault: " & fault & " black: " & black) response.end 'test clause the above code verified that black = true and fault = fault so i have no idea why the if statement is being ignored. Any ideas?
tommccann Posted March 26, 2010 Posted March 26, 2010 i know that many different coding languages now that i get constantly muggled up but shouldnt it be == please ignore my ramblings if i am way off:confused:
webman Posted March 26, 2010 Posted March 26, 2010 Firstly, it looks like you're comparing fault to itself. Is this what you're wanting to do? Secondly, try wrapping them in brackets: if (fault = fault) and (black = true) Then
powdarrmonkey Posted March 26, 2010 Posted March 26, 2010 i know that many different coding languages now that i get constantly muggled up but shouldnt it be == please ignore my ramblings if i am way off:confused: It looks like Visual Basic, so the equality operator is =.
Flakes Posted March 26, 2010 Author Posted March 26, 2010 actually webman i think your right, asp is probably seeing both as the variable rather than the variable and contents... tommccann, i know what you mean but in asp it is just one = sign.
u8dmtm Posted March 26, 2010 Posted March 26, 2010 Does this work?: if fault = "fault" and black = true Then response.write("faulty black") 'test clause response.end 'test clause rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 Else If fault = null and black = true Then response.write("faulty null, black replaced") 'test clause response.end ' test clause rsAddRoom.fields("usedblack") = rsAddRoom("usedblack") + 1 End if End if
Flakes Posted March 26, 2010 Author Posted March 26, 2010 (edited) sorry lads got called off to refill some toner cartridges (ironic really) >.< changed fault to equal true instead of fault(also changed on the form) and using this code: if fault = true and black = true Then response.write("faulty black") response.end rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 ElseIf fault = null and black = true Then response.write("faulty null, black replaced") response.end rsAddRoom.fields("usedblack") = rsAddRoom("usedblack") + 1 End if still no different. ill try it with the brackets, see if that makes a difference (didnt know you could use them in asp?) ARGH! *bangs head... still not working, tried with this: if (fault = true) and (black = true) Then response.write("faulty black") response.end rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 Else if (fault = null) and (black = true) Then response.write("faulty null, black replaced") response.end rsAddRoom.fields("usedblack") = rsAddRoom("usedblack") + 1 End if and this if (fault = true) and (black = true) Then response.write("faulty black") response.end rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 ElseIf (fault = null) and (black = true) Then response.write("faulty null, black replaced") response.end rsAddRoom.fields("usedblack") = rsAddRoom("usedblack") + 1 End if and i just realised i made a slight error with the way this works, when a faulty cartridge is replaced it only will record one instance, ill need to turn that into a int instead(thats easily solved) heres the whole code just incase ive missed something obvious: <% 'process_room.asp 'Dimension variables Dim adoCon 'Holds the Database Connection Object Dim rsAddRoom 'Holds the recordset for the new record to be processed Dim strSQL 'Holds the SQL query to query the database 'get form values Dim roomid Dim printid Dim tonerid Dim fault Dim black Dim cyan Dim megenta Dim yellow Dim year roomid = Request.Form("roomid") printid = Request.Form("printid") tonerid = Request.Form("tonerid") fault = Request.Form("fault") black = Request.Form("black") cyan = Request.Form("cyan") megenta = Request.Form("megenta") yellow = Request.Form("yellow") year = Request.Form("year") 'Create an ADO connection object Set adoCon = Server.CreateObject("ADODB.Connection") 'Set an active connection to the Connection object using a DSN-less connection adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("toner.mdb") 'Create an ADO recordset object Set rsAddRoom = Server.CreateObject("ADODB.Recordset") 'Initialise the strSQL variable with an SQL statement to query the database strSQL = "SELECT * FROM used WHERE roomid =" & roomid 'response.write ("val fault: " & fault & " black: " & black) 'response.end 'Set the cursor type we are using so we can navigate through the recordset rsAddRoom.CursorType = 2 'Set the lock type so that the record is locked by ADO when it is updated rsAddRoom.LockType = 3 'Open the recordset with the SQL query rsAddRoom.Open strSQL, adoCon if rsAddroom.EOF OR rsAddRoom.BOF Then rsAddroom.Close 'response.write("end of File") 'response.end 'Initialise the strSQL variable with an SQL statement to query the database strSQL = "SELECT * FROM used;" 'Set the cursor type we are using so we can navigate through the recordset rsAddRoom.CursorType = 2 'Set the lock type so that the record is locked by ADO when it is updated rsAddRoom.LockType = 3 'Open the recordset with the SQL query rsAddRoom.Open strSQL, adoCon 'Tell the recordset we are adding a new record to it rsAddRoom.AddNew 'Add a new record to the recordset rsAddRoom.Fields("roomid") = roomid rsAddRoom.Fields("tonerid") = tonerid rsAddRoom.Fields("printid") = printid rsAddroom.Fields("year") = year if (fault = true) and (black = true) Then response.write("faulty black") response.end rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 Else if (fault = null) and (black = true) Then response.write("faulty null, black replaced") response.end rsAddRoom.fields("usedblack") = rsAddRoom("usedblack") + 1 End if if fault = true and cyan = true Then rsAddRoom.fields("faultycyan") = rsAddRoom("faultycyan") + 1 ElseIf fault = null and cyan = true Then rsAddRoom.fields("usedcyan") = rsAddRoom("usedcyan") + 1 End if if fault = true and megenta = true Then rsAddRoom.fields("faultmegenta") = rsAddRoom("faultmegenta") + 1 ElseIf fault = null and megenta = true Then rsAddRoom.fields("usedmegenta") = rsAddRoom("usedmegenta") + 1 End if if fault = true and yellow = true Then rsAddRoom.fields("faultyellow") = rsAddRoom("faultyellow") + 1 ElseIf fault = null and yellow = true Then rsAddRoom.fields("usedyellow") = rsAddRoom("usedyellow") + 1 End if 'Write the updated recordset to the database rsAddRoom.Update 'Reset server objects rsAddRoom.Close Set rsAddRoom = Nothing Set adoCon = Nothing else 'response.write("else statement") 'response.end 'Tell the recordset we are adding a new record to it rsAddRoom.AddNew 'Add a new record to the recordset rsAddRoom.Fields("roomid") = roomid rsAddRoom.Fields("tonerid") = tonerid rsAddRoom.Fields("printid") = printid rsAddRoom.Fields("year") = year if (fault = true) and (black = true) Then response.write("faulty black") response.end rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 Else if (fault = null) and (black = true) Then response.write("faulty null, black replaced") response.end rsAddRoom.fields("usedblack") = rsAddRoom("usedblack") + 1 End if if fault = true and cyan = true Then rsAddRoom.fields("faultycyan") = rsAddRoom("faultycyan") + 1 ElseIf fault = null and cyan = true Then rsAddRoom.fields("usedcyan") = rsAddRoom("usedcyan") + 1 End if if fault = true and megenta = true Then rsAddRoom.fields("faultmegenta") = rsAddRoom("faultmegenta") + 1 ElseIf fault = null and megenta = true Then rsAddRoom.fields("usedmegenta") = rsAddRoom("usedmegenta") + 1 End if if fault = true and yellow = true Then rsAddRoom.fields("faultyellow") = rsAddRoom("faultyellow") + 1 ElseIf fault = null and yellow = true Then rsAddRoom.fields("usedyellow") = rsAddRoom("usedyellow") + 1 End if 'Write the updated recordset to the database rsAddRoom.Update 'Reset server objects rsAddRoom.Close Set rsAddRoom = Nothing Set adoCon = Nothing End if 'Redirect to the default.asp page Response.Redirect "Default.asp" %> Edited March 26, 2010 by Flakes
u8dmtm Posted March 26, 2010 Posted March 26, 2010 Is this still a problem? If so post the error message. Also, have you not considered moving over to ASP.Net?
Flakes Posted March 26, 2010 Author Posted March 26, 2010 Is this still a problem? If so post the error message. Also, have you not considered moving over to ASP.Net? yep still an issue, unfortunately there is no error message, the if statement above just does not seem to do anything, however the entry in the table "used" is created. the Response.write and response.end should tell me what part of the If statement is being executed(although i know response.end stops the execution there)
webman Posted March 26, 2010 Posted March 26, 2010 Explicitly set fault and black to TRUE just above the IF statement. I'm thinking you might need to compare strings (and not a boolean type such as true/false), depending on what the form values are. E.g. if fault = "true" and black = "true" then.....
u8dmtm Posted March 26, 2010 Posted March 26, 2010 I'm thinking you might need to compare strings One reason why ASP.Net is so much better than ASP as you have properly defined variables there.
pwds Posted March 26, 2010 Posted March 26, 2010 Do you have HP printers? HP Web jet admin will do all of this for you and is supported.
MattMitchell Posted March 26, 2010 Posted March 26, 2010 Have you tried just outputting the values of your variables in a response page to see what's coming out? I'm with webman, I think that fault will either be set to the string "True", or to a numeric value equivalent to True (normally -1, 0 or 1 depending on the language).
Flakes Posted March 26, 2010 Author Posted March 26, 2010 Have you tried just outputting the values of your variables in a response page to see what's coming out? yea i tried that, and it all checked out. Im going to try some of the suggestions here on Monday when i get back to work and see if they work. Never bring work home with me:D.
Flakes Posted March 29, 2010 Author Posted March 29, 2010 im about ready to throw asp out the window, chuck out all my toys and go home. im now getting this error: Microsoft VBScript compilation error '800a0400' Expected statement /toner/process_room.asp, line 94 End if which concerns this bit of my code (changed to a case statement btw): if fault = "true" Then For Each item In tonerColour Select case item case "black" rsAddRoom.fields("faultyblack") = rsAddRoom("faultyblack") + 1 case "cyan" rsAddRoom.fields("faultycyan") = rsAddRoom("faultycyan") + 1 case "megenta" rsAddRoom.fields("faultmegenta") = rsAddRoom("faultmegenta") + 1 case "yellow" rsAddRoom.fields("faultyellow") = rsAddRoom("faultyellow") + 1 End Select End if
webman Posted March 29, 2010 Posted March 29, 2010 End your for-each block You've closed the select, and the if, but not the foreach. 1
Flakes Posted March 29, 2010 Author Posted March 29, 2010 End your for-each block You've closed the select, and the if, but not the foreach. i love you lol thanks, think ive been staring at this code too long.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now