Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. accessing buttons in vb 6.0 thru loop

accessing buttons in vb 6.0 thru loop

Scheduled Pinned Locked Moved Visual Basic
data-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    noshaba mariam
    wrote on last edited by
    #1

    Is there any way to access all of buttons one by one thru loop but the buttons are not in a control array. I have almost 40 buttons on a form and i need to make some of them enable and some of them disable at runtime by checking there names. I dont want to write the long code but the buttons are not in a control array...Is there any way out of this situation. Thanx in advance Noshaba

    S 1 Reply Last reply
    0
    • N noshaba mariam

      Is there any way to access all of buttons one by one thru loop but the buttons are not in a control array. I have almost 40 buttons on a form and i need to make some of them enable and some of them disable at runtime by checking there names. I dont want to write the long code but the buttons are not in a control array...Is there any way out of this situation. Thanx in advance Noshaba

      S Offline
      S Offline
      Steve Pullan
      wrote on last edited by
      #2

      I'd possibly re-build part of the form so that the buttons are in a control array. Much easier and the resultant code will be cleaner too. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)

      N 1 Reply Last reply
      0
      • S Steve Pullan

        I'd possibly re-build part of the form so that the buttons are in a control array. Much easier and the resultant code will be cleaner too. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)

        N Offline
        N Offline
        noshaba mariam
        wrote on last edited by
        #3

        I have got the solution of the problem....here is that for u also Don't redesign the form rather use the following code: Function fResetEntries(frm As Form) Dim objObject As Object Dim i As Long For i = 0 To frm.Count - 1 Set objObject = frm.Controls(i) If objObject.NAME = "cmd1" then objObject.enabled = false End If Next i End Function :) isn't more easier and cleaner Noshaba

        D S 2 Replies Last reply
        0
        • N noshaba mariam

          I have got the solution of the problem....here is that for u also Don't redesign the form rather use the following code: Function fResetEntries(frm As Form) Dim objObject As Object Dim i As Long For i = 0 To frm.Count - 1 Set objObject = frm.Controls(i) If objObject.NAME = "cmd1" then objObject.enabled = false End If Next i End Function :) isn't more easier and cleaner Noshaba

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          noshaba mariam wrote:

          isn't more easier and cleaner

          No, it's not. If you just looped through 40 buttons to find one, I can save you the trouble and get it down to just one line of code:

          Button1.Enabled = False

          You'd be much better off sticking the related buttons into a control array. Then you wouldn't have to waste all that time checking for a name. You could just do something like:

          For i = 0 to 12
          SomeButtons(i).Enabled = False
          Next

          Dave Kreskowiak Microsoft MVP - Visual Basic

          1 Reply Last reply
          0
          • N noshaba mariam

            I have got the solution of the problem....here is that for u also Don't redesign the form rather use the following code: Function fResetEntries(frm As Form) Dim objObject As Object Dim i As Long For i = 0 To frm.Count - 1 Set objObject = frm.Controls(i) If objObject.NAME = "cmd1" then objObject.enabled = false End If Next i End Function :) isn't more easier and cleaner Noshaba

            S Offline
            S Offline
            Steve Pullan
            wrote on last edited by
            #5

            OK - if you want - but it sometimes comes to the point where you need to refactor the code to make it more efficient, more readable and maintainable. It takes a little time to do properly but isn't that the whole point? See Dave's answer to see how compact and easy the code becomes. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups