Jump to content

bilwebore

Members
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About bilwebore

  • Rank
    Newbie
  1. Obtaining new numbers from a randomly filled dynamic arrayThe following code generates a list of random numbers and displays them on the html page.<html><body><pre><script language="vbscript">Dim RanNum() ReDim RanNum(10)document.writeln("Check 1: Is RanNum an array? " & IsArray(RanNum))document.writeln("Random Numbers:")For i = 0 To 10RandomNumber = Int(50 * Rnd())x = RandomNumberRanNum(i) = xdocument.writeln(" " & i & "=" & RanNum(i))Next 'Erase RanNum(10) </SCRIPT></pre></body></html>When I rerun the program the members of the array never change. I expect to get new random numbers each time!I have placed the "erase" function at numerous places in the code, to no avail. How can I get this code to generate and print new numbers each time the program is run?Bill
  2. All the code development I have done has been with VBA for use in Excel files. VBA is the only code I have real experience with. I thought going from VBA to vbscript would be easy. But visual bascic does not work the same in vbscript. Can visual basic be used directly in web applications? What alternative code would you recommend?Bill
  3. I am having a problem getting this VBA code to run as VBScript. In Excel, the following code works perfectly:Sub DynamicCollection()Dim sampleVisualBasicColl As New CollectionDim i, RanNum(5), x As LongFor i = 1 To 5RandomNumber = Int(100 * Rnd()) x = RandomNumber RanNum(i) = x 'The code below adds the first random number to the collection "sampleVisualbasicColl"sampleVisualBasicColl.Add RanNum(i), CStr("Pos" & i) '"Cstr("Pos" & i)" is the KEY 'for this collection object. RanNumber = sampleVisualBasicColl.Item(CStr("Pos" & i)) Next is = sampleVisualBasicColl.Counts1 = sampleVisualBasicColl("Pos1")s2 = sampleVisualBasicColl("Pos2")s3 = sampleVisualBasicColl("Pos3")s4 = sampleVisualBasicColl("Pos4")s5 = sampleVisualBasicColl("Pos5")'document.writeln.sampleVisualBasicColl.Item (CStr("Pos" & i)) RandomNumber = InputBox("Pick a Position from 1 to 5", "Random Number")MsgBox (sampleVisualBasicColl.Item(CStr("Pos" & RandomNumber)))Set sampleVisualBasicColl = NothingEnd SubWhen I write it into a VBScript code as follows, it fails to work. I can’t figure out why it will not run. Any help:<html><body><Pre><script language="vbscript">Sub DynamicCollection()Dim sampleVisualBasicColl As New CollectionDim i, RanNum(5), x As LongFor i = 1 To 5RandomNumber = Int(100 * Rnd()) x = RandomNumber RanNum(i) = x 'The code below adds the first random number to the collection "sampleVisualbasicColl"sampleVisualBasicColl.Add RanNum(i), CStr("Pos" & i) '"Cstr("Pos" & i)" is the KEY 'for this collection object. RanNumber = sampleVisualBasicColl.Item(CStr("Pos" & i)) Next is = sampleVisualBasicColl.Counts1 = sampleVisualBasicColl("Pos1")s2 = sampleVisualBasicColl("Pos2")s3 = sampleVisualBasicColl("Pos3")s4 = sampleVisualBasicColl("Pos4")s5 = sampleVisualBasicColl("Pos5")RandomNumber = InputBox("Pick a Position from 1 to 5", "Random Number")MsgBox (sampleVisualBasicColl.Item(CStr("Pos" & RandomNumber)))Set sampleVisualBasicColl = NothingEnd Sub </script><script language="vbscript">document.writeln.sampleVisualBasicColl.Item (CStr("Pos" & i))document.writeln(" " & "Collection Count =: " & cstr(sampleVisualBasicColl.count))document.writeln("Pos1")</script></Pre></body></html>
  4. I have been using a function to generate numbers that are added to a collection. Let's say that the collection name is "ACollection". How can I call up or use a single member of the collection. I have not been able to call up a single member of the collection.Like:For i = 1 to 10number = ACollection (i) or some code akin to this that will let me call up any member of the collection and assign it to a variable or iadded to a string.Thanks
  5. I am trying to make an HTML table for a website that will be dynamic. I am looking to have the result of a VB function become the TD, ie what shows up in the table cell. I understand the makeup of an HTML table with TR and TD tags, etc. But how can I have what goes into a cell in the table be the result of a function. Let's say the function goes as follows:<html><body><script type="text/vbscript">randomize()randomNumber=Int(100 * rnd())document.write("A random number: <b>" & randomNumber & "</b>")</script></body></html>How can I get randomNumber to become a TD element?Thanks in advance!Webby
×
×
  • Create New...