Results 1 to 7 of 7

Thread: looping thru an assigned array

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    24

    looping thru an assigned array

    sorry if this is too basic but i cant seems to get it to work..


    let say i created an array

    X= array(2,20,100,400)

    how am i suppose to write it so that
    the first is X=2 , 2nd is x=20 3rd is X=400??

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: looping thru an assigned array

    You already appear to have that.

    VB Code:
    1. dim x(3) as integer
    2. x(0) = 2
    3. x(1) = 200
    4. x(2) = 100
    5. x(3) = 400


    EDIT: Misread request.
    Last edited by dglienna; Apr 4th, 2005 at 02:46 AM.

  3. #3
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: looping thru an assigned array

    Quote Originally Posted by kunckle
    let say i created an array

    X= array(2,20,100,400)

    how am i suppose to write it so that
    the first is X=2 , 2nd is x=20 3rd is X=400??
    Can you explain a bit more. I don't quite understand what you're asking. In your example, X(0) = 2, X(1) = 20, X(2) = 100 and x(3) = 400. So what do you want to do?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    24

    Re: looping thru an assigned array

    ok i was actually trying to do this :


    Private Sub cmdStart_Click(Index As Integer)
    Dim i As Integer
    Dim X()
    Dim Y()

    Dim Data

    X() = Array(14.1, 28.2, 42.3, 56.4, 70.5, 84.6, 98.7, 112.8, 126.9, 141, 155.1, 169.2)
    Y() = Array(14, 28.1, 42.2)

    Do
    ret = eCIdx0249SetVelocity(handle, 0, 10)
    ret = eCIdx0249SetAcceleration(handle, 0, 200)
    ret = eCIdx0249setPosition(handle, 0, X(i))
    ret = eCIdx0249SetDeceleration(handle, 0, 200)
    ret = eCIdx0249Start(handle, 0)

    ret = eCIdx0249SetVelocity(handle, 1, 10)
    ret = eCIdx0249SetAcceleration(handle, 1, 200)
    ret = eCIdx0249setPosition(handle, 1, 14.1)
    ret = eCIdx0249SetDeceleration(handle, 1, 200)
    ret = eCIdx0249Start(handle, 1)

    (handle is my device name)

    ret = eCIdx0249ReadStatus(handle, 0, Data)

    If Data = 257 Then
    i = i + 1
    End If

    Loop While X <= 8

    above is a portion of my code
    (those commands with eCIdx0249 are commands for my hard ware)

    i also have a timer running behind:



    Private Sub Timer1_Timer()

    Dim pPos
    Dim pBos

    ret = eCIdx0249ReadActualPos(handle, 0, pPos)
    Label4.Caption = pPos
    ret = eCIdx0249ReadActualPos(handle, 1, pBos)
    label5.Caption = pBos

    End Sub

    (the above is to retrieve the actual position of the slider and i set the interval to 100)

    initally i though i did something wrong with the array thing
    but now i solved the array thing however a new problem arises the timer cannot seems to update the position of the slider anymore..

    can someone help me pls? thks...

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: looping thru an assigned array

    You are looping while x<=8, but I don't see where you are changing it. You also have an array with the same name. That isn't good to do.

    Wouldn't you want to declare your variables in the Timer as Public? Declare them at the top of the form in General Declarations so that they are accessible in all modules in that form. If you need them in all of the program's forms, then you have to declare them in a module.

  6. #6
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: looping thru an assigned array

    Quote Originally Posted by kunckle
    now i solved the array thing however a new problem arises the timer cannot seems to update the position of the slider anymore.
    Try putting a DoEvents statement within the body of your loop. That should allow your Timer event to be processed.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    24

    Re: looping thru an assigned array (solved)

    oh thks! the doevents statement did the trick =)

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