In the code block below I am wishing to use a variable in a xxxx.Rows.Count line.
Specifically, I'm wanting to take the "R1200s" portion and increment it to R1201s, R1202s, R1203s and so on as the For-Next loop executes. I, of course, already have the DataTable()'s portion defined... no problem there. The code works fine if I write out every single instance but I'd like to shorten up into a simpler block of code. I've been able to use "i" in every other control with success but getting hung up on only this portion.
I've tried something like ("R120" & i & "s"), along with many variations of this but, can find no solution that works.
Any help, or a point in the right direction, is appreciated.
For i = 1 To 8
Dim Ai As Label = DirectCast(Page.FindControl("A" & ID.ToString()), Label)
Dim Si As Hyperlink = DirectCast(Page.FindControl("S" & ID.ToString()), Hyperlink)
If R1200s.Rows.Count < Slots.Rows(0)(Ri).ToString() +1 Then
Ai.Style.Add("background-color","#000000")
Si.ImageUrl = "images/" & ID & ".png"
Si.NavigateUrl = "step3.aspx?Time=" & ID & "&Date=" & Request.QueryString("Date") & "&Day=" & Request.QueryString("Day") & "&Entry=" & Request.QueryString("Entry")
End If
Next
Related
I'm new to classic asp and I'm trying to figure out this simple if else statement.
For some reason it's just recognizing person 2 and not even trying person 1?
Any idea on how to fix? Thanks
This is my code:
<%
Dim GetPath
GetPath = request.ServerVariables("URL") & query_string
Dim page
page = "/products/dowlex/index.htm"
if GetPath = page then
varrecipient = "email1#email.com"
Response.Write("*Path = " & GetPath)
Response.Write("Person 1")
else
varrecipient = "email2#email.com"
Response.Write("*Path = " & GetPath)
Response.Write("Person 2")
end if
varFormName = "Contact"
varRHBusinessUnit = "businessname"
varLanguage = "ENGLISH"
varCourtesyResponse = "Y"
varRedirect = "#noredir?formRun=true"
varSubject = "Ask an Expert Form"
%>
I would compare the two strings based on the same case...
if UCase(GetPath) = UCase(page) then
And of course, if query_string ever has a value, then the 1st case will never be true.
The formatting of your statement is fine. If... Then... Else... End if.
I would do a Response.Write("GetPath") to see if you are getting back, what you think you should be.
I have a couple thoughts.
1) Can you use Response.Write to display what's in "GetPath" before the if statement? That might help you see what's going wrong!
2) Try changing the variable names. The editor is making "GetPath" blue, as though it's a reserved word. That might be messing things up.
I'm sorry guys, I messed up a small code and thats why it wasn't working.
I forgot to complete the full path of the site. Thanks for all your help and suggestions!
*Path = /plasticpipes/eu/products/dowlex/index.htm
*Page = /products/dowlex/index.htm
I am having the following issue:
I am using an application that allows users to concatenate text to build a URL that passes parameters to an ASP page via GET method, i.e. something like:
http://myhostname/process.asp?param1=value1¶m2=value2
Problem is value1 and value2 can contain the ampersand symbol, which is not interpreted as a text character.
The most popular solution to this issue is to encode the URL, which is not an option for me because I cannot modify the program that builds the URL. I can modify the process.asp page, but not the program that concatenates the text fields and builds the URL.
Things I've tried to search for are:
How to encode a URL using javascript directly in the browser
How to change IIS default behaviour when reading an &
Alternative ways to pass parameters, i.e. something like passing them as a single string of characters separated with pipes
Hope you can give me some guidance.
You can read the entire query string and parse it yourself, like this:
q = Request.QueryString
a = Split(q, "=")
i = 1
For Each s In a
If i mod 2 = 0 Then
If InStr(s, "&") <> InStrRev(s, "&") Then
Response.Write "Value: " & Left(s, InStrRev(s, "&") - 1) & "<br/>"
hidingParam = Right(s, Len(s) - InStrRev(s, "&"))
Response.Write "PAramName: " & hidingParam & "<br/>"
i = i + 1
Else
Response.Write "Value: " & s & "<br/>"
End If
Else
Response.Write "PAramName: " & s & "<br/>"
End If
i = i + 1
Next
Result:
URL: ...?Q=abc&def&P=123 produces
PAramName: Q Value: abc&def PAramName: P Value: 123
Note that this is less than robust. I am only illustrating my idea. I didn't test with no &.
It also doens't handle multiple "=" characters (if that's a possiblity as well).
If there are 2 (or more) ampersands in-between the equals, then only the last one is a parameter separator. So, using your URL above, and assuming that value1 = "abc&def", and value2 = "123", then the URL will look like:
http://myhostname/process.asp?param1=abc&def¶m2=123
Notice there's 2 ampersands in-between the 2 equals. The last one will be your parameter separator, the rest are part of the value. And any ampersands after the last equals are also part of the value.
You'll have to dissect the incoming URL and apply the appropriate logic.
I'm working on executing the same code several times to produce a table. My first thoughts went out to using an array to do this.
Here is what i have got so far:
Dim iRow
iRow = 0
'alternate color for rows
Do While Not rsGlobalWeb.EOF
If iRow Mod 2 = 0 Then
response.write "<tr bgcolor=""#FFFFFF"">"
Else
response.write "<tr bgcolor=""#EEEEEE"">"
End If
'some other code
SqlBackup = "SELECT * FROM CMDBbackup WHERE Naam_Cattools = '" & rsGlobalWeb("Device_name") & "'"
Set rsBackup = Server.CreateObject("ADODB.Recordset")
rsBackup.Open SqlBackup, dbGlobalWeb, 3
'declaration of array
Dim fieldname(5),i
fieldname(0) = "Device_name"
fieldname(1) = "Image"
fieldname(2) = "Backup"
fieldname(3) = "Uptime"
fieldname(4) = "Processor"
fieldname(5) = "Nvram"
For i = 0 to 5
If rsGlobalWeb(fieldname(i)) <> "" Then
response.write("<td>" & rsGlobalWeb(fieldname(i)) & "</td>")
Else
If Not rsBackup.EOF Then
If Not IsNull(rsBackup(fieldname(i))) And (rsBackup(fieldname(i)) <> "") Then
response.write("<td>" & rsBackup(fieldname(i)) & " (backup)</td>")
End if
Else
response.write("<td>No data found</td>")
End if
End if
Next
response.write("</tr>")
iRow = iRow + 1
rsGlobalWeb.MoveNext
Loop
The issue i have now is that the following error occurs even tho i have friendly messages turned off:
"500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed."
The logfile shows the following:
"DaEngineSDB.asp |58|800a000d|Type_mismatch 80 -" Where the 58 is the line with the Dim Fieldname.
Without the array it does show the remainder of the code (i have 1 other field which gets added). If i remove the array and fill the fieldname(i) with a normal string value it also works fine.
I was trying out stuff that google says but after attempting several things i am still running up to a wall.
Any ideas what it could be?
Thanks in advance,
Erik
First you should turn on error displaying in your iis, or read the error log for its description, google it if not sure how.
Without error description, it's way too difficult to check what is wrong.
Problem solved!
After banging my head against the wall for a day i found out that i stupidly declared the array inside the DO WHILE loop. Moved the declaration out of it and problem solved.
i'm learning by practice. I was given an OCX file which according to who gave it to me was created using VB6 and I have the task of creating a user interface for it to test all the functionality that is described in a poorly written documentation file. On top of that I am not well-versed in VBScript but I've managed to dodge a few bullets while learning.
I have a method which returns a Collection and when I try to access it from VBScript I am only able to query the Count but when I try to do job.Item(i) or job(i) I get an error stating it doesn't have that property or method.
Can someone point me in the right direction to be able to traverse the contents of this collection?
I had to do it from JavaScript but since some things weren't that easy I decided that perhaps VBScript would help me bridge the gaps where JavaScript didn't cut it. I can access all properties from the ActiveXObject from JavaScript, but the methods which return other VB objects are a little more obscure to me. I've tried aJob.Item(iCount), aJob.Items(iCount) and aJob(iCount).
My code is:
For iCount = 1 To aJobs.Count
MsgBox("Num " & iCount)
MsgBox(aJobs.Item(iCount))
Next
Thanks.
People often create specialized and/or strongly typed collection classes in VB6. They don't always do it correctly though, and they sometimes create "partial" collection implementations that have no Item() method (or fail to mark it as the default member of the class). They might even have a similar method or property but name it something entirely different.
It is rarer to return a raw Collection object, but it can be done and if it is you shouldn't have the problems you have indicated from VBScript.
I just created a DLL project named "HallLib" with three classes: Hallway, DoorKnobs, and DoorKnob. The DoorKnobs class is a collection of DoorKnob objects. The Hallway class has a DoorKnobs object that it initializes with a random set of DoorKnob objects with randomly set properties. Hallway.DoorKnobs() returns the DoorKnobs collection object as its result.
It works fine in this script:
Option Explicit
Dim Hallway, DoorKnobs, DoorKnob
Set Hallway = CreateObject("HallLib.Hallway")
Set DoorKnobs = Hallway.DoorKnobs()
MsgBox "DoorKnobs.Count = " & CStr(DoorKnobs.Count)
For Each DoorKnob In DoorKnobs
MsgBox "DoorKnob.Material = " & CStr(DoorKnob.Material) & vbNewLine _
& "DoorKnob.Color = " & CStr(DoorKnob.Color)
Next
Update:
This script produces identical results:
Option Explicit
Dim Hallway, DoorKnobs, KnobIndex
Set Hallway = CreateObject("HallLib.Hallway")
Set DoorKnobs = Hallway.DoorKnobs()
MsgBox "DoorKnobs.Count = " & CStr(DoorKnobs.Count)
For KnobIndex = 1 To DoorKnobs.Count
With DoorKnobs.Item(KnobIndex)
MsgBox "DoorKnob.Material = " & CStr(.Material) & vbNewLine _
& "DoorKnob.Color = " & CStr(.Color)
End With
Next
As does:
Option Explicit
Dim Hallway, DoorKnobs, KnobIndex
Set Hallway = CreateObject("HallLib.Hallway")
Set DoorKnobs = Hallway.DoorKnobs()
MsgBox "DoorKnobs.Count = " & CStr(DoorKnobs.Count)
For KnobIndex = 1 To DoorKnobs.Count
With DoorKnobs(KnobIndex)
MsgBox "DoorKnob.Material = " & CStr(.Material) & vbNewLine _
& "DoorKnob.Color = " & CStr(.Color)
End With
Next
So I suspect you'll need to use some type library browser like OLEView to look at your OCX to see what classes and members it actually exposes.
Having an issue with type conversion in ASP classic.
heres my code:
Set trainingCost = Server.CreateObject("ADODB.Recordset")
strSQL3 = "SELECT cost1 FROM tblMain WHERE (Booked = 'Booked') AND (Paid IS NULL) AND (PaidDate BETWEEN '01/04/" & startyear & "' AND '31/03/" & endyear & "')"
trainingCost.Open strSQL3, Connection
trainingCost.movefirst
totalTrainCost = 0
do while not trainingCost.eof
trainCost = trainingCost("cost1")
If NOT isNull(trainCost) then
trainCostStr = CStr(trainCost)
trainCostStr = Replace(trainCostStr, "£", "")
trainCostStr = Replace(trainCostStr, ",", "")
totalTrainCost = totalTrainCost + CInt(trainCostStr)
end if
trainingCost.movenext
loop
trainingCost.close
when I run this I get the following error:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'CInt'
/systems/RFT/v1.2/Extract.asp, line 43
which is "totalTrainCost = totalTrainCost + CInt(trainCostStr)"
Im guessing that the problem is to do with the String value being uncastable to Int in which case is there any way to catch this error? I havent worked with asp classic much so any help would be usefull
cheers
-EDIT-
the type of column cost1 is String as it may contain a number or a sequence of chars eg £10.00 or TBC
You have a couple of choices. You can be proactive by checking ahead of time whether the value is numeric using the IsNumeric function:
If IsNumeric(trainCostStr) Then
totalTrainCost = totalTrainCost + CInt(trainCostStr)
Else
' Do something appropriate
End If
...or you can be reactive by using error catching; in Classic ASP probably easiest to define a function and use On Error Resume Next:
Function ConvertToInt(val)
On Error Resume Next
ConvertToInt = CInt(val)
If Err.Number <> 0 Then
ConvertToInt = Empty
Err.Clear
End If
End Function
Or return 0 or Null or whatever suits you, then use it in your trainCost code.
Note that CInt expects an integer and will stop at the first non-digit, so "123.45" comes back as 123. Look at the other conversions, CDouble, CCur, etc.
Rather than casting to a string, why not use CCur (Cast as Currency) so that your commas and any currency symbols (I think) are effectively ignored while doing arithmetic operations?
Potentially solving the wrong problem, depends on the type of Cost1 within the database but the code is looping through the records to generate a total.
strSQL3 = "SELECT sum(cost1) FROM tblMain WHERE (Booked = 'Booked') AND (Paid IS NULL) AND (PaidDate BETWEEN '01/04/" & startyear & "' AND '31/03/" & endyear & "')"
trainingCost.Open strSQL3, Connection
etc and just read off the value as a total.
I don't see why the RS is being looped to generate a sum when the database can do that work for you. All the conversion work it has generated just looks artifical.
Heh heh. Classic ASP. You have my pity :) Anyway,
On error resume next
And then on the next line, check that it worked.
Though maybe you want CDouble. Is that a function? I can't remember.