please help me in Private Sub bt1_Click()

please
pleaaaaaaaaaaaaaaaaaaase

compile error:
Method or data member not found

Private Sub balance_Click()

Dim sc As Single
Dim sd As Single

sc = 0
sd = 0

For i = 0 To listcr.ListCount - 1
sc = sc + CSng(List.List(i))

Next i
For j = 0 To listde.ListCount - 1
sd = sd + CSng(List.List(j))

Next j
totcr.Caption = sc
totde.Caption = sd
totb = sc - sd

End Sub

Private Sub bt1_Click()

If opt1.Value = True Then

listcr.AddItem (t1.Text)
listde.AddItem ("0")

Else
listcr.AddItem (t1.Text)
listcr.addltem ("0")
End If

End Sub

Private Sub bt2_Click()

listcr.RemoveItem (listcr.ListCount - 1)
listde.RemoveItem (listde.ListCount - 1)

balance_Click
End Sub

Private Sub bt3_Click()

End

End Sub

Private Sub Form_Load()
bt1.Enabled = False
bt2.Enabled = False

End Sub

Private Sub t1_Change()
If t1.Text <> "" Then
bt1.Enabled = True
bt2.Enabled = True
End If
End Sub

Private Sub t1_validate(cancel As Boolean)

If Not IsNumeric(t1.Text) Then
cancel = True
Else
cancel = False
End If
End Sub


picture in error

Dani AI

Generated

Short diagnosis and how the earlier suggestions fit together: the compile error "Method or data member not found" means VB can't resolve the name or member used in code. and are correct that an OptionButton set up as a control array will not be callable as a single control; is also right to point to the Properties window — both checks are necessary. In this particular thread the most frequent causes are (a) the option button is an array but the code assumes a single control, (b) simple typos or wrong control names (for example the visible addltem vs AddItem), and (c) event procedures whose signatures don’t match what the IDE expects.

Practical checklist (run these in order):

  1. Inspect the controls in Form Design: confirm each control’s Name and the Index property. If Index contains a number the control is an array; either refer to an array element by index or clear the Index so the control is standalone.
  2. Confirm listbox and button names in Properties and use those exact names in code; watch visually similar characters (l, I, 1) and common misspellings that silently break compilation.
  3. Recreate event stubs from the IDE dropdowns (control left, event right) so the procedure signature matches the control’s event — hand-typed names often lead to "orphan" Subs.
  4. Add compile-time checks: put Option Explicit at the top of the form module and compile frequently to catch undeclared/incorrect names.
  5. Debugging checks: use breakpoints or Debug.Print to inspect ListCount and item contents, step through the routine, and check Tools → References for any "MISSING" libraries that can interfere with members.

A small, high-value change to add at the top of the form module:

Option Explicit

Typical real-world fix flow: confirm whether the option button is an array and either clear Index or change the code to reference an indexed item; fix any misspelled method/property names; regenerate event handlers from the IDE; then compile. Back up the .frm before changing many controls. These steps resolve the majority of "Method or data member not found" cases seen in this thread.

Recommended Answers

All 3 Replies

Hi mahdouch5,

I am 100% sure this will solve your problem. By looking your attached Image I found out that your control opt1 has array. Just change your code as under.

If opt1(0).Value = True Then

Or you can clear Index on Properties on that option if you have unique name.

Thanks

What that error is telling you is that you do not have a control by that name. So, go to form design view and click on the option button that you think is of that name and see what its name is in properties...

Good Luck

it cause your option button is an array control.. so vb doesn't recognize the control..
so your code must be :

If Opt1(0).Value = True Then
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.