so its been a verrrry long time since I messed around with vb. I am trying to make a program for my clan and here is a simple question I hope some one can answer. I am trying to make a button activate a radiobutton to checked if you press the button. If its already checked then to uncheck it. The code im using is sending my prog into a loop I think. Can i get some help code is as follows.. please try not to be harsh, this is the first time Ive used vb since late 90s. thank you guys.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonflaga.Click
RadioButtonAsel.Refresh()
If RadioButtonAsel.Checked = False Then RadioButtonAsel.Checked = True

If RadioButtonAsel.Checked = True Then RadioButtonAsel.Checked = False
End Sub

also while Ive been playing around and trying to find an answer on my own, I figured maybe Ill just use a clear button. I have 3 buttons and 3 radiobuttons, can I have more than one raidobutton active? It looks great for a selected item. Im using the radio button to show that you have activated that button. If that makes any sense.

Dani AI

Generated

A quick diagnosis and compact fixes for the two issues raised by , plus a small helper for the flag/score math.

Your toggle logic was running both branches: the first If sets the radio to True and the second immediately sets it back to False. Replace the two separate Ifs with a single toggle or an If/Else so the control only changes once. A minimal one-liner:

' Button click: toggle the checked state
RadioButtonAsel.Checked = Not RadioButtonAsel.Checked

Note: as suggested, radio buttons that live in the same container are meant for one choice only. If you want multiple “active” indicators at once, use CheckBox controls instead.

If you have CheckedChanged handlers that also change Checked programmatically, protect against recursion with a simple guard:

Private suppressEvents As Boolean = False

Private Sub Buttonflaga_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Buttonflaga.Click
    suppressEvents = True
    RadioButtonAsel.Checked = Not RadioButtonAsel.Checked
    suppressEvents = False
End Sub

Private Sub RadioButtonAsel_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles RadioButtonAsel.CheckedChanged
    If suppressEvents Then Exit Sub
    ' normal user-driven handling here
End Sub

For the scoring/capture math: treat each 5-second tick as one unit and compute ticks needed = ceiling((goal - current) / pointsPerTick). Example helper and usage:

Function TicksToWin(goal As Integer, current As Integer, ptsPerTick As Integer) As Integer
    If current >= goal Then Return 0
    If ptsPerTick <= 0 Then Return Integer.MaxValue
    Return CInt(Math.Ceiling((goal - current) / CDbl(ptsPerTick)))
End Function

Compare the ticks for both sides. If ticks are equal and the game applies points simultaneously, both reach the goal together; if the game applies points in order inside a tick, simulate tick-by-tick in that order to break ties.

Recommended Answers

All 4 Replies

if you put radio/option buttons in one frame then only one can be active, you should use the checkbox for that
for an option button the property is
option1.value= true/false

if you put radio/option buttons in one frame then only one can be active, you should use the checkbox for that
for an option button the property is
option1.value= true/false

thank you so much. just playing around has started to bring out some old memories. Im loving it, and hating it, but thats the love :). and thank you so much for the solution. Is there any way I could pick your brain on a few other issues?

if i can

I just sent you a message, I would say we can do it there, so we dont clog the forums. Many forums dislike off subject topic. But one more problem here shouldnt hurt. It involves a counter. I have a count based on a video game. The video game is a shooter where you have to control 3 flags. for each flag you gain a point every 5 seconds. Im trying to make a program that can tell me if input a current score, how many flags i need to win and or can i win holding the x amount of flags I currently have. so i need a counter(s) that counts up in incriments of 1, ends at 200, but if a option is selected either count by x2 or x3 the point,(not times just 2 or 2 points per 5 seconds) i dont think the 5 seconds actaully matter cause i want it to instantly tell me. IE ( 150 to 150 ) 200 points to win, my team controls 2 of 3 flags, every 5 seconds i get 2 poitns and they get 1. I know Ill win that situation. Is there a way i can set counters up for that to see which one will reach 200 first and give me output?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.