Results 1 to 7 of 7

Thread: Arrays

  1. #1

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Arrays

    Take a look in my first image named a.jpg ... there is my question ....




    And This is my second question realting in my second image named b.jpg

    what statement should i use to determine if a number is ( - ) negative go to the next cotrol array ... i mean ... like in my image b.jpg .... as you can see there is a numbers appear in my control array ... what statement should i use finding a positive number ... like this ... uhm ... the program must test if number of txtA(0) = ( - ) negative go to the next array which is txtA(1) if txtA(1) = still a ( - ) negative number go to next array which is txtA(2) if txtA(2) is not a negative number stop ... sorry in my english ... thank you in advance

    txtA(0) = -1
    txtA(1) = -1
    txtA(2) = 2
    Attached Images Attached Images   
    Last edited by Loraine; Oct 8th, 2006 at 07:06 AM.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Arrays

    Try
    VB Code:
    1. Dim pos As Long
    2.  
    3. pos = LBound(txtA)
    4. 'Do Until (Val(txtA(pos)) >= 0 Or pos > Ubound(txtA))  
    5. 'my bad an error can occur since Val(txtA(pos)) can't be tested when pos > Ubound(txtA)
    6.  
    7. Do Until pos > UBound(txtA)  'updated
    8.   If Val(txtA(pos)) >= 0 Then Exit Do
    9.   pos = pos + 1
    10. Loop
    11.  
    12. If pos <= Ubound(txtA) Then Msgbox "stopped at txtA(" & pos & ") "
    Last edited by leinad31; Oct 8th, 2006 at 06:32 AM.

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Arrays

    BTW, where are the images?

  4. #4

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: Arrays

    Help me please

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Arrays

    Ahhh I see its a control array. To add

    VB Code:
    1. Dim cnt As Integer
    2. Dim Sum As Double
    3.  
    4. Sum = 0
    5. For cnt = txtA.LBound To txtA.UBound
    6.    Sum = Sum + Val(txtA(cnt).Text)
    7. Next
    8. Text1.Text = Sum

    Code in previous post for your 2nd question needs to be updated... it had assumed a string array but your using a control array. I'll leave the research on that (compare with recent code) to you.

    Pretty avatar

  6. #6

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: Arrays

    In my second question is this right ?

    Dim pos As Long
    Dim arr(4) As Integer
    Dim i As Integer

    pos = LBound(arr)
    'Do Until (Val(txtA(pos)) >= 0 Or pos > Ubound(txtA))
    'my bad an error can occur since Val(txtA(pos)) can't be tested when pos > Ubound(txtA)

    Do Until pos > UBound(arr) 'updated
    If Val(txtA(pos)) >= 0 Then Exit Do
    pos = pos + 1
    Loop

    If pos <= UBound(arr) Then
    Text1.Text = Val(txtA(i).Text) + Val(txtA(i).Text)
    End If

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Arrays

    You don't need arr() since your using txtA control array as list source.

    pos = txtA.LBound

    Ubound(txtA) should be txtA.UBound

    The last statement (Text1.Text = ... ) is confusing cause you never mentioned you needed a sum, you said you only needed to determine which control array textbox has a positive number.

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