How to store option button name and value in database
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: How to store option button name and value in database

  1. #1
    Join Date
    Apr 2009
    Location
    kuala lumpur
    Posts
    7

    How to store option button name and value in database

    Hi,

    i'm currently develop a system using VB 6.0 and Access 2003.

    suppose user enter answer through the interface which is made up of option/ radio button.

    user have to answer few question before getting the result and each answer entered then compare with the value stored in database. Each answer entered by user from each question will form a pattern of solution that will have specific result. Noted i also wanted to store result in database.

    Here is my code,


    'Rule1
    ' all option button value from different frame combine together
    ' this is example if user the to select certain option button
    ' how can i store this in database and call back in code?
    If notfresh.Value = True And smelly.Value = True And yellowmescrp.Value = True Then

    ' below is the answer that suppose shows to user and each answer has weightage
    ' how can i store this also in database

    gred.unripe = 0 'the weightage
    gred.almostripe = 0 'the weightage
    gred.ripen = 0 'the weightage
    gred.emptybunch= 0 'the weightage
    gred.smelly = 10 'the weightage

    'Rule 2
    ElseIf notfresh.Value = True And smelly.Value = True And yellworangemescrp.Value = True Then

    gred.unripe = 0
    gred.almostripe = 0
    gred.ripen = 0
    gred.emptybunch = 0
    gred.smelly = 10


    End If

    pls suggest to me the design of database for above and thanks in adv for helping me.

    rgds,
    izah

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,951

    Re: How to store option button name and value in database

    Please use CODE TAGS
    Code:
    ' like this
    Also, there's a link in my signature about BOUND DATA in VB6. Check it out for full code sample
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2009
    Location
    kuala lumpur
    Posts
    7

    Smile Re: How to store option button name and value in database

    dglienna,

    if you don't mind, could you pls gimme the full title of Bound Data VB6 since there are so many title posted by you. tq.

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: How to store option button name and value in database

    I think he means this one

    Bound Controls are Evil-VB6


    btw you did not provide enough info to be able to help with database design.
    To assign the caption to a database you would typically need a text field in the database and then in code you would have

    Code:
    RS("MyField")=MyOptionButton.Caption
    And to save the value you would have a boolean field to store the value and code something like

    Code:
    RS("MyFieldValue")=MyOptionButton.Value
    Last edited by DataMiser; May 4th, 2009 at 09:04 PM.

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,951

    Re: How to store option button name and value in database

    Quote Originally Posted by izah View Post
    dglienna,

    if you don't mind, could you pls gimme the full title of Bound Data VB6 since there are so many title posted by you. tq.
    Please turn on SIGNATURE BLOCKS in your USER CP Section. It is turned OFF by default. Most users have a signature block. You can add your own as well
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: How to store option button name and value in database

    And as another thought, you better not store the caption of the control, but rather the Name of the control. As for me, some of the option buttons on a screen might even have the same caption (visible text), but must have a different Name property.

  7. #7
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: How to store option button name and value in database

    I think that depends on your coding style. In my case it would be caption and not name.

    btw if you use control arrays the name property is the same but the index is different so using the name is not fool proof either.
    Last edited by DataMiser; May 5th, 2009 at 08:00 AM.

  8. #8
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: How to store option button name and value in database

    Yes, we had another issue of passing single controls as well as control arrays to a function.

    What concerns using the caption: Some people make their software to work in other languages, too. So the caption might be different dependig on the language settings.

    Also, having controls with same caption is not a question of style but of rquirements.
    Imagine three groups of Option buttons, Size, Offset and Position, each having three Option buttons with the captions "X", "Y" and "both".

  9. #9
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: How to store option button name and value in database

    Another option would be to use the tag property. Of course I would not be using any of these as the value to put in the database. I would code the value to put in the database based on which option was selected, that value may or may not match any of the properties of the option button.

    The only way that would make much sense to use a text property of the control as the data which will go into the database is if you are using a loop to loop through the option buttons and update within. otherwise I would just associate a value through code directly and not even worry about names , tags and captions.

  10. #10
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: How to store option button name and value in database

    Quote Originally Posted by WoF View Post
    What concerns using the caption: Some people make their software to work in other languages, too. So the caption might be different dependig on the language settings.
    Keep in mind that this might be exactly what the user wants. Not much point in placing text in the database that is in a different language than the user understands.

  11. #11
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: How to store option button name and value in database

    Right, ok, ok. Point taken.
    But the name of a control will not change in any language.
    So you could store the Name, the Value, and if it is an arry you store the index, too, which si kept -1 when it is not an array.

  12. #12
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,951

    Re: How to store option button name and value in database

    As long as your query will always be the same then the easiest way is to use control index numbers that correspond to field numbers that are returned.

    Whether you pick col(2) or col(5) as the first column, you can use txt(0) to refer to .field(0), and loop thru the indexes
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  13. #13
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: How to store option button name and value in database

    Yes. I use this method quite often. Can be difficult to tell what field a given text box refers to when looking at the code but if you have 30-50 fields a for next loop with 3 or 4 lines of code is much prefered over the would be 30-50 lines to assign the data.

  14. #14
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,951

    Re: How to store option button name and value in database

    When there are too many to manage, I use the TAG event
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  15. #15
    Join Date
    Apr 2009
    Posts
    394

    Re: How to store option button name and value in database

    That would be the Tag Property D

Page 1 of 2 12 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center