One Check Box At A Time

Allowing Only One Check Box To Be Selected

Page 1 of 1

7 Replies - 18441 Views - Last Post: 17 November 2006 - 01:16 AM Rate Topic: -----

#1 supercharged_V6   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 03-October 06

One Check Box At A Time

Posted 11 October 2006 - 06:25 PM

Hi, i am trying to make this work. I am working on a program to calculate a checking account. but i have 3 options available. DEPOSIT, CHECK and SERVICE FEE. They are under check box. What can i use to only be able to select one box. For example if you select deposit, then the check box for CHECK goes blank, and the one for service FEE too... in other words, be able to select one box at a time. anyone understand. here is the code.

Option Explicit
	Dim curBeginning	As Currency
	Dim curAmountOne	As Currency
	Dim curAmountTwo	As Currency
	Dim curFinalBalance As Currency
	






Private Sub cmdCalculate_Click()
curBeginning = Val(txtBeginngBalance.Text)
curAmountOne = Val(txtAmountOne.Text)
curAmountTwo = Val(txtAmountTwo.Text)

If chkDepositOne.Value = 1 And chkDepositTwo.Value = 1 Then
	curFinalBalance = curAmountOne + curAmountTwo + curBeginning
End If
If chkDepositOne.Value = 1 And chkCheckTwo.Value = 1 Then
	curFinalBalance = (curAmountOne - curAmountTwo) + curBeginning
End If
If chkDepositOne.Value = 1 And chkServiceTwo.Value = 1 Then
	curFinalBalance = (curAmountOne - curAmountTwo) + curBeginning
End If
If chkCheckOne.Value = 1 And chkDepositTwo.Value = 1 Then
	curFinalBalance = (curAmountOne - curBeginning) + curAmountTwo
End If
If chkCheckOne.Value = 1 And chkServiceTwo.Value = 1 Then
	curFinalBalance = (curAmountOne + curAmountTwo) - curBeginning
End If
If chkCheckOne.Value = 1 And chkCheckTwo.Value = 1 Then
	curFinalBalance = (curAmountOne + curAmountTwo) - curBeginning
End If
If chkServiceOne.Value = 1 And chkDepositTwo.Value = 1 Then
	curFinalBalance = (curAmountTwo + curBeginning) - curAmountOne
End If
If chkServiceOne.Value = 1 And chkCheckTwo.Value = 1 Then
	curFinalBalance = (curAmountOne + curAmountTwo) - curBeginning
End If
If chkServiceOne.Value = 1 And chkServiceTwo.Value = 1 Then
	curFinalBalance = (curAmountOne + curAmountTwo) - curBeginning
End If

lblFinalBalance.Caption = FormatCurrency(curFinalBalance)
End Sub

Private Sub cmdClear_Click()
lblFinalBalance.Caption = ""
txtAmountOne.Text = ""
txtAmountTwo.Text = ""
txtBeginngBalance.Text = ""
chkCheckOne.Value = 0
chkCheckTwo.Value = 0
chkDepositOne.Value = 0
chkDepositTwo.Value = 0
chkServiceOne.Value = 0
chkServiceTwo.Value = 0
End Sub

Private Sub cmdExit_Click()
End
End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: One Check Box At A Time

#2 BlackJesus   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 161
  • Joined: 10-February 05

Re: One Check Box At A Time

Posted 12 October 2006 - 04:27 AM

i would just use radio buttons instead of check boxes
Was This Post Helpful? 0
  • +
  • -

#3 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: One Check Box At A Time

Posted 12 October 2006 - 05:04 AM

Maintain a boolean variable which would hold true if a checkbox is checked.
Whenever a new one is clicked, it should check itself only if the variable is false.

Don't forget to include code that changes the state of the boolean variable, as the design is useless without that.

But instead of doing all this, use a Radio Button...it was created for this very purpose.
Was This Post Helpful? 0
  • +
  • -

#4 Ryan747   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 16-October 06

Re: One Check Box At A Time

Posted 16 October 2006 - 07:44 PM

private sub chkDepositOne_click()
if chkDepositOne.value = 1 then
   chkCheckOne.Value = 0
   chkServiceOne.value = 0
endif
end sub

private sub chkCheckOne_click()
if chkCheckOne.value = 1 then
   chkDepositOne.value = 0
   chkServiceOne.value = 0
endif
end sub

private sub chkServiceOne_click()
if chkServiceOne.value = 1 then
   chkDepositOne.value = 0
   chkCheckOne.value = 0
endif
end sub



this is how I would do it for me to be able to select one checkbox at a time.

hope this would be helpful to you!!!
Was This Post Helpful? 1

#5 William_Wilson   User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: One Check Box At A Time

Posted 16 October 2006 - 08:33 PM

been a while since i used vb, but the idea behind check boxes is that multiple boxes can be checked, for single items, radio buttons really are what you're looking for!
Was This Post Helpful? 0
  • +
  • -

#6 bobby83   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-October 06

Re: One Check Box At A Time

Posted 18 October 2006 - 07:30 PM

try tu use Option Button! :D
Was This Post Helpful? 0
  • +
  • -

#7 KeyWiz   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 439
  • Joined: 26-October 06

Re: One Check Box At A Time

Post icon  Posted 27 October 2006 - 12:55 PM

If you don't want to use radio buttons, you could set the program to make the other check boxes automatically blanked

put these lines of code into the approprite ckBox_Click methods.


if ckBox1.value = true then ckBox2.value = false: ckBox3.value = false

if ckBox2.value = true then ckBox1.value = false: ckBox3.value = false

if ckBox3.value = true then ckBox2.value = false: ckBox1.value = false
Was This Post Helpful? 0
  • +
  • -

#8 Tiamatte   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-November 06

Re: One Check Box At A Time

Posted 17 November 2006 - 01:16 AM

I would use a loop to acheive the effect you are after, such as


Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
		Dim x As Integer = Me.CheckedListBox1.SelectedIndex

		Dim i As Integer
		For i = 0 To Me.CheckedListBox1.Items.Count - 1
			Me.CheckedListBox1.SetItemChecked(i, False)
		Next i
		Me.CheckedListBox1.SetItemChecked(x, True)

	End Sub


this would allow you to even add more to the checkbox without having to add three million lines to the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1