Advertisement
C_Volume2 Miscellaneous #74083

Acces control thru variable

Be able to access multiple controls which require the same task with minimal code. Basically I wanted to be able to access controls without having to write numerous bits and peices to reach multiple controls with multiple forms and could not find what I needed so I decided to post. Here you are creating 2 control arrays with labels and all the code will demonstrate is randomly changeing the color of a randomly selected label. This is my first post so if a bit lame hope you at least find it usefull.

AI

Resumen de IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Código fuente
original-source
Private Sub Timer1_Timer()
  Dim CtrlName As String, CtrlIdx As Integer
  Dim ClrSlct As Integer, ClrSlcted As Long
  Dim LblRow As Integer
  
  Randomize
  
  CtrlIdx = Rnd * 7
  
  Randomize
  
  ClrSlct = Rnd * 3
  
  Select Case ClrSlct
    Case 0
      ClrSlcted = &HFF00&   'Green
    Case 1
      ClrSlcted = &HFF&    'Red
    Case 2
      ClrSlcted = &HFF0000  'Blue
    Case 3
      ClrSlcted = &HFFFF&   'Yellow
  End Select
  
  Randomize
  
  LblRow = (Rnd * 1) + 1
  CtrlName = "Label" & LblRow
  
  Form1.Controls(CtrlName).Item(CtrlIdx).BackColor = ClrSlcted
  
End Sub
Comentarios originales (3)
Recuperado de Wayback Machine