-
Hmmm.. I guess I'm too lazy to spend the needed time in browsing the the help files so here I am.
Stupid question I think, since I`ve done that millions of times in Access. But now in VB: I've succesfully created exclusive option buttons (2) on a form by creating them both in a frame.
To assign a value to these option buttons by code, in Access, all you had to do is give the frame a value (True or False), and the appropriate Option button would become clicked. In VB this just won't work.. what's the best way of doing this? I'm trying to avoid having 2 lines of code:
opt1.value = true
opt2.value = false
I'm sure you guys get the idea - thanks...
-
Set one to true, the other will automatically be set to false.
As in:
Opt1.value = true
-
Of course I've already tried this - that's how it works in Access.
But it doesn't work in VB. Setting opt1.value = False won't make opt2.value = True. Both of them will then be False. And I did check twice to make sure they're exclusive.
How can I fix that? Btw, they're both in a vb frame.
Thanks.
-
instead of making 1 of them false, make the other one true
-
You should make your optionbuttons an array so that you can easyly set the first index to true
-
You can combine lines with a semicolon so it will appear as one.
Code:
Option1.Value = True: Option2.Value = False
-
dimava: Yes, but that way, I need 2 lines of code. Let's say I'm making a lookup from a database, the code would look like this:
opt1.value = iif(dbfield = "Male";True;False)
This sets the option value in only one line of code. Do you understand what I mean by that? In access, if dbfield is "Female", the opt2.value will automatically be set to true by setting opt1.value to false. You may find it a bit exagerated to save only one line of code but I really believe that, for some reasons, I do need that.
kedaman: Will using an array let me fix the problem described above?
Thanks to you guys
-
why do you need to lines of code
[code]
(bold means checked)
O Male
O FeMale
'to get that then you write
optMale.value = true
'and the other will automaticly become un checked
Code:
O Male
O FeMale
'to get that then you write
optFeMale.value = true
'and the otehr will automaticly become un checked
-
I'm beginning to give up on my one line of code idea, just like access could do it using a frame.
dimava, it does take 2 lines of code or.. I dunno, an IF, to evaluate which option button I must set to true. you understand? If not, try coding it :) I know it takes one line to set an option button to true but what I was saying is that in Access, you can always set the value on the first option button (true OR false), and the other one will react accordingly. This was done on one line. (I know I can put 20 lines of code on only one line, using ":") :)
Anyway I see it's not possible in VB, I'm giving up, gonna do something like:
if dbfield = "Male" then
opt1.value = true: opt2.value = false
else
opt1.value = false: opt2.value = true
end if
voila.
-
what you are trying to do is gonna take up 2 lines (at least)
Code:
if dbfield = "male" then
opt1.value = true
else opt2.value = true
-
Yes that would be more like it.. my code exemple was written on the fly...
...still wonder why they didn't to it like in access tho.
-
Using an array you could have one line
Code:
opt1(-(dbfield = "male"))=true