-
Mar 19th, 2012, 11:55 AM
#1
Thread Starter
Hyperactive Member
Need help assigning variable if value is equal to this/that.
Hey guys I know this is far too silly of a question but I just can't seem to figure it out.
I have 10 checkboxes on my screen.
I have a variable setup called "case" as a string
I want to know how I can say if checkbox 1 is checked then case would be equal to "this"
If checkbox2 is checked then case would = "that"
Example of something I tried to cook up but didn't work because it tells me that I can't only use this in a "select case"
Code:
Dim Case as string
If checkbox1.checked = true
case = test1
end if
If checkbox2.checked = true
case = test2
end if
If checkbox2.checked = true
case = test2
end if
If checkbox3.checked = true
case = test3
end if
If checkbox4.checked = true
case = test4
end if
If checkbox5.checked = true
case = test5
end if
-
Mar 19th, 2012, 12:03 PM
#2
Re: Need help assigning variable if value is equal to this/that.
Case is a reserved keyword. this works:
vb Code:
Dim [Case] As String
If checkbox1.checked = True Then
[Case] = test1
End If
If checkbox2.checked = True Then
[Case] = test2
End If
If checkbox2.checked = True Then
[Case] = test2
End If
If checkbox3.checked = True Then
[Case] = test3
End If
If checkbox4.checked = True Then
[Case] = test4
End If
If checkbox5.checked = True Then
[Case] = test5
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 19th, 2012, 12:05 PM
#3
Re: Need help assigning variable if value is equal to this/that.
Yeah, Case is a reserved word. Just name it something else and it will be fine. However, I would also point out that there can always be multiple checkboxes selected, so the way your code runs, the variable (whatever you name it to) will hold the value for the last checkbox that was checked. That is unlikely to be the way you want it to work. RadioButtons would be exlusive, or else you could &= things together to build all the checked items, but right now you pretty much have a strange race condition going on.
My usual boring signature: Nothing
-
Mar 19th, 2012, 12:05 PM
#4
Re: Need help assigning variable if value is equal to this/that.
*edit flood of replys in the few seconds the tab was open
The ide is telling you exactly what it is. "case" is a keyword. You can not name your string "case"
-
Mar 19th, 2012, 12:06 PM
#5
Re: Need help assigning variable if value is equal to this/that.
Three of the same replies in short order. That was quick.
Take a look at the rest of my post, though, because that point is still valid.
My usual boring signature: Nothing
-
Mar 19th, 2012, 12:41 PM
#6
Thread Starter
Hyperactive Member
Re: Need help assigning variable if value is equal to this/that.
Oh wow..never occured to me...thanks guys...
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
|