Results 1 to 23 of 23

Thread: Control Array Problem - Solved

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Control Array Problem - Solved

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.  
    3. Dim varProduct1 As String, Selected As Integer, I As Integer
    4.  
    5.     For I = 0 To Product().Count - 1
    6.    
    7.     If Product(I).Value = Checked Then
    8.    
    9.         Select Case Product(I)
    10.  
    11.             Case 0
    12.                 varProduct1 = "STAR"
    13.        
    14.             Case 1
    15.                 varProduct1 = "SEXP"
    16.        
    17.             Case 2
    18.                 varProduct1 = "W2BN"
    19.        
    20.             Case 3
    21.                 varProduct1 = "D2DV"
    22.        
    23.             Case 4
    24.                 varProduct1 = "D2XP"
    25.        
    26.             Case 5
    27.                 varProduct1 = "WAR3"
    28.        
    29.             Case 6
    30.                 varProduct1 = "W3XP"
    31.        
    32.         End Select
    33.    
    34.     End If
    35.    
    36.     Next I
    37.  
    38.     WriteStuff "Main", "Username", txtUsername.text
    39.     WriteStuff "Main", "Password", txtPassword.text
    40.     WriteStuff "Main", "Home", txtHome.text
    41.     WriteStuff "Main", "Server", txtServer.text
    42.     WriteStuff "Main", "CDKey", txtCDKey.text
    43.     WriteStuff "Main", "Cdkey2", txtCDKey2.text
    44.     WriteStuff "Main", "Cdkey2", txtCDKey2.text
    45.     WriteStuff "Main", "Product", varProduct1
    46.    
    47. End Sub

    I have a array of Checkboxes, Product(x). X = 0,1,2,3,4,5

    1) I want to be Able to Detect which Option is Displayed, and Give it a Name ( varProduct1 )

    2) when i Click one Checkbox, the rest of the Checked Boxes Become Unchecked

    THe Above code doesn't seem to be working, and i am not sure how to do #2
    Last edited by BaDDBLooD; Apr 11th, 2004 at 06:35 PM.

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    VB Code:
    1. Private Sub Product_Click(Index As Integer)
    2. For i = 0 To Product.Count - 1
    3. Product.Item(i).Value = 0
    4. Next i
    5. Product.Item(Index).Value = 1
    6. End Sub

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    Read it again phreak, i edited it!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    i had to change it to

    For I = 0 To Product.Count - 1

    Because i don't have 7 Items ;P

    i get the error: out of stack space, when i try to run!

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Ok, I hate being fast to reply


    All you have to do is set a flag to which one is checked.

    VB Code:
    1. Dim checked_box As Integer
    2.  
    3. checked_box = 0
    4.  
    5. Private Sub Product_Click(Index As Integer)
    6. For i = 0 To Product.Count - 1
    7. Product.Item(i).Value = 0
    8. Next i
    9. checked_box = Index
    10. Product.Item(Index).Value = 1
    11. End Sub
    12.  
    13. Private Sub Form_Unload(Cancel As Integer)
    14. Dim varProduct1 As String
    15. Select Case checked_box
    16.             Case 0:
    17.                 varProduct1 = "STAR"
    18.             Case 1:
    19.                 varProduct1 = "SEXP"
    20.             Case 2:
    21.                 varProduct1 = "W2BN"
    22.             Case 3:
    23.                 varProduct1 = "D2DV"
    24.             Case 4:
    25.                 varProduct1 = "D2XP"
    26.             Case 5:
    27.                 varProduct1 = "WAR3"
    28.             Case 6:
    29.                 varProduct1 = "W3XP"
    30.         End Select
    31.  
    32.     WriteStuff "Main", "Username", txtUsername.text
    33.     WriteStuff "Main", "Password", txtPassword.text
    34.     WriteStuff "Main", "Home", txtHome.text
    35.     WriteStuff "Main", "Server", txtServer.text
    36.     WriteStuff "Main", "CDKey", txtCDKey.text
    37.     WriteStuff "Main", "Cdkey2", txtCDKey2.text
    38.     WriteStuff "Main", "Cdkey2", txtCDKey2.text
    39.     WriteStuff "Main", "Product", varProduct1
    40. End Sub

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    still getting Out Of Stack Space Error

    Does that mean i am out of Memory?

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    You must have some other code somewhere doing it. Such code as that I gave you wouldn't produce that. Try my code again, works for me.


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    VB Code:
    1. Public NN As Node
    2. Dim checked_box As Integer
    3. Dim varProduct As String
    4. Dim varProduct1 As String
    5.  
    6. Private Sub Form_Load()
    7.  
    8. AddTree "Main1", "Main", "P"
    9. AddTree "Main1", "Login", "C"
    10.  
    11. txtUsername.text = GetStuff("Main", "Username")
    12. txtPassword.text = GetStuff("Main", "Password")
    13. txtHome.text = GetStuff("Main", "Home")
    14. txtServer.text = GetStuff("Main", "Server")
    15. txtCDKey.text = GetStuff("Main", "Cdkey")
    16. txtCDKey2.text = GetStuff("Main", "Cdkey2")
    17. varProduct = UCase(GetStuff("Main", "Product"))
    18.  
    19. Select Case varProduct
    20.  
    21.     Case "STAR"
    22.         Product(0).Value = Checked
    23.        
    24.     Case "SEXP"
    25.         Product(1).Value = Checked
    26.        
    27.     Case "W2BN"
    28.         Product(2).Value = Checked
    29.        
    30.     Case "D2DV"
    31.         Product(3).Value = Checked
    32.        
    33.     Case "D2XP"
    34.         Product(4).Value = Checked
    35.        
    36.     Case "WAR3"
    37.         Product(5).Value = Checked
    38.        
    39.     Case "W3XP"
    40.         Product(6).Value = Checked
    41.        
    42. End Select
    43.  
    44. End Sub
    45.  
    46. Public Function AddTree(ByVal Name, ByVal Capt, ByVal PC)
    47.  
    48. Dim NodeC As Variant
    49.  
    50.     Select Case PC
    51.      
    52.         Case "P"
    53.            
    54.             Set NN = TreeSetup.Nodes.Add(, , Name, Capt)
    55.              
    56.         Case "C"
    57.  
    58.             NodeC = NodeC & NodeC
    59.             Set NN = TreeSetup.Nodes.Add(Name, tvwChild, NodeC, Capt)
    60.              
    61.     End Select
    62.      
    63.  End Function
    64.  
    65.  Public Function SelectFrame(ByVal Inx As Integer, ByVal Vis As Boolean, ByVal frm As Frame)
    66.  
    67.      If TreeSetup.Nodes.Item(Inx).Selected = True Then
    68.      
    69.          Select Case Vis
    70.          
    71.              Case True
    72.                  frm.Visible = True
    73.                  
    74.              Case False
    75.                  frm.Visible = False
    76.                  
    77.          End Select
    78.          
    79.      End If
    80.      
    81.  End Function
    82.  
    83. Private Sub Product_Click(Index As Integer)
    84.  
    85. checked_box = 0
    86. For I = 0 To Product.Count - 1
    87. Product.Item(I).Value = 0
    88. Next I
    89. checked_box = Index
    90. Product.Item(Index).Value = 1
    91. End Sub
    92.  
    93. Private Sub Form_Unload(Cancel As Integer)
    94.  
    95. Select Case checked_box
    96.             Case 0:
    97.                 varProduct1 = "STAR"
    98.             Case 1:
    99.                 varProduct1 = "SEXP"
    100.             Case 2:
    101.                 varProduct1 = "W2BN"
    102.             Case 3:
    103.                 varProduct1 = "D2DV"
    104.             Case 4:
    105.                 varProduct1 = "D2XP"
    106.             Case 5:
    107.                 varProduct1 = "WAR3"
    108.             Case 6:
    109.                 varProduct1 = "W3XP"
    110.         End Select
    111.  
    112.     WriteStuff "Main", "Username", txtUsername.text
    113.     WriteStuff "Main", "Password", txtPassword.text
    114.     WriteStuff "Main", "Home", txtHome.text
    115.     WriteStuff "Main", "Server", txtServer.text
    116.     WriteStuff "Main", "CDKey", txtCDKey.text
    117.     WriteStuff "Main", "Cdkey2", txtCDKey2.text
    118.     WriteStuff "Main", "Cdkey2", txtCDKey2.text
    119.     WriteStuff "Main", "Product", varProduct1
    120. End Sub
    121.  
    122. Private Sub TreeSetup_Click()
    123.  
    124. SelectFrame "2", "True", Frame1
    125.  
    126. End Sub

    That's my Enite code.. i don't see anything interfearing.. maybe i set up my Control Array Wrong?

  9. #9
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    I don't see anything either. Try restarting your PC, then running it. If that doesn't help, I'm not sure. You could try re-dimensioning those variants to a data type less memory consuming.


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    yeah i did restart ;|

  11. #11
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    What line does it highlight?


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    VB Code:
    1. Product.Item(I).Value = 0

    EDIT: any other way i can Do what i want?

    Look in a .ini File and See what The user Specified.

    Check a Certain Checkbox in a array

    User can Check / Uncheck one checkbox to make a change, and the rest will go Unchecked/Checked.

    It Converts the Number of the Checked Box into a String back into the Client ID to go back to the Config

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    In the click event, use a static boolean flag... set the flag to true when your about to update the values, reset to false afterwards. At the very beginning of the click event, if the flag is true then immediately exit the sub.

    What happens is that everytime you set a new value to the checkbox, the click event is fired... Since in the click event you again assign new values the click event is again fired.

    It cascades that's why you ran out of stack space.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    Originally posted by leinad31
    In the click event, use a static boolean flag... set the flag to true when your about to update the values, reset to false afterwards. At the very beginning of the click event, if the flag is true then immediately exit the sub.

    What happens is that everytime you set a new value to the checkbox, the click event is fired... Since in the click event you again assign new values the click event is again fired.

    It cascades that's why you ran out of stack space.
    i am not sure what you mean by that, but maybe phreak does!

  15. #15
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Say you updated checkbox(3).value = 1, the click event is fired... you loop through and update checkbox(0).value = 0. Immediatley the click event is again fired even though you havent finished with the loop.... and it happens again and again each time you update.

    Your call stack is filled with Checkbox click events.

    What the flag will do is ignore succeeding click events when your already doing the update. Although the event is refired, it is immediately ended.
    Last edited by leinad31; Apr 11th, 2004 at 05:44 PM.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    that makes sence, but am not sure how to fix it given what you said.

    let me play around for a bit.. i'll look back in a bit

  17. #17
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246



    Well spotted...I wasn't paying much attention to the top, as I thought it was with my codes area..



    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  18. #18
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    VB Code:
    1. Private Sub Checkbox_Click(Index As Integer)
    2. Static booFlag As Boolean  'Initially False
    3.  
    4.    If booFlag = True Then Exit Sub
    5.  
    6.    booFlag = True
    7.    'Your code goes here
    8.  
    9.    booFlag = False 'reset to false after update
    10. End Sub

    Same applies with textbox change event, it can also cascade. Just in case so you know...

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    VB Code:
    1. Private Sub Product_Click(Index As Integer)
    2. Static Blah As Boolean
    3.  
    4. If Blah = True Then: Exit Sub
    5.  
    6. checked_box = 0
    7. For I = 0 To Product.Count - 1
    8. Blah = True
    9. Product.Item(I).Value = 0
    10. Next I
    11. Blah = False
    12. checked_box = Index
    13. Product.Item(Index).Value = 1
    14. End Sub

    that was my attempt.. still didn't work..

  20. #20
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Originally posted by BaDDBLooD
    VB Code:
    1. Private Sub Product_Click(Index As Integer)
    2. Static Blah As Boolean
    3.  
    4. If Blah = True Then: Exit Sub
    5.  
    6. checked_box = 0
    7. For I = 0 To Product.Count - 1
    8. Blah = True
    9. Product.Item(I).Value = 0
    10. Next I
    11. Blah = False
    12. checked_box = Index
    13. Product.Item(Index).Value = 1
    14. End Sub

    that was my attempt.. still didn't work..
    Cause you already set the flag to False but still did an update Product.Item(Index).Value = 1 so it still cascades since you havent exited the sub yet

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301
    Originally posted by leinad31
    Cause you already set the flag to False but still did an update Product.Item(Index).Value = 1 so it still cascades
    \

    Show me a fix, and explain what you did differently, please?

    Thanks a bunch

    - BaDDBLooD

  22. #22
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Yup... I already did. The difference is that your algorithm is nested between the flag check and set/reset.

  23. #23
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    You need to set the flag to true once its started:
    VB Code:
    1. Private Sub Product_Click(Index As Integer)
    2. Static Blah As Boolean
    3.  
    4. If Blah = True Then: Exit Sub
    5.  
    6. Blah = True ' <--
    7. checked_box = 0
    8. For I = 0 To Product.Count - 1
    9. Blah = True
    10. Product.Item(I).Value = 0
    11. Next I
    12. checked_box = Index
    13. Product.Item(Index).Value = 1
    14. Blah = False
    15. End Sub

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width