myITforum and Windows IT Pro Forums
Forum Themes:
Welcome !

 Can we use variables in array declaration like myArray(x) instead of myArray(10)

Author Message
mrzcomputer

  • Total Posts : 1
  • Scores: 0
  • Reward points : 100
  • Joined: 11/10/2013
  • Status: offline
Can we use variables in array declaration like myArray(x) instead of myArray(10) Sunday, November 10, 2013 10:05 PM (permalink)
0
where is the problem? I cannot assign a variable inside array like myArray(x). When I did it threw an error! However if I hard code like a straight number then there is no problem... but it makes no sense as to why I cannot put a variable instead of a fix number..... can anyone help me with the code below....
 
 
 
n=inputbox("please enter an integer value: ") 'a value of 6 has been entered
t=n
msgbox t
t=t+5
msgbox t 'returns 11 which absolutely perfect.
'dim x(t)
'------  dim x( t )     THIS IS WHERE THE PROBLEM IS. IT DOESN'T ACCEPT THE VALUE OF T. I HAVE CHECKED IF "T" 'AFTER IT HAS  BEEN ASSIGNED WITH AN INTEGER VALUE IS REALLY AN INTEGER VALUE AND FOUND T TO BE AN INTEGER AS BECAUSE 'WHEN  T = T+5 RETURNED 11 (AFTER N HAD BEEN GIVEN AN INPUT OF 6)------------
'for i = 0 to n
'x(i) =inputbox("")
next
msgbox x(0)
msgbox x(1)
<message edited by mrzcomputer on Sunday, November 10, 2013 10:11 PM>
 
#1
    akaplan

    • Total Posts : 148
    • Scores: 38
    • Reward points : 26920
    • Joined: 4/22/2003
    • Location: North Carolina
    • Status: offline
    Re:Can we use variables in array declaration like myArray(x) instead of myArray(10) Tuesday, November 12, 2013 11:14 AM (permalink)
    0
    Create the array, then use Redim:
    myArray=Array()
    n=InputBox("How many elements in Array?")
    ReDim MyArray(n)
    Wscript.echo ubound(myarray)

    Alan Kaplan --- www.akaplan.com/blog
     
    #2
      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2017 ASPPlayground.NET Forum Version 3.9