|
Im creating a web browser for a friend, and one of his requests is that I should have favourites/bookmarks built in. Im trying to do this by reading and writing to a text file. Can anyone fix my mistakes? This doesnt work at all.
'To load the favourites on startup:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each item As String In "C:/Program Files/Testfile.txt"
ComboBox1.Items.Add(item)
Next
End Sub
'To add the content of a textbox to your favourites
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
texty.Text = WebBrowser1.Url.ToString()
'If My.Settings.Favourites.Contains(texty.Text) Then
' MessageBox.Show("It has been in your favourites!")
'Else
'
ComboBox1.Items.Add(texty.Text)
Dim objStreamWriter As StreamWriter
'Pass the file path and the file name to the StreamWriter constructor.
objStreamWriter = New StreamWriter("C:\Program Files\Testfile.txt")
'Write a line of text.
objStreamWriter.WriteLine(texty.Text)
'Close the file.
objStreamWriter.Close()
'End If
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
WebBrowser1.Navigate(ComboBox1.Text)
End Sub
|
|
|
|
|
britishcolumbia wrote: For Each item As String In "C:/Program Files/Testfile.txt"
You really need to pickup a beginners book on VB.NET and work through it. Just specifying a string in a For Each doesn't automatically assume that string is a file path and open it for reading.
britishcolumbia wrote: Im creating a web browser for a friend
So, why doesn't your friend get a hold of IE8 or FireFox and have a working web browser now, instead of waiting for a couple of months for you to figure out how to write one?? After all, your obviously just wrapping the built-in WebBrowser component, which is just IE anyway.
Seriously, your code is so bad that I don't consider it fixable. I'd scrap it and rewrite it from scratch, using XML to store the Favorites instead of a straight text file.
|
|
|
|
|
Please keep your comments to your self if you don't plan to help anyone.
Everyone starts somwhere, I start here.
If you’re the Microsoft MVP, you most likley know how to fix this. If you would like, without criticizing me, please help me out. If not, good day to you.
|
|
|
|
|
Do you really expect people to spend time and help you with your attitude?
Be smart and recognize good advice when it is offered.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Allright, well I'm going to close this post, Im just used to other forums where that would have been considered "Bad help" but I'm new here, so I suppose things work a little differently.
I guess I took the previous post the wrong way, I thought that saying that the code was so bad that I should just re-write it, and then saying that the whole project was nutty, or worthless as I took it. I don't really see that too much outside of YouTube commenting, and thought it was a bit rude.
I was just looking for a bit of advice. That’s for whatever you gave me, even if I didn’t see it.
|
|
|
|
|
I'd agree with you actually, he was a bit rude. But he is also right! You do need to learn the basic concepts, and while you're welcome to make your own IE-based web browser (the web browser component is full of IE code as far as I understand) it probably isn't the best way to learn.
If you really want advice, as opposed to code that loads/saves bookmarks, then none can be better than getting a good introductory programming book. There's no shame in being a beginner, but it's smart to realize that you are one and work from that assumption.
Personally I'd advice you to go with C# instead of VB.NET though. Let me be clear about this right away: C# and VB.NET will both allow you to do the same, and you'll achieve the same performance (or lack thereof, depending on your code) no matter which one you use. However, a lot of VB.NET coders have come to the .net platform from lesser programming tools (in my opinion) such as VB6, Access, and probably a few people who have just written a few macros in Excel (VBA), while a lot of C/C++/java coders have picked up C#. This might upset some people, but in my opinion there is little doubt that the C# community is of higher average quality than the VB.NET one. There are awful and great programmers in both camps of course, but if I were you I'd choose to associate with the C# lot.
VB.NET on the other hand might be preferable in some ways. It has optional parameters, which is in fact useful if you do Microsoft Office programming (lots of methods with 30 parameters - it's the one thing I will use VB.NET for if free to choose). And the Visual Studio tools are sometimes more refined for VB, presumably because MS feels it's necessary to nanny VB.NET users a bit more. For example, the code snippets that ship with VS include lots of VB stuff and little C# stuff.
My two cents.
|
|
|
|
|
britishcolumbia wrote: you most likley know how to fix this
Yes, and I already told you how. I would scrap the whole thing and start over with an XML storage format.
Seriously, even the basics of VB.NET is beyond you right now. How successful do you think your going to be if you don't understand the simple concepts of loops and enumerations?? Get a book on VB.NET and start teaching yourself the basics. I'm not trying to insult you, but just trying to prevent frustration and a lot of wasted time posting question on forums and waiting hours/days for answers to questions that you wouldn't even have to ask in the first place if you understood the basics of how VB.NET works and how it relates to the .NET Framework.
britishcolumbia wrote: If you would like, without criticizing me, please help me out.
Excuse me if I questiond the whole point of writing your "own" web browser for your friend. The whole concept of him/her waiting for you to write a browser is a bit nutty.
|
|
|
|
|
Hello Friends..
I want to call Shell from my vb.net windows application and run the command.
I have tried like
"Process.Start("cmd.exe", "cd\")"
But it just open command prompt.Does not run the command which passed by argument. That is "Cd\".
How can i do that...????
Thanks in advance.
|
|
|
|
|
|
Create a bacth file of ur command and execute it.
|
|
|
|
|
I cannot run any dotnet executable if the path including the name of the exe exceeds 128 characters.
The executable does appear for a split second and disappears immediately.
There is nothing in the event log.
I'm running Windows XP SP3, and .NET framework 2 SP1.
Any help is appreciated.
Thank you,
Michel
|
|
|
|
|
msmits wrote: The executable does appear for a split second and disappears immediately.
In that case, you've got some debugging to do. Since the code runs and shows a window, albeit briefly, it means your code IS running. So, the problem would have to be in your code somewhere. Is your code using files somewhere?? Is it handling the path names with spaces properly??
|
|
|
|
|
Hi Dave,
This problem happens with ANY exe, mine or anyone else's.
I've also created a new windows forms application (without code) and it behaves the same.
I've also debugged an application, it steps through the code and exits after the last debuggable statement (i.e. when it enters the event handling phase).
I've done this on VS2005 and VS2008.
Just to make it stranger, if I start the application rapidly many times in a row, *some* instances actually stay alive.
Cheers,
Michel
|
|
|
|
|
Sorry I made a small mistake in last post, with "any exe" I mean "any .NET exe".
Cheers,
Michel
|
|
|
|
|
msmits wrote: his problem happens with ANY exe, mine or anyone else's.
Well, you didn't say that in your original post, so how were we supposed to know??
msmits wrote: Just to make it stranger, if I start the application rapidly many times in a row, *some* instances actually stay alive.
In that case, make sure your machine hasn't had a virus introduced, then uninstall and reinstall the .NET Frameworks.
Oops. I just saw your last post. Glad you got it fixed!
|
|
|
|
|
When the application exits in Visual Studio in the debug window I see the message:
The program '[4756] MyTestApp.vshost.exe: Managed' has exited with code
-1073741819 (0xc0000005).
After searching for the error code on search.microsoft.com I found there are quite some people with the same problem. There was one solution listed and it works for me.
The problem is caused by the Kensington Mouseworks software that I have installed. It is very strange indeed but after uninstalling it the problem disappeared.
Cheers,
Michel
|
|
|
|
|
Hi all,
I have a requirement like.. i want develop a tool which will create and add a class library project to a given solution. and also i am able to add a class file to the project with a given name.
Please suggest me how can i do this..
Thanks in Advance.
|
|
|
|
|
First I'd try it manually with Notepad. Once you see the structure of the solution you should be able to write something that uses a System.Xml.XmlDocument to do it.
|
|
|
|
|
Hi Guys,
I've got an app composed of a moderately complicated control hierachy. I have a situation where on selecting a different node in a tree view, i'd like to focus on a seperate control and have that focus bubble up to the primary text box so that it can be edited straight away, however the OnGotFocus method in my custom control never gets called after control.Focus(), so can't be bubbled up the object tree.
Any ideas how to get around this?
Regards
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Tristan Rhodes wrote: I have a situation where on selecting a different node in a tree view, i'd like to focus on a seperate control and have that focus bubble up to the primary text box so that it can be edited straight away
What is the purpose of the middle control getting involved? Sounds like you are over complicating things.
Tristan Rhodes wrote: I've got an app composed of a moderately complicated control hierachy
I would look into simplifying it. One example would be the Mediator pattern[^]
If you are not familiar with patterns or even this one in particular, don't get bogged down in the details. Look at the description of the pattern, the problem it solves and the basic idea of how. Even if you roll your own and it doesn't match the pattern exactly, it will still be far superior to the tightly coupled approach you seem to be currently engaged in.
|
|
|
|
|
I've got a Treeview for item selection / association and another control for editing / validating the selected item. These form a composite control responsible for managing the Items collection. There are a number of similar style controls (View / Editor combo) with responsibilities for different parts of the application data beside items. These all sit on an observable model which can be modified and kept in sync with the various views and handle the Undo/Redo commands.
I'm trying to get the manager control to handle the Selected event in the tree view / list and pass the focus to the editor control, which in turn would focus on it's main field so the user can edit and tab through the various controls without having to click on it first.
I'm hoping to make this the default behavior for each view, but for some reason the Focus event gets eaten by the Custom control.
EDIT: Ok - so it IS shifting focus, but it's not raising an event or the OnFocus method, and i have no control over what it selects. I thought it was tab index, but it doesn't do anything that i can see.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
modified on Tuesday, April 7, 2009 8:05 AM
|
|
|
|
|
Ok, now I recognize that I can't understand the design as you are stating it.
Tristan Rhodes wrote: There are a number of similar style controls (View / Editor combo)
Tristan Rhodes wrote: These form a composite control
Tristan Rhodes wrote: I'm trying to get the manager control to handle the Selected event in the tree view / list and pass the focus to the editor control
So if this "editor control" is one of your custom controls you should say that rather than editor control which is interpreted as edit control, hence much confusion.
Anyway if I now understand correctly, don't use the focus event. If this is your custom control, in fact they all are I guess, you should have a design that is yours. It could be events or messages it doesn't matter but it should be yours. Don't try to use the framework events as your custom events, that is probably not a great idea even when it works.
This is not a topic I remember Kent Beck covering in Implementation Patterns, but I imagine he would say something like "prefer explicit design to implicit" as it is easier to understand.
|
|
|
|
|
Hi Mike,
I'm not trying to use any custom events, i just want to be able to handle a change of focus on my control so i can implement some specific behavioral logic. It's not (or shouldn't be) a complicated task. I'm happy with the application design as is, and I don't really want to have to implement my own system for something that already exists that just needs a bit of custom tailoring.
To sum up the process:
* User selects MenuItem in treeview
* TreeView raises selected item change
* Selected MenuItem is loaded into MenuItemEditor
* Focus is passed to MenuItemEditor
* MenuItemEditor passes focus to TextBox. //OnFocus / Focus event not hit
* User edits TextBox Text.
Regards
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Are you handling an event or overriding OnFocus? If you are overriding the method, do you still call base.OnFocus()?
|
|
|
|
|
I override the OnFocus method as the event wasn't getting raised. The OnFocus method never gets hit either for some reason.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|