Results 1 to 10 of 10

Thread: [RESOLVED] ubound

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Resolved [RESOLVED] ubound

    a simple question, what does ubound in this code means?
    VB Code:
    1. Dim folding() As String
    2.  
    3. folding() = Split(txtFolding.Text, "+")
    4.  
    5. If UBound(folding) = 1 Then
    6.                 result = result + Val(Mid(txtNumber(i).Text, Left(folding(1), 1), Len(folding(1))))

    thanks

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: ubound

    Ubound() returns the upper limit of an array.
    Split(txtFolding.text,"+") feeds into an array, seperating a block of text into each array index.

    If UBound(folding) = 1 then

    Means that there is a + present inside the txtFolding.text

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: ubound

    UBound() returns the last index in the folding() array. You can alsow use LBound(), which returns the first index of array.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: ubound

    thanks...
    hey gavio,
    can I have a favor?
    can you explain to me the flow of the program about folding
    especially about the left,mid and right function?

  5. #5
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: ubound

    I have used the Left(), Right() and the Mid() functions because i needed to get values from the suitable txtInput TextBox. I could not always use Mid(), since it doesn't work right, if you're on the left/right side of a string. So i've used Left() and Right(). Maybe that seems complicated, but for example:

    VB Code:
    1. result = result + CLng(Val(Right(txtInput(i).Text, Len(folding(UBound(folding))))))
    That's just add the length of the last folding process (for example 2 digits) from the txtInput(i) TextBox to the result (btw... Val() returns a number (if somebody would have make a mistake and inputed a non-numeric value) and CLng() converts it to Long, since the result is Long

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: ubound

    wooahh...it's true! that it is so complicated

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: ubound

    Quote Originally Posted by belvita
    wooahh...it's true! that it is so complicated
    Always look at the most middle functions, like in mathematics. You always check the most middle brackets (), what are they doing. What this functions returns, the next left/rigth function gets... and so on, until the first/last one.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: ubound

    in this part:
    VB Code:
    1. result = result + Val(Mid(txtNumber(i).Text, Left(folding(j), 1), Len(folding(j))))

    you use the mid function, using the len of the folding?

  9. #9
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: ubound

    I'll try to explain how have i splited the folding process. For example, if user enters "1+234+5", that means 3 folding processes:

    VB Code:
    1. folding() = Split(txtFolding.Text, "+")
    Now you have:

    folding(0)=1
    folding(1)=234
    folding(2)=5

    VB Code:
    1. result = result + Val(Mid(txtNumber(i).Text, Left(folding(j), 1), Len(folding(j))))
    I think that that Mid() was used in a For loop... so... previously, i've looped with i through all txtInput() TextBoxes. Now i've created another loop... i'm using j to loop through all the middle folding processes... folding(0) is calculated with the Left() function and folding(2) is calculated with the Right() function. All the middle folding proccesses are calculated with the Mid() function - in this case only 1, but there can be thousands of theme.

    VB Code:
    1. Val(Mid(txtNumber(i).Text, Left(folding(j), 1), Len(folding(j))))
    That just means: take number/s from txtNumber(i) - in my case that was txtInput(i), in the length of folding(j) - in this case folding(1) and add theme to result. Is this any clearer?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: ubound

    yes...thanks gavio

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