How Can I make string expression variable [duplicate]












0
















This question already has an answer here:




  • How To Get Control Property by “String Name”?

    5 answers




I made over a hundred checkbox for movie ticketing project(University)
and We have to check what checkbox is checked.
but We couldn't make it through.



I thought



For i As Integer = 1 To 180 Step 1
If ("checkbox" & i).checked = True Then
'blah blah blah
End If
Next


I know it's not grammatical-right but you know what I mean.
please help us :( we hold it very long time...



ps. of course, we can make another route to this system.
But I want to know it.
Thanks.










share|improve this question













marked as duplicate by Ahmed Abdelhameed, None of the Above vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 1:07


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • How To Get Control Property by “String Name”?

      5 answers




    I made over a hundred checkbox for movie ticketing project(University)
    and We have to check what checkbox is checked.
    but We couldn't make it through.



    I thought



    For i As Integer = 1 To 180 Step 1
    If ("checkbox" & i).checked = True Then
    'blah blah blah
    End If
    Next


    I know it's not grammatical-right but you know what I mean.
    please help us :( we hold it very long time...



    ps. of course, we can make another route to this system.
    But I want to know it.
    Thanks.










    share|improve this question













    marked as duplicate by Ahmed Abdelhameed, None of the Above vb.net
    Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 22 '18 at 1:07


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • How To Get Control Property by “String Name”?

        5 answers




      I made over a hundred checkbox for movie ticketing project(University)
      and We have to check what checkbox is checked.
      but We couldn't make it through.



      I thought



      For i As Integer = 1 To 180 Step 1
      If ("checkbox" & i).checked = True Then
      'blah blah blah
      End If
      Next


      I know it's not grammatical-right but you know what I mean.
      please help us :( we hold it very long time...



      ps. of course, we can make another route to this system.
      But I want to know it.
      Thanks.










      share|improve this question















      This question already has an answer here:




      • How To Get Control Property by “String Name”?

        5 answers




      I made over a hundred checkbox for movie ticketing project(University)
      and We have to check what checkbox is checked.
      but We couldn't make it through.



      I thought



      For i As Integer = 1 To 180 Step 1
      If ("checkbox" & i).checked = True Then
      'blah blah blah
      End If
      Next


      I know it's not grammatical-right but you know what I mean.
      please help us :( we hold it very long time...



      ps. of course, we can make another route to this system.
      But I want to know it.
      Thanks.





      This question already has an answer here:




      • How To Get Control Property by “String Name”?

        5 answers








      vb.net






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 22:58









      K.JHK.JH

      71




      71




      marked as duplicate by Ahmed Abdelhameed, None of the Above vb.net
      Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 '18 at 1:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Ahmed Abdelhameed, None of the Above vb.net
      Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 '18 at 1:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can place all checkboxes in a group box and then make a loop for all checkboxes in it like this:



          For Each ctrl In GroupBox1.Controls

          If (ctrl.GetType() Is GetType(CheckBox)) Then
          Dim chkbx As CheckBox = CType(ctrl, CheckBox)
          End If
          Next


          Or if you insist on doing it with predefined strings then try something with directcasting:



          For i as integer = 1 to 180 Step 1
          dim chkbox as Checkbox = DirectCast(Controls("checkbox" & i.ToString), Checkbox )
          If chkbox IsNot Nothing
          ' do something with the object now
          End If
          Next





          share|improve this answer





















          • 1





            And what if in that groupbox is another control per say a panel with checkboxs....? Do you think either of your solutions would work?

            – Çöđěxěŕ
            Nov 21 '18 at 23:12













          • never thought of that, still until reasonable sizes can be hard looped with For Each containertype in form first then for each ctrl in container1-2-3.controls i suppose. or if things get really messy DirectCast or CType or Find from id string would be a better approach.

            – koksalb
            Nov 21 '18 at 23:17













          • Thanks for helping! I'll check it soon.

            – K.JH
            Nov 22 '18 at 22:39


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can place all checkboxes in a group box and then make a loop for all checkboxes in it like this:



          For Each ctrl In GroupBox1.Controls

          If (ctrl.GetType() Is GetType(CheckBox)) Then
          Dim chkbx As CheckBox = CType(ctrl, CheckBox)
          End If
          Next


          Or if you insist on doing it with predefined strings then try something with directcasting:



          For i as integer = 1 to 180 Step 1
          dim chkbox as Checkbox = DirectCast(Controls("checkbox" & i.ToString), Checkbox )
          If chkbox IsNot Nothing
          ' do something with the object now
          End If
          Next





          share|improve this answer





















          • 1





            And what if in that groupbox is another control per say a panel with checkboxs....? Do you think either of your solutions would work?

            – Çöđěxěŕ
            Nov 21 '18 at 23:12













          • never thought of that, still until reasonable sizes can be hard looped with For Each containertype in form first then for each ctrl in container1-2-3.controls i suppose. or if things get really messy DirectCast or CType or Find from id string would be a better approach.

            – koksalb
            Nov 21 '18 at 23:17













          • Thanks for helping! I'll check it soon.

            – K.JH
            Nov 22 '18 at 22:39
















          0














          You can place all checkboxes in a group box and then make a loop for all checkboxes in it like this:



          For Each ctrl In GroupBox1.Controls

          If (ctrl.GetType() Is GetType(CheckBox)) Then
          Dim chkbx As CheckBox = CType(ctrl, CheckBox)
          End If
          Next


          Or if you insist on doing it with predefined strings then try something with directcasting:



          For i as integer = 1 to 180 Step 1
          dim chkbox as Checkbox = DirectCast(Controls("checkbox" & i.ToString), Checkbox )
          If chkbox IsNot Nothing
          ' do something with the object now
          End If
          Next





          share|improve this answer





















          • 1





            And what if in that groupbox is another control per say a panel with checkboxs....? Do you think either of your solutions would work?

            – Çöđěxěŕ
            Nov 21 '18 at 23:12













          • never thought of that, still until reasonable sizes can be hard looped with For Each containertype in form first then for each ctrl in container1-2-3.controls i suppose. or if things get really messy DirectCast or CType or Find from id string would be a better approach.

            – koksalb
            Nov 21 '18 at 23:17













          • Thanks for helping! I'll check it soon.

            – K.JH
            Nov 22 '18 at 22:39














          0












          0








          0







          You can place all checkboxes in a group box and then make a loop for all checkboxes in it like this:



          For Each ctrl In GroupBox1.Controls

          If (ctrl.GetType() Is GetType(CheckBox)) Then
          Dim chkbx As CheckBox = CType(ctrl, CheckBox)
          End If
          Next


          Or if you insist on doing it with predefined strings then try something with directcasting:



          For i as integer = 1 to 180 Step 1
          dim chkbox as Checkbox = DirectCast(Controls("checkbox" & i.ToString), Checkbox )
          If chkbox IsNot Nothing
          ' do something with the object now
          End If
          Next





          share|improve this answer















          You can place all checkboxes in a group box and then make a loop for all checkboxes in it like this:



          For Each ctrl In GroupBox1.Controls

          If (ctrl.GetType() Is GetType(CheckBox)) Then
          Dim chkbx As CheckBox = CType(ctrl, CheckBox)
          End If
          Next


          Or if you insist on doing it with predefined strings then try something with directcasting:



          For i as integer = 1 to 180 Step 1
          dim chkbox as Checkbox = DirectCast(Controls("checkbox" & i.ToString), Checkbox )
          If chkbox IsNot Nothing
          ' do something with the object now
          End If
          Next






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 23:12

























          answered Nov 21 '18 at 23:03









          koksalbkoksalb

          355713




          355713








          • 1





            And what if in that groupbox is another control per say a panel with checkboxs....? Do you think either of your solutions would work?

            – Çöđěxěŕ
            Nov 21 '18 at 23:12













          • never thought of that, still until reasonable sizes can be hard looped with For Each containertype in form first then for each ctrl in container1-2-3.controls i suppose. or if things get really messy DirectCast or CType or Find from id string would be a better approach.

            – koksalb
            Nov 21 '18 at 23:17













          • Thanks for helping! I'll check it soon.

            – K.JH
            Nov 22 '18 at 22:39














          • 1





            And what if in that groupbox is another control per say a panel with checkboxs....? Do you think either of your solutions would work?

            – Çöđěxěŕ
            Nov 21 '18 at 23:12













          • never thought of that, still until reasonable sizes can be hard looped with For Each containertype in form first then for each ctrl in container1-2-3.controls i suppose. or if things get really messy DirectCast or CType or Find from id string would be a better approach.

            – koksalb
            Nov 21 '18 at 23:17













          • Thanks for helping! I'll check it soon.

            – K.JH
            Nov 22 '18 at 22:39








          1




          1





          And what if in that groupbox is another control per say a panel with checkboxs....? Do you think either of your solutions would work?

          – Çöđěxěŕ
          Nov 21 '18 at 23:12







          And what if in that groupbox is another control per say a panel with checkboxs....? Do you think either of your solutions would work?

          – Çöđěxěŕ
          Nov 21 '18 at 23:12















          never thought of that, still until reasonable sizes can be hard looped with For Each containertype in form first then for each ctrl in container1-2-3.controls i suppose. or if things get really messy DirectCast or CType or Find from id string would be a better approach.

          – koksalb
          Nov 21 '18 at 23:17







          never thought of that, still until reasonable sizes can be hard looped with For Each containertype in form first then for each ctrl in container1-2-3.controls i suppose. or if things get really messy DirectCast or CType or Find from id string would be a better approach.

          – koksalb
          Nov 21 '18 at 23:17















          Thanks for helping! I'll check it soon.

          – K.JH
          Nov 22 '18 at 22:39





          Thanks for helping! I'll check it soon.

          – K.JH
          Nov 22 '18 at 22:39





          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter