Some quick questions about My.Settings

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
Hey, I think I'm going to try using a listbox or dropdown box for the favorite zip codes in my program instead of trying to deal with deleting a dropdown menu item. I haven't worked with My.Settings yet, and I need to know one thing. If I have a variable saved there called FavoriteZip1, and it hasn't been used yet by the person, if I want to refer to its current state in my program, is it equal to Nothing, or ""? Thanks.

Also, I've been noticing that there's a ZIP code being added to the drop down box when I run the program to debug. I keep using my delete feature, but it's still there the next time I run it. I can't figure out where it's being saved. How do I get rid of it so my users don't have that ZIP when they get the program?
 
Last edited:
You could initialize FavoriteZip1 with a value "" that would make it easy to check for.
Dim FavoriteZip1 As String = ""

Make sure the drop down box doesn't have any items defined in it's properties under DATA => ITEMS => COLLECTIONS
Make sure you are not assigning a value to it at startup.
 
That seems like it could be a problem doing it that way since I'm saving these variables so their favorites list refreshes when they restart the program. I'm using My.Settings.FavoriteZIP1. If they have a zip code saved there, I don't want to initialize it to "" when the form loads, or they'll lose that zip code. I fixed the variable being saved from my earlier testing. Now I just need to know if I have a variable that hasn't been set yet and I want to refer to its current state if it's Nothing or "". Thanks.

Another quick question. What's the event for when they click on a selection on a tool strip combo box? I found this (
Private
Sub ToolStripComboBox1_Click) but that's just for when they click the combo box. I need something for when they select an item, so I can do something with the text. Keep in mind that I don't know what that text is now or what order it is in, because they'll add and delete how they want.
 
Last edited:
Not sure about tool strip combobox but for a combobox you use the selected index changed event.

VB.NET:
     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged


    End Sub

As for the saved zip, is it a string? You could see if anything is there by:
If FavoriteZip1 > "" Then
'there is something saved
End If

Sorry if I'm not much help, I'm still using VS2003.
 
No, that helped, thank you. :) I have one more question. I'm not sure about the parameters of this, or if I'm even able to do it. How/Can I raise the Button1_Click event when they select something in a combo box? Thanks.
 
Riasing a button click is not really the way to think of it. You are performing some tasks when the button is clicked. If you wish to perform the same tasks when something else is done, then the code for those tasks would work nicely as a SUB.
VB.NET:
Private Sub YourName1()
[COLOR=SeaGreen] 'Code you want performed here[/COLOR]
End Sub
Under the button click and selected change events you just call that sub.

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        [COLOR=SeaGreen]'Call your sub[/COLOR]
        Me.YourName1
    End Sub
 
Thanks, I figured it out by using a sub like you said. My project is almost ready to be released, but I'm having one small problem. I included two folders in the project with icons in them. One is called "icons" and one is called "32". When I was testing the project (before it was compiled), the path "../../32/iconname.jpg" worked for me. Now when it's compiled, it shows errors, because it can't find that folder. How should I refer to the folder in my code so it works for everyone?
 
Last edited:
The problem, I believe, is that you changed the path the application was run from when you changed it to release mode rather than debug mode; the application would be run from a different path. Usually it is easier to put the data either in a fixed location ("C:\...\something.jpg"), although not the best way, or in a location that always has the same relative path to the application, where it is run from, ("[App path]\something.jpg") In your case, put the finished executable in a separate folder, along with the other items in the same folder, changing the path in the code.

Although, for what you are trying to do, you could use a resource file to store the jpg's, so that the pictures are stored in the executable rather than in different files. However, this method is more complicated and it may be better to just use files.
 
I put the images in the .rsx. Now I'm just having problems referring to them in the program. It's giving me errors. The file names are all numbers, so do I just refer to it as "10.jpg" now that it's embedded? Also, when I embedded them, they got renamed. They all start with _ now and since the icons from both folders have the same names, all the icons from one of the folders got a 1 added to the end. I'd really like to get this app running, but this is frustrating, since I don't know how to refer to the embedded files. Even though they are embedded, there are still the "icons" and "32" folders, so I'm confused.
 
Thanks, I got it figured out and finally have my little project done! :) I really want to thank everyone for their help. Thanks for putting up with all of my questions. I've learned alot from doing this, and you've all helped. Here's a screenshot of my project. It's an XML weather checker. It shows you the current conditions and 4 day forecast for any US zip code.
b26843298.jpg
 
I need help with a few more things. I'm having a few issues with this program. I need to know how to unset a variable, specifically a My.Settings variable that will be remembered the next time you start the program unless you unset it. I'm having glitches, because my program is supposed to allow you to keep three favorite zip codes, and sometimes, it will tell you that all three are used, even if you only have two or less in the combo box. I think this is happening after I try to remove a zip code, and it may not really be getting unset. I also want to know if there is anything I can/should do to close a connection to the internet in my program when I don't need it anymore. I'm not able to delete some program folders, because it says they're in use, and I think that may be why. Thanks for any help.
 
Back
Top