|
-
Apr 11th, 2004, 04:51 PM
#1
Thread Starter
Hyperactive Member
Control Array Problem - Solved
VB Code:
Private Sub Form_Unload(Cancel As Integer)
Dim varProduct1 As String, Selected As Integer, I As Integer
For I = 0 To Product().Count - 1
If Product(I).Value = Checked Then
Select Case Product(I)
Case 0
varProduct1 = "STAR"
Case 1
varProduct1 = "SEXP"
Case 2
varProduct1 = "W2BN"
Case 3
varProduct1 = "D2DV"
Case 4
varProduct1 = "D2XP"
Case 5
varProduct1 = "WAR3"
Case 6
varProduct1 = "W3XP"
End Select
End If
Next I
WriteStuff "Main", "Username", txtUsername.text
WriteStuff "Main", "Password", txtPassword.text
WriteStuff "Main", "Home", txtHome.text
WriteStuff "Main", "Server", txtServer.text
WriteStuff "Main", "CDKey", txtCDKey.text
WriteStuff "Main", "Cdkey2", txtCDKey2.text
WriteStuff "Main", "Cdkey2", txtCDKey2.text
WriteStuff "Main", "Product", varProduct1
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.
-
Apr 11th, 2004, 04:55 PM
#2
VB Code:
Private Sub Product_Click(Index As Integer)
For i = 0 To Product.Count - 1
Product.Item(i).Value = 0
Next i
Product.Item(Index).Value = 1
End Sub
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 11th, 2004, 04:56 PM
#3
Thread Starter
Hyperactive Member
Read it again phreak, i edited it!
-
Apr 11th, 2004, 04:59 PM
#4
Thread Starter
Hyperactive Member
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!
-
Apr 11th, 2004, 05:01 PM
#5
Ok, I hate being fast to reply 
All you have to do is set a flag to which one is checked.
VB Code:
Dim checked_box As Integer
checked_box = 0
Private Sub Product_Click(Index As Integer)
For i = 0 To Product.Count - 1
Product.Item(i).Value = 0
Next i
checked_box = Index
Product.Item(Index).Value = 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim varProduct1 As String
Select Case checked_box
Case 0:
varProduct1 = "STAR"
Case 1:
varProduct1 = "SEXP"
Case 2:
varProduct1 = "W2BN"
Case 3:
varProduct1 = "D2DV"
Case 4:
varProduct1 = "D2XP"
Case 5:
varProduct1 = "WAR3"
Case 6:
varProduct1 = "W3XP"
End Select
WriteStuff "Main", "Username", txtUsername.text
WriteStuff "Main", "Password", txtPassword.text
WriteStuff "Main", "Home", txtHome.text
WriteStuff "Main", "Server", txtServer.text
WriteStuff "Main", "CDKey", txtCDKey.text
WriteStuff "Main", "Cdkey2", txtCDKey2.text
WriteStuff "Main", "Cdkey2", txtCDKey2.text
WriteStuff "Main", "Product", varProduct1
End Sub
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 11th, 2004, 05:04 PM
#6
Thread Starter
Hyperactive Member
still getting Out Of Stack Space Error
Does that mean i am out of Memory?
-
Apr 11th, 2004, 05:09 PM
#7
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
-
Apr 11th, 2004, 05:16 PM
#8
Thread Starter
Hyperactive Member
VB Code:
Public NN As Node
Dim checked_box As Integer
Dim varProduct As String
Dim varProduct1 As String
Private Sub Form_Load()
AddTree "Main1", "Main", "P"
AddTree "Main1", "Login", "C"
txtUsername.text = GetStuff("Main", "Username")
txtPassword.text = GetStuff("Main", "Password")
txtHome.text = GetStuff("Main", "Home")
txtServer.text = GetStuff("Main", "Server")
txtCDKey.text = GetStuff("Main", "Cdkey")
txtCDKey2.text = GetStuff("Main", "Cdkey2")
varProduct = UCase(GetStuff("Main", "Product"))
Select Case varProduct
Case "STAR"
Product(0).Value = Checked
Case "SEXP"
Product(1).Value = Checked
Case "W2BN"
Product(2).Value = Checked
Case "D2DV"
Product(3).Value = Checked
Case "D2XP"
Product(4).Value = Checked
Case "WAR3"
Product(5).Value = Checked
Case "W3XP"
Product(6).Value = Checked
End Select
End Sub
Public Function AddTree(ByVal Name, ByVal Capt, ByVal PC)
Dim NodeC As Variant
Select Case PC
Case "P"
Set NN = TreeSetup.Nodes.Add(, , Name, Capt)
Case "C"
NodeC = NodeC & NodeC
Set NN = TreeSetup.Nodes.Add(Name, tvwChild, NodeC, Capt)
End Select
End Function
Public Function SelectFrame(ByVal Inx As Integer, ByVal Vis As Boolean, ByVal frm As Frame)
If TreeSetup.Nodes.Item(Inx).Selected = True Then
Select Case Vis
Case True
frm.Visible = True
Case False
frm.Visible = False
End Select
End If
End Function
Private Sub Product_Click(Index As Integer)
checked_box = 0
For I = 0 To Product.Count - 1
Product.Item(I).Value = 0
Next I
checked_box = Index
Product.Item(Index).Value = 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Select Case checked_box
Case 0:
varProduct1 = "STAR"
Case 1:
varProduct1 = "SEXP"
Case 2:
varProduct1 = "W2BN"
Case 3:
varProduct1 = "D2DV"
Case 4:
varProduct1 = "D2XP"
Case 5:
varProduct1 = "WAR3"
Case 6:
varProduct1 = "W3XP"
End Select
WriteStuff "Main", "Username", txtUsername.text
WriteStuff "Main", "Password", txtPassword.text
WriteStuff "Main", "Home", txtHome.text
WriteStuff "Main", "Server", txtServer.text
WriteStuff "Main", "CDKey", txtCDKey.text
WriteStuff "Main", "Cdkey2", txtCDKey2.text
WriteStuff "Main", "Cdkey2", txtCDKey2.text
WriteStuff "Main", "Product", varProduct1
End Sub
Private Sub TreeSetup_Click()
SelectFrame "2", "True", Frame1
End Sub
That's my Enite code.. i don't see anything interfearing.. maybe i set up my Control Array Wrong?
-
Apr 11th, 2004, 05:21 PM
#9
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
-
Apr 11th, 2004, 05:22 PM
#10
Thread Starter
Hyperactive Member
-
Apr 11th, 2004, 05:26 PM
#11
What line does it highlight?
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 11th, 2004, 05:29 PM
#12
Thread Starter
Hyperactive Member
VB Code:
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
-
Apr 11th, 2004, 05:30 PM
#13
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.
-
Apr 11th, 2004, 05:32 PM
#14
Thread Starter
Hyperactive Member
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!
-
Apr 11th, 2004, 05:36 PM
#15
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.
-
Apr 11th, 2004, 05:37 PM
#16
Thread Starter
Hyperactive Member
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
-
Apr 11th, 2004, 05:37 PM
#17
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
-
Apr 11th, 2004, 05:40 PM
#18
VB Code:
Private Sub Checkbox_Click(Index As Integer)
Static booFlag As Boolean 'Initially False
If booFlag = True Then Exit Sub
booFlag = True
'Your code goes here
booFlag = False 'reset to false after update
End Sub
Same applies with textbox change event, it can also cascade. Just in case so you know...
-
Apr 11th, 2004, 05:40 PM
#19
Thread Starter
Hyperactive Member
VB Code:
Private Sub Product_Click(Index As Integer)
Static Blah As Boolean
If Blah = True Then: Exit Sub
checked_box = 0
For I = 0 To Product.Count - 1
Blah = True
Product.Item(I).Value = 0
Next I
Blah = False
checked_box = Index
Product.Item(Index).Value = 1
End Sub
that was my attempt.. still didn't work..
-
Apr 11th, 2004, 05:42 PM
#20
Originally posted by BaDDBLooD
VB Code:
Private Sub Product_Click(Index As Integer)
Static Blah As Boolean
If Blah = True Then: Exit Sub
checked_box = 0
For I = 0 To Product.Count - 1
Blah = True
Product.Item(I).Value = 0
Next I
Blah = False
checked_box = Index
Product.Item(Index).Value = 1
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
-
Apr 11th, 2004, 05:43 PM
#21
Thread Starter
Hyperactive Member
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
-
Apr 11th, 2004, 05:45 PM
#22
Yup... I already did. The difference is that your algorithm is nested between the flag check and set/reset.
-
Apr 11th, 2004, 05:47 PM
#23
You need to set the flag to true once its started:
VB Code:
Private Sub Product_Click(Index As Integer)
Static Blah As Boolean
If Blah = True Then: Exit Sub
Blah = True ' <--
checked_box = 0
For I = 0 To Product.Count - 1
Blah = True
Product.Item(I).Value = 0
Next I
checked_box = Index
Product.Item(Index).Value = 1
Blah = False
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|