Results 1 to 9 of 9

Thread: Math Problem

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Math Problem

    Hi. I am trying to make a Vscroll type OCX. I have everything finished except figuring out how to drag the slider with the mouse and have it figure its place on the bar and turn that into a value between the minimum which is usualy 0 and the Max which could be anything but is set to 500 for this example.


    I can drag the slider img up and down no problem. But figuring out the math to get the Value of the slider is hard. I've tried using the .top property divided by the Userontrol.height etc... and can't get anything reliebale.

    I have attached a small .jpg so you can see the control and get an idea of what i am talking about.

    Here is an idea of the code i am using as well.

    VB Code:
    1. Private Sub imgSLIDER_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. If Button = 1 Then
    3. imgSLIDER.Move imgSLIDER.Left - 0, imgSLIDER.Top - (prevY - Y)
    4.  
    5. m_Value = imgSLIDER.Top - Usercontrol.Height - ImgUP.Height - imgSLIDER.Height - ImgDOWN.Height / m_Max / 2
    6.  
    7. RaiseEvent Scroll
    8. End If
    9. End Sub

    m_Value is the current value of the slider which is somewhere between the M_Min and M_Max values 0-500 for this example.

    Imgup, ImgDown and ImgSlider are the 3 images on the control.

    THanks alot for any help!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    Why can't you just use the scroll bars value property?
    VB6 VS2005

  3. #3

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Huh?


    You obviously dont understand. THis scroll baris being made by me. It doesnt have a scroll value property yet. THat's what i am trying to make.

    It does have the change porperty. Meaning if i push the up or down buttons the slider will move and the value does change exactly like it is suppost to. But i am having trouble figuring out how to accomplish the same thing while draging the slider with the mouse...
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  4. #4
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    Oh sorry, I'll have a go and see if i can come up with anything
    VB6 VS2005

  5. #5

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Thanks
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  6. #6
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    Try this, i haven't tried it as I domn't have your project, but mathematically it shouild work:


    controlRange=(ImgDown.Top-(imgSLIDER.Height/2))-((UserControl.Top + ImgUp.Height) + (imgSLIDER.Height/2))

    scrollValue= (imgSlider.top+(imgSLIDEER.Height/2)/scrollRange)*(mMax-mMin)



    (I assume it imgUp is the top button and imgDown is the bottom button)
    VB6 VS2005

  7. #7

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Nope, doesnt work. Anything based off the .top value od the slider isnt going to work because the top value will be radically different depending on the size of the control.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  8. #8
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    The difference shouldn't matter, as this calculates the range that the control can reach and then works out the value by division.

    could you send me the code for the OCX?
    VB6 VS2005

  9. #9
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    This works, I tried it out


    controlrange = (imgDown.Top - (imgSLIDER.Height / 2)) - ((imgUp.Top + imgUp.Height) + (imgSLIDER.Height / 2))

    scrollvalue = ((imgSLIDER.Top + (imgSLIDER.Height / 2)) - (imgUp.Top + imgUp.Height + (imgSLIDER.Height / 2))) / controlrange * (mMax - mMin)
    VB6 VS2005

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