Results 1 to 6 of 6

Thread: My.Settings problem

  1. #1

    Thread Starter
    Lively Member swingyswongy's Avatar
    Join Date
    Jun 2010
    Location
    Bay area, CA
    Posts
    83

    My.Settings problem

    on close i use

    Code:
    My.Settings.SET20 = Form4.TextBox3.Text
    My.Settings.SET21 = Form1.ComboBox2.SelectedIndex

    on run i use
    Code:
    Form4.TextBox3.Text = My.Settings.SET20
    ComboBox2.SelectedIndex = My.Settings.SET21
    and then i get this error at runtime, but only the first time. Once i run it the second time its good from there on out



    Help?

  2. #2
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    774

    Re: My.Settings problem

    Do you have correct data types in the "settings" properties of the project? It looks like SET20 needs to be a string and SET21 an integer. Sorry if this is obvious stuff that you have already checked. I've only just recently used My.Settings for the first time Also, I assume you have My.Settings.Save somewhere ...

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: My.Settings problem

    when you first create the settings, they have no value... so it's possible that My.Settings.SET21 is empty... and VB doesn't know how to convert that into a number... or ... the value being returned by the settings doesn't match any indexes in combobox... suggestion - default the value of SET21 to -1 in the settings screen... then that way first time it'll have a value of -1, which means nothing will be selected.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Lively Member swingyswongy's Avatar
    Join Date
    Jun 2010
    Location
    Bay area, CA
    Posts
    83

    Re: My.Settings problem

    edit:nm
    Last edited by swingyswongy; Aug 25th, 2010 at 09:26 PM.

  5. #5

    Thread Starter
    Lively Member swingyswongy's Avatar
    Join Date
    Jun 2010
    Location
    Bay area, CA
    Posts
    83

    Re: My.Settings problem

    Quote Originally Posted by techgnome View Post
    when you first create the settings, they have no value... so it's possible that My.Settings.SET21 is empty... and VB doesn't know how to convert that into a number... or ... the value being returned by the settings doesn't match any indexes in combobox... suggestion - default the value of SET21 to -1 in the settings screen... then that way first time it'll have a value of -1, which means nothing will be selected.

    -tg
    yeah that worked! thanks!

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My.Settings problem

    How could SET21 possibly contain an empty string unless it was type String to begin with? If the setting is to hold an Integer then it should be type Integer. You will then have to give it a numeric value. The default would be zero. ALWAYS use the correct types for EVERYTHING. If something represents a number then ALWAYS us a numeric type, etc.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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