Favorites

tonyr1988
07-18-2003, 07:52 AM
I'm trying to make a browser, and I'm having trouble with the favorites. I have a few questions:

1. How can I access the Menu Editor from my Code?

2. Why isn't this working:

I decided to make the favorites appear in a list as well as the menu. I made an Add Favorite button with the name of cmdAddFav. It's code is simply:

Private Sub cmdAddFav_Click()
frmAddFav.Show
End Sub

frmAddFav has two text boxes [txtURL and txtName] along with a button named cmdAdd. Here's the code:

Private Sub cmdAdd_Click()
SaveSetting "MyBrowser", "Favorites", "Number", ThisNum
SaveSetting "MyBrowser", "Favorites", "URL" & ThisNum, txtURL.Text
SaveSetting "MyBrowser", "Favorites", "Name" & ThisNum, txtName.Text
Me.Hide
End Sub
Private Sub Form_Load()
Dim Favorites As Integer
Dim ThisNum As Integer
Favorites = GetSetting("MyBrowser", "Favorites", "Number", 0)
ThisNum = Favorites + 1
End Sub

What I wanted it to do was write to the registry so that it would look like this:

MyBrowser: Favorites:
Number-3
URL1-http://www.google.com/
Name1-Google
URL2-http://www.yahoo.com/
Name2-Yahoo!
URL3-http://www.msn.com/
Name3-MSN

But when I run it it I get Compile Error: Variable not defined and it highlights ThisNum in SaveSetting "MyBrowser", "Favorites", "Number", ThisNum. Any ideas?

3. Is there an easier way to do this other than the registry?

Thanks for all help in advance. Until next time, take care and God Bless!
-Tony

Squishy
07-18-2003, 07:56 AM
Have you declared ThisNum?

tonyr1988
07-18-2003, 08:00 AM
How do you declare a varible? I had to teach myself VB, so I have a lot of gaps in my knowledge :( I always thought that the Dim xxxxx as xxxx was "declaring" a variable [guess not].

Until next time, take care and God Bless!
-Tony

Squishy
07-18-2003, 08:02 AM
It is...oops...missed the Form_Load event... :-\

EDIT: wait...if its declared in Form_Load it's available only in that event...you need to declare it as a Static variable in the cmdAdd_Click event (Static varName instead of Dim varName)...or declare it using Dim at the beginning of your code if you need to access it from multiple events.

Squishy
07-18-2003, 08:07 AM
Regarding question #3...it might be better to store it in file rather than in the registry. Some users (like me) who have 50+ favorites and like to tinker around in the registry might have a stroke seeing over 100 entries. :)

tonyr1988
07-18-2003, 08:17 AM
EDIT: wait...if its declared in Form_Load it's available only in that event...you need to declare it as a Static variable in the cmdAdd_Click event (Static varName instead of Dim varName)...or declare it using Dim at the beginning of your code if you need to access it from multiple events.

I Dimmed it at the beginning of my code and it works. Thank you a ton - you saved me hours of frustration and staring at code :D

Regarding question #3...it might be better to store it in file rather than in the registry. Some users (like me) who have 50+ favorites and like to tinker around in the registry might have a stroke seeing over 100 entries.

That's something I haven't thought of. I'll have to try that later. Will I be able to use the same general format as I did with the registry?

Until next time, take care and God Bless!
-Tony

Squishy
07-18-2003, 08:24 AM
A few more lines of code, but it's the same basic format...might even make it easier to load the data since VB knows when it's at the end of a file (If you decide to use the registry method, you should consider adding a value that gives you the number of favorites, so that you don't need to determine if Number-x exists). Be sure to include ThisNum = ThisNum + 1 so that every entry will get different numbers.

tonyr1988
07-18-2003, 08:26 AM
I use the variable Number to tell me how many Favorites there are.

Until next time, take care and God Bless!
-Tony

Squishy
07-18-2003, 08:28 AM
Wouldn't your variable reset to 0 every time you start the program?

tonyr1988
07-18-2003, 08:34 AM
Sorry, that's my bad. It's not a variable, it's a registry value. Also, I have another question that just came up. I'm trying to pull from the registry and put them into lstFav via the pressing of cmdUpdateFav. Here's the code:

Private Sub cmdUpdateFav_Click()
Dim Start As Integer
Dim Finish As Integer
Dim Name As Integer
Finish = GetSetting("MyBrowser", "Favorites", "Number", 1)
For Start = 1 To Finish Step 1
Name = GetSetting("MyBrowser", "Favorites", "Name" & Start, 1)
lstFav.AddItem (Name)
Next Start
End Sub

When I run it, it gives me a type mismatch error on the "Name = GetSetting("MyBrowser", "Favorites", "Name" & Start, 1)" line. I'm gonna be gone for the most of today, so this will probably be my last post for a while.

Until next time, take care and God Bless!
-Tony



EDIT: Nevermind, I did a stupid mistake. I dimmed Name as an integer when it should be a string. It works now. Thanks for all of your help.

tonyr1988
07-18-2003, 08:39 AM
I hate to bug you again, but now that I have some websites in my favorites list, how can I make it where the Browser goes to them when double-clicked? I very unfamiliar with List, which doesn't help me much. Thanks again :p

Until next time, take care and God Bless!
-Tony


[This one should be my very last post until later today]

Squishy
07-18-2003, 08:40 AM
No prob...reading a PDF textbook on a flickering monitor is boring...

Squishy
07-18-2003, 08:44 AM
Private Sub List1_DblClick() 'Runs when the user double clicks
FormWhereBrowerIs.WebBrowser1.Navigate TheURLBasedOnList1.Text

End Sub


You could put the URL in brackets after the name and extract it when you need it, or write a function that goes into the registry and reads the URL based on List1.ListIndex

Use Private Sub List1_Click() if you want it to navigate on one click.

tonyr1988
07-18-2003, 04:07 PM
How can I tell what item is currently selected in the List? Is that what the List1.ListIndex is? I think that that's my main problem...

Until next time, take care and God Bless!
-Tony

Banjo
07-18-2003, 04:17 PM
Yes, Listindex tells you which item in the list is selected. It ranges from 0 to ListCount - 1.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum