I'am trying to make a color mix program and is giving me this :Error Invalid Use Of Property.
I guess is because i have to put some values for colors, but i don't know how.
This is the code, hope somebody help me:

Private Sub Command1_Click()
Picture1.BackColor RGB(Text1, Text2, Text3)
End Sub

Private Sub Command2_Click()
Picture1.BackColor Form1.BackColor
Text1 = " "
Text2 = " "
Text3 = " "
Text1.SetFocus
End Sub

Private Sub Command3_Click()
End
End Sub

Dani AI

Generated

— the runtime error comes from treating the BackColor property like a procedure call and from feeding raw textbox strings into the color function without validating them. is right to point at conversion, but it’s safer to validate and clamp each component to the 0–255 byte range before making the color.

A compact helper to parse and clamp input:

Private Function ParseByte(s As String) As Integer
    s = Trim$(s)
    If s = "" Or Not IsNumeric(s) Then
        ParseByte = 0
        Exit Function
    End If
    ParseByte = CInt(Val(s))
    If ParseByte < 0 Then ParseByte = 0
    If ParseByte > 255 Then ParseByte = 255
End Function

Apply ParseByte to each TextBox to get R, G and B, then pass those three integers to the RGB function and assign the result to the PictureBox BackColor. Doing the parsing separately keeps conversions explicit and avoids runtime type errors when a field is empty or non-numeric.

Extra notes: enable Option Explicit to catch typos, initialize the textboxes to valid defaults (for example "0"), and consider using numeric controls (spin/trackbar) to prevent invalid input. AutoRedraw is useful only when drawing on the PictureBox and needing persistent pixels; it is not required simply to change the BackColor. In VB.NET the equivalent approach is to validate and use Color.FromArgb with Byte values.

I'm assuming that Text1-3 are text boxes.
I'd grab their "text" properties, then cast them to integers.
In programmer-ese, that's

Picture1.BackColor RGB(cint(Text1.Text),cint(Text2.Text),cint(Text3.Text))

OK, now correct me if I'm wrong (It's been forever since VB6 for me), but doesn't this need an equal sign between Picture1.BackColor and RGB(...) ?

Picture1.BackColor=RGB(cint(Text1.Text),cint(Text2.Text),cint(Text3.Text))

Also, I did some digging and it looks like you also need your Picture1.AutoRedraw set to true.

Hope that helps.

commented: thanks a lot, i knew something's missing, i have this book but sometimes the code is not done properly +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.