none
Scrollbar ArgumentOutOfRangeException: RRS feed

  • Question

  • ArgumentOutOfRangeException: Value of '255' is not valid for 'Value'.

    This doesn't make sense to me.  The same code works for the background color scrollbars.

    The scrollbar (VsbFR) is set to Min:0 Max: 262 Default value: 0
    I have tried negative numbers for Min.  I've also changed the default 1 and 254.

    If Val(TbxDFR.Text) > 255 Then TbxDFR.Text = 255
    
    VsbFR.Value = 255 - Val(TbxDFR.Text)
    
    FRVsb = 255 - VsbBR.Value
    
    Dim FColor = RGB(FRVsb, FGVsb, FBVsb)
    TbxLg.ForeColor = ColorTranslator.FromOle(FColor)
    TbxSm.ForeColor = ColorTranslator.FromOle(FColor)
    FRVsb is declared globally "Private FRVsb As Integer" since I have 3 foreground scrollbars and 3 decimal and 3 hex text boxes.

    I'm using VS 2017
    • Edited by cdwder Friday, December 7, 2018 1:58 AM
    Friday, December 7, 2018 1:07 AM

All replies

  • Hi,

    This error indicates that 255 is not within the scope of the Scrollbar.Please confirm the minimum and maximum values of the Scrollbar

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 7, 2018 3:17 AM
  • Hi Alex,

    Here's the code from the designer.vb:

    'VsbFR
    '
    Me.VsbFR.LargeChange = 8
    Me.VsbFR.Location = New System.Drawing.Point(22, 240)
    Me.VsbFR.Maximum = 262
    Me.VsbFR.Name = "VsbFR"
    Me.VsbFR.Size = New System.Drawing.Size(17, 263)
    Me.VsbFR.TabIndex = 0
    Me.VsbFR.Value = 255

    And the Minimum is set to 0

    This is why I'm confused 255 is in between 0 and 262

    Bobbie


    • Edited by cdwder Friday, December 7, 2018 4:06 AM
    Friday, December 7, 2018 3:30 AM
  • Hi,

    I try your code,but not show your error,which code is given an error?

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.VsbFR.LargeChange = 8
            Me.VsbFR.Location = New System.Drawing.Point(22, 240)
            Me.VsbFR.Maximum = 264
            Me.VsbFR.Name = "VsbFR"
            Me.VsbFR.Size = New System.Drawing.Size(17, 263)
            Me.VsbFR.TabIndex = 0
            Me.VsbFR.Value = 255
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Val(TbxDFR.Text) > 255 Then TbxDFR.Text = 255
    
            VsbFR.Value = 255 - Val(TbxDFR.Text)
    
            Dim FRVsb = 255 - VsbBR.Value
    
            Dim FColor = RGB(FRVsb, 123, 123)
            TbxLg.ForeColor = ColorTranslator.FromOle(FColor)
            TbxSm.ForeColor = ColorTranslator.FromOle(FColor)
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 7, 2018 5:11 AM
  • Hi Alex,

    I'm sorry for the confusion.  Let's start over from the beginning.

    I'm rewriting a color comparison program which I originally wrote in VB3 in the late '90s.

    There are 6 vertical scrollbars 3 foreground and 3 background.  Each scrollbar has 2 text boxes associated with it 1 for decimal and 1 for hexadecimal.  Scrollbars change the text and typing in text changes the scrollbars.  Both/either change the color.

    Every thing worked fine until I added the last Sub "Private Sub TbxDFR_TextChanged". Which is the same as the sub above it "Private Sub TbxDBB_TextChanged".  At which point I got "ArgumentOutOfRangeException: Value of '255' is not valid for 'Value'."

    All scrollbars are set to minimum = 0 and maximum = 262

    Tbx is text box TbxDFR = Text box Decimal Foreground Red.  The variables nnVsb i.e. FRVsb are for reversing the scrollbars so that 0 is at the bottom.

    Here is the code:

    Public Class FrmColorComPair
    
        Private FRVsb As Integer
        Private FGVsb As Integer
        Private FBVsb As Integer
        Private BRVsb As Integer
        Private BGVsb As Integer
        Private BBVsb As Integer
    
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            FRVsb = 0
            FGVsb = 0
            FBVsb = 0
            BRVsb = 255
            BGVsb = 255
            BBVsb = 255
    
        End Sub
    
        Private Sub CmdClose_Click(sender As Object, e As EventArgs) Handles CmdClose.Click
    
            Close()
    
        End Sub
    
        Private Sub VsbBR_Scroll(sender As Object, e As ScrollEventArgs) Handles VsbBR.Scroll
    
            BRVsb = 255 - VsbBR.Value
    
            TbxDBR.Text = BRVsb
            TbxHBR.Text = Hex(BRVsb)
    
            Dim BColor = RGB(BRVsb, BGVsb, BBVsb)
    
            TbxLg.BackColor = ColorTranslator.FromOle(BColor)
            TbxSm.BackColor = ColorTranslator.FromOle(BColor)
    
        End Sub
    
        Private Sub VsbBG_Scroll(sender As Object, e As ScrollEventArgs) Handles VsbBG.Scroll
    
            BGVsb = 255 - VsbBG.Value
    
            TbxDBG.Text = BGVsb
            TbxHBG.Text = Hex(BGVsb)
    
            Dim BColor = RGB(BRVsb, BGVsb, BBVsb)
    
            TbxLg.BackColor = ColorTranslator.FromOle(BColor)
            TbxSm.BackColor = ColorTranslator.FromOle(BColor)
    
        End Sub
    
        Private Sub VsbBB_Scroll(sender As Object, e As ScrollEventArgs) Handles VsbBB.Scroll
    
            BBVsb = 255 - VsbBB.Value
    
            TbxDBB.Text = BBVsb
            TbxHBB.Text = Hex(BBVsb)
    
            Dim BColor = RGB(BRVsb, BGVsb, BBVsb)
    
            TbxLg.BackColor = ColorTranslator.FromOle(BColor)
            TbxSm.BackColor = ColorTranslator.FromOle(BColor)
    
        End Sub
    
        Private Sub VsbFR_Scroll(sender As Object, e As ScrollEventArgs) Handles VsbFR.Scroll
    
            FRVsb = 255 - VsbFR.Value
    
            TbxDFR.Text = FRVsb
            TbxHFR.Text = Hex(FRVsb)
    
            Dim FColor = RGB(FRVsb, FGVsb, FBVsb)
    
            TbxLg.ForeColor = ColorTranslator.FromOle(FColor)
            TbxSm.ForeColor = ColorTranslator.FromOle(FColor)
    
        End Sub
    
        Private Sub VsbFG_Scroll(sender As Object, e As ScrollEventArgs) Handles VsbFG.Scroll
    
            FGVsb = 255 - VsbFG.Value
    
            TbxDFG.Text = FGVsb
            TbxHFG.Text = Hex(FGVsb)
    
            Dim FColor = RGB(FRVsb, FGVsb, FBVsb)
    
            TbxLg.ForeColor = ColorTranslator.FromOle(FColor)
            TbxSm.ForeColor = ColorTranslator.FromOle(FColor)
    
        End Sub
    
        Private Sub VsbFB_Scroll(sender As Object, e As ScrollEventArgs) Handles VsbFB.Scroll
    
            FBVsb = 255 - VsbFB.Value
    
            TbxDFB.Text = FBVsb
            TbxHFB.Text = Hex(FBVsb)
    
            Dim FColor = RGB(FRVsb, FGVsb, FBVsb)
    
            TbxLg.ForeColor = ColorTranslator.FromOle(FColor)
            TbxSm.ForeColor = ColorTranslator.FromOle(FColor)
    
        End Sub
    
        Private Sub TbxDBR_TextChanged(sender As Object, e As EventArgs) Handles TbxDBR.TextChanged
    
            If Val(TbxDBR.Text) > 255 Then TbxDBR.Text = 255
            VsbBR.Value = 255 - Val(TbxDBR.Text)
    
            BRVsb = 255 - VsbBR.Value
            Dim BColor = RGB(BRVsb, BGVsb, BBVsb)
            TbxLg.BackColor = ColorTranslator.FromOle(BColor)
            TbxSm.BackColor = ColorTranslator.FromOle(BColor)
    
        End Sub
    
        Private Sub TbxDBG_TextChanged_1(sender As Object, e As EventArgs) Handles TbxDBG.TextChanged
    
            If Val(TbxDBG.Text) > 255 Then TbxDBG.Text = 255
            VsbBG.Value = 255 - Val(TbxDBG.Text)
    
            BGVsb = 255 - VsbBG.Value
            Dim BColor = RGB(BRVsb, BGVsb, BBVsb)
            TbxLg.BackColor = ColorTranslator.FromOle(BColor)
            TbxSm.BackColor = ColorTranslator.FromOle(BColor)
    
        End Sub
    
        Private Sub TbxDBB_TextChanged(sender As Object, e As EventArgs) Handles TbxDBB.TextChanged
    
            If Val(TbxDBB.Text) > 255 Then TbxDBB.Text = 255
            VsbBB.Value = 255 - Val(TbxDBB.Text)
    
            BBVsb = 255 - VsbBB.Value
            Dim BColor = RGB(BRVsb, BGVsb, BBVsb)
            TbxLg.BackColor = ColorTranslator.FromOle(BColor)
            TbxSm.BackColor = ColorTranslator.FromOle(BColor)
    
        End Sub
    
        Private Sub TbxDFR_TextChanged(sender As Object, e As EventArgs) Handles TbxDFR.TextChanged
    
            If Val(TbxDFR.Text) > 255 Then TbxDFR.Text = 255
            VsbFR.Value = 255 - Val(TbxDFR.Text)
    
            FRVsb = 255 - VsbFR.Value
            Dim FColor = RGB(FRVsb, FGVsb, FBVsb)
            TbxLg.ForeColor = ColorTranslator.FromOle(FColor)
            TbxSm.ForeColor = ColorTranslator.FromOle(FColor)
    
        End Sub
    End Class




    • Edited by cdwder Friday, December 7, 2018 1:36 PM
    Friday, December 7, 2018 1:13 PM
  • cd,

    As Alex shows, I too was not able to reproduce what you describe with my own code. 

    There are too many variables. ie you could have missed a scrollbar setting of 255.

    You example is too complicated for us to remake.

    You probably have a variable misnamed or a bad scrollbar initial value etc.

    When it stops on the error, check all the current values. You should see a wrong value.

    Make a simple example with one scroll bar and see if you can reproduce the problem like Alex shows. Then you will most likely find the error.

    If you cant find it then post the one scroll bar example that we can use to reproduce the problem.

    PS Put Option Strict ON as the first line in the top of the form then visual studio will point out spelling etc errors.

    What intervals are you using? ie SmallChange, LargeChange etc. Perhaps set all of that with code in a loop. Perhaps a class.

    Tell us what it is you want to do maybe we have ideas?

    Can you show a picture or link to something like what you want to do (or your vb3 version image)?


    PS Why is the max 262? What happens when value is 255 and step scrollbar large change = 8 then total = 263? Does that make an error?


    Friday, December 7, 2018 2:23 PM