Results 1 to 10 of 10

Thread: Upper Bound Of Array

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Question Upper Bound Of Array

    Hi all
    How to found the upper bound of the array without using the redim value
    Check the code error in the command 2 click then how to solve this error without using the value of the text1.text


    VB Code:
    1. Dim A() As Integer
    2. Private Sub Command1_Click()
    3. Dim I As Integer
    4. ReDim A(Val(Text1.Text))
    5. For I = 0 To Text1.Text
    6.     A(I) = I * 1
    7. Next
    8. End Sub
    9. Private Sub Command2_Click()
    10. 'Without Using the value of Text1.Text How we founnd the UpperBound Of Array A
    11. 'I Want
    12. For I = 0 To [B]A.ubound 'Error Here[/B] :confused:
    13.     MsgBox A(I)
    14. Next
    15. End Sub
    Hope you all understand the problem I have a lot of array and I want to know the ubound value at run time without saving the other value
    Thanks

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Upper Bound Of Array

    VB Code:
    1. Debug.Print UBound(A)
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Re: Upper Bound Of Array

    Shouldnt that be ubound(a) ?? and btw fir command1_click the line
    for i=0 to text1.text is wrong it should be val(text1.text)
    __________________
    ________________0îîî___
    ___îîî0________(___)____
    __(___)_________) _/_____
    ___\_ (_________(_/______
    ____\_)_________________

  4. #4

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Upper Bound Of Array

    Quote Originally Posted by Shuja Ali
    VB Code:
    1. Debug.Print UBound(A)
    Thanks but I want random value from the saved array, so what to do?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Upper Bound Of Array

    Quote Originally Posted by shakti5385
    Thanks but I want random value from the saved array, so what to do?
    I don't understand what bearing this has on the orginal question.

    A random value may not always be, in fact, may never be, it upper boundary.

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Upper Bound Of Array

    your code in the first post doesn't make any sense at all.

    you're creating an array of integers where A(1) = 1, A(2) = 2 etc., so in order to get the member which has the value 2 you have to access the member with index 2 and hence you already know the number - why bother with the array?????

  7. #7
    Lively Member
    Join Date
    Jun 2006
    Location
    Chennai, India
    Posts
    87

    Re: Upper Bound Of Array

    try this one
    VB Code:
    1. Dim A(5) As String
    2.  
    3. Private Sub Command1_Click()
    4. Dim index As Integer
    5. Math.Randomize
    6. index = Math.Rnd * UBound(A)
    7. MsgBox A(index)
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11. Dim i As Integer
    12. For i = 0 To UBound(A)
    13. A(i) = "Item " & i
    14. Next i
    15. End Sub

  8. #8

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Talking Re: Upper Bound Of Array

    Quote Originally Posted by bushmobile
    your code in the first post doesn't make any sense at all.

    you're creating an array of integers where A(1) = 1, A(2) = 2 etc., so in order to get the member which has the value 2 you have to access the member with index 2 and hence you already know the number - why bother with the array?????
    I AM MAKING THE ARRAY BECAUSE I AM USING MORE THEN 2 array in my project, what’s happening that I am finding the teacher code related to the class code, and next I am finding the value of subject code related to the teacher code so I need the upper bound of the array.
    But now I want random subject code related to the teacher’s code so I want to get the random value from the saved array.
    Thanks

  9. #9
    Lively Member
    Join Date
    Jun 2006
    Location
    Chennai, India
    Posts
    87

    Re: Upper Bound Of Array

    Did my answer solve ur problems?

  10. #10

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Upper Bound Of Array

    Quote Originally Posted by balajikandaswamy
    Did my answer solve ur problems?
    Your effort is good but i am thinking that how to apply
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width