This is my array
<%
Dim myFixedArray
myFixedArray(0) = "Albert Einstein"
myFixedArray(1) = "Mother Teresa"
myFixedArray(2) = "Bill Gates"
myFixedArray(3) = "Martin Luther King Jr."
%>
Now i using to get value is
<%
For i=0 to 3
response.write myArray(i) & "<br>"
Next
%>
I need to take "Bill Gates" array Number
I need resut is "2"
How find result with out loop?
How about this?
<%
For i=0 to 3
If myArray(i) = "Bill Gates" Then
mynumber = i (or return i)
End If
Next
%>
Related
I'm new to programming so I'm sorry if my question seems dumb. I want to ask if there is any way to return the keys from Multi.Dictionary when I have the value?
This is my code:
Dim myDict
Set myDict= Server.CreateObject("Multi.Dictionary")
myDict.UniqueKeys = False
'Fill dictionary with some data
myDict("param1") = "value1"
myDict.Add "param2", "value2"
myDict.Add "param2", "value2.2"
'Get dictionary Keys
Keys = myDict.Keys
Items = myDict.Items
For Z = 0 To UBound(Items)
Response.Write(Keys(Z) & " " & Items(Z) & "<br>")
Next
And for now returns
Subscript out of range: '2'
Which is normal because I loop 3 times while I have only 2 keys.
So is it possible to have a result like this:
Param1: "value1"
Param2: "value2"
Param2: "value2.2"
You can loop through the keys of myDict by checking the items multiple or not.
Dim myDict
Set myDict= Server.CreateObject("Multi.Dictionary")
myDict.UniqueKeys = False
myDict("param1") = "value1"
myDict.Add "param2", "value2"
myDict.Add "param2", "value2.2"
Dim key, subItem
For Each key In myDict.Keys
If IsArray(myDict(key)) Then ' item is an array
For Each subItem In myDict(key)
Response.Write key & ": " & subItem & "<br>"
Next
Else
Response.Write key & ": " & myDict(key) & "<br>"
End If
Next
How to find in between Ou=9999998 Only number
For example
suppose this is my string cn=54445sddsfsd, ou=99988855, o=fgfgfdg, u=dfddfgfgg. subject=5454gffdgfg454hg I want to declare only ou=99988855
<%
dim str,strArray,ouStr
str = "cn=54445sddsfsd,ou=99988855,o=fgfgfdg,u=dfddfgfgg.subject=5454gffdgfg454hg"
strArray = split(str,",")
for i=0 to ubound(strArray)
if instr(strArray(i),"ou")>0 then
ouStr = strArray(i)
end if
next
response.Write ouStr
%>
I was wondering if someone could help me out.
I need to work out a range that a dynamic number sits in.
For example, i have a script like so
<% upperlimit = 50000.0 %>
<% lowerlimit = -30000.0 %>
<%=Int((upperlimit - lowerlimit + 1)*Rnd() + lowerlimit) %>
This spits out the value 30366.
The upperlimit and lowerlimit are dynamic so i dont know what the output would be.
This value is in the range 30001 - 40000 ... How can i get those values dynamically?
Cheers
I believe this example covers your situation:
<%
max=100
min=1
Randomize
%>
<%=Int((max-min+1)*Rnd+min)%>
Update 1
<% upperlimit = 50000.0 %>
<% lowerlimit = -30000.0 %>
<% range = 10000 %>
<% newValue =Int((upperlimit - lowerlimit + 1)*Rnd() + lowerlimit) %>
<% lowerBand=(newValue\range)*range %>
<% upperBand=lowerBand+range %>
<%=newValue%>
<br>
<%=lowerBand+1%>-<%=upperBand%>
if you wanted to generate 30000-40000
<%
Dim MyNewRandomNum
Randomize
MyNewRandomNum = Int(Rnd * 10000)+30000
response.write MyNewRandomNum
%>
the value you random
30000 is minimal value
and 10000 is value you wanted to random (1-10000)
i hope this is you want
This works for both negative and positive values of newValue:
<%
dim upperlimit, lowerlimit, newValue, lowerBand, upperBand
upperlimit = 50000.0
lowerlimit = -30000.0
Randomize
newValue = Int((upperlimit - lowerlimit + 1)*Rnd + lowerlimit)
lowerBand = Fix(newValue/10000) * 10000 + Sgn(newValue)
upperBand = Sgn(lowerBand) * 10000 + lowerBand - Sgn(newValue)
response.write "newValue: " & newValue & "<br>"
response.write "lowerBand: " & lowerBand & "<br>"
response.write "upperBand: " & upperBand & "<br>"
%>
Please see Running example
Shadow Wizard help me showing this code to me:
<%
Set oRS= TarefasConexaoMSSQL.Execute("SELECT * FROM apptabela ORDER BY oito ASC")
Dim currentGroupName, previousGroupName
currentGroupName = ""
previousGroupName = ""
Do Until oRS.EOF
currentGroupName = oRS("oito")
One = oRS("um")
Two = oRS("dois")
If currentGroupName<>previousGroupName Then
Response.Write("<p>")
Response.Write("<a href='#'>" & currentGroupName & "</a>")
Response.Write("</p>")
End If
Response.Write("- One: " & One & ", Two: " & Two & "<br />")
previousGroupName = currentGroupName
oRS.MoveNext
Loop
oRS.Close
%>
it's generating something like:
1000
One: Apples, Two: Pear
One: Volks, Two: Lexus
1001
One: Car, Two: Boat
1002
One: Chicken, Two: Cow
One: Pen, Two: Pencil
One: C#, Two: C++
What I want is to add a line at the bottom of the each group, like a Sum, so later I can do some calculations:
1000
One: Apples, Two: Pear
One: Volks, Two: Lexus
SUM: X, Y
1001
One: Car, Two: Boat
SUM: X, Y
1002
One: Chicken, Two: Cow
One: Pen, Two: Pencil
One: C#, Two: C++
SUM: X, Y
Thanks
http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm
you can use this jquery plugin for your requirement. If you can not understand how to implement then please let me know. I have used this recently.
<%
Set oRS= TarefasConexaoMSSQL.Execute("SELECT * FROM apptabela ORDER BY oito ASC")
Dim currentGroupName, previousGroupName, sumone, sumtwo
currentGroupName = ""
previousGroupName = ""
Do Until oRS.EOF
currentGroupName = oRS("oito")
One = oRS("um")
Two = oRS("dois")
If currentGroupName<>previousGroupName Then
(!)Response.write("- Sum: " & sumone & ", " & sumtwo)
(!)sumone = 0 / ""
(!)sumtwo = sumone
Response.Write("<p>")
Response.Write("<a href='#'>" & currentGroupName & "</a>")
Response.Write("</p>")
End If
Response.Write("- One: " & One & ", Two: " & Two & "<br />")
(!)sumone = sumone + one
(!)sumtwo = sumtwo + two
previousGroupName = currentGroupName
oRS.MoveNext
Loop
oRS.Close
%>
this shoud fix it. as you are ordering by groupname and want a sum for every group you have to sum things up when printing the group elements and print the sum when goint into a new group + clear the sum before summing up again. this should also work if you are using string, but maybe you would want to add whitespaces when summing up then
I have a table (MSSQL) with data like:
1 AAA 100
2 BBB 101
3 C 100
4 D 100
I would like to list itens like:
100:
- 1 AAA
- 3 C
- 4 D
101:
- 2 BBB
How can I do this? I have done a While inside a While but the result isn't what I am waiting:
<%
Set Group= TarefasConexaoMSSQL.Execute("SELECT DISTINCT GroupName FROM _NewDummy")
GroupName= Group("GroupName")
WHILE NOT Group.EOF
%>
<p>
<% Response.Write Group("GroupName") %>
</p>
<%
Set Itens= TarefasConexaoMSSQL.Execute("SELECT * FROM _NewDummy WHERE GroupName= '"& GroupName &"'")
One= Itens("One")
Two= Itens("Two")
%>
<%
WHILE NOT Itens.EOF
%>
- One: <% Response.Write One %>
- Two: <% Response.Write Two %>
<%
Itens.MOVENEXT
WEND
%>
<%
Group.MOVENEXT
WEND
%>
Thanks for any info on this.
You don't need any nested loop here, just sort by the group name and keep track of the previous value vs. the current value. When the value changes (or first value) show the group name.
Code:
<%
Set oRS= TarefasConexaoMSSQL.Execute("SELECT * FROM _NewDummy ORDER BY GroupName ASC")
Dim currentGroupName, previousGroupName
currentGroupName = ""
previousGroupName = ""
Do Until oRS.EOF
currentGroupName = oRS("GroupName")
One = oRS("One")
Two = oRS("Two")
If currentGroupName<>previousGroupName Then
Response.Write("<p>")
Response.Write("" & currentGroupName & "")
Response.Write("</p>")
End If
Response.Write("- One: " & One & ", Two: " & Two & "<br />")
previousGroupName = currentGroupName
oRS.MoveNext
Loop
oRS.Close
%>