Results 1 to 12 of 12

Thread: Option Buttons (!!!)

  1. #1

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    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...
    Chris

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    Set one to true, the other will automatically be set to false.

    As in:

    Opt1.value = true

  3. #3

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    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.
    Chris

  4. #4
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    instead of making 1 of them false, make the other one true
    NXSupport - Your one-stop source for computer help

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You should make your optionbuttons an array so that you can easyly set the first index to true
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Guest
    You can combine lines with a semicolon so it will appear as one.
    Code:
    Option1.Value = True: Option2.Value = False

  7. #7

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    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
    Chris

  8. #8
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    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
    NXSupport - Your one-stop source for computer help

  9. #9

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    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.
    Chris

  10. #10
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    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
    NXSupport - Your one-stop source for computer help

  11. #11

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    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.
    Chris

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Using an array you could have one line
    Code:
    opt1(-(dbfield = "male"))=true
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width