GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Jun-2007, 22:47
not a banana not a banana is offline
New Member
 
Join Date: May 2007
Posts: 9
not a banana is an unknown quantity at this point

Navigating


This is for C# actually, but it is basically the same...

C-SHARP / C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        private string Website;
        public string website
        {
            get
            {
                return Website;
            }
            set
            {
                Website = value;
            }
        }
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.GoHome();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            webBrowser1.Stop();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            webBrowser1.Refresh();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.StartsWith("http://")) 
            {
                website = textBox1.Text;
                website = ("http://" + website);
                webBrowser1.Navigate(new Uri(website.ToString()));
            }
            else
            {
                website = textBox1.Text;
                webBrowser1.Navigate(new Uri(website.ToString()));
            } 
           }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }
}

webBrowser1.Navigate(new Uri(website.ToString()));
On this line, when I click button 6 I get the error "Invalid URI: The format of the URI could not be determined."
Any help?
Last edited by LuciWiz : 08-Jun-2007 at 06:23. Reason: Please insert your C# code between [c#] & [/c#] tags
  #2  
Old 14-Jan-2009, 12:33
FeareD FeareD is offline
New Member
 
Join Date: Jan 2009
Posts: 4
FeareD is on a distinguished road

Re: Navigating


I know this is old but I recently had the same problem and all you have to do it change the string
C-SHARP / C# Code:
if (textBox1.Text.StartsWith("http://"))
to
C-SHARP / C# Code:
if (textBox1.Text.StartsWith(""))
Basically take out the http:// and it works, the only problem now is if you press the button more than once it adds to many "http://" which isn't a big of a problem but it works and you dont even have to type "http://" when you type out the URL!
The problem I believe was that the program was looking for the string "http://" but when its looking for a blank spot it easily can insert it, I noticed it when I added "http://" to the URL and it added "http://" infront of the URL over and over.

  #3  
Old 14-Jan-2009, 19:22
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,309
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Navigating


Quote:
Originally Posted by FeareD
...
The problem I believe was that the program was looking for ...

Huh???

Isn't the logic in the original post exactly backwards? See footnote.

If it starts with the http stuff, just use it, otherwise prepend the http stuff.

Maybe something like
CPP / C++ / C Code:
    if (textBox1.Text.StartsWith("http://"))
    {
        website = textBox1.Text;
        webBrowser1.Navigate(new Uri(website.ToString()));
    }
    else
    {
        website = textBox1.Text;
        website = ("http://" + website);
        webBrowser1.Navigate(new Uri(website.ToString()));
    }

Or, with a little more elegance, to my eye, and with an intent that is at least as clear (to me, that is):

CPP / C++ / C Code:
    website = textBox1.Text;
    if (!textBox1.Text.StartsWith("http://"))
    {
        website = ("http://" + website);
    }
    webBrowser1.Navigate(new Uri(website.ToString()));


Regards,

Dave

Footnote: Since I don't do .net, I can't test it, but assuming the original syntax was correct, isn't this what you had in mind?
  #4  
Old 15-Jan-2009, 13:16
FeareD FeareD is offline
New Member
 
Join Date: Jan 2009
Posts: 4
FeareD is on a distinguished road

Re: Navigating


Hmm not really, that produces errors, and we are talking about C# if you read, but anyways no the code your "provided" does not work and produces even more errors.
And no its not what I had in mind.
  #5  
Old 15-Jan-2009, 13:58
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,031
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Navigating


Quote:
Originally Posted by FeareD
Hmm not really, that produces errors, and we are talking about C# if you read, but anyways no the code your "provided" does not work and produces even more errors.
And no its not what I had in mind.

Quote:
I know this is old but I recently had the same problem and all you have to do it change the string

C-SHARP / C# Code:
if (textBox1.Text.StartsWith("http://"))

to

C-SHARP / C# Code:
if (textBox1.Text.StartsWith(""))


.StartsWith("") will return true for any String, even the empty String. Your else condition will never be reached, and you always hit the if branch.

Dave offered a good solution for a sane input. If the problem you are trying so solve is different, perhaps you can describe it, but providing a sample input and the expected output. Your current solution is logically flawed.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #6  
Old 15-Jan-2009, 15:05
FeareD FeareD is offline
New Member
 
Join Date: Jan 2009
Posts: 4
FeareD is on a distinguished road

Re: Navigating


I did say it does cause other problems there I pretty much did say it was flawed in a sense, and I know it is flawed but it makes the program run and it half works okay and that's what matters here at the moment okay?
Please read whole posts and whole threads before posting comments.

P.S Dave did input something but that something is also flawed and doesn't even get the program to run.
  #7  
Old 15-Jan-2009, 15:14
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,031
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Navigating


Quote:
Originally Posted by FeareD
I did say it does cause other problems there I pretty much did say it was flawed in a sense, and I know it is flawed but it makes the program run and it half works okay and that's what matters here at the moment okay?

If you say so.
My point is that

C-SHARP / C# Code:
            if (textBox1.Text.StartsWith("")) 
            {
                website = textBox1.Text;
                website = ("http://" + website);
                webBrowser1.Navigate(new Uri(website.ToString()));
            }
            else
            {
                website = textBox1.Text;
                webBrowser1.Navigate(new Uri(website.ToString()));
            } 

is equivalent to

C-SHARP / C# Code:
website = textBox1.Text;
website = ("http://" + website);
webBrowser1.Navigate(new Uri(website.ToString()));

So there is no need for an "if" branch at all. The code simply performs those 3 lines of code.

Quote:
Originally Posted by FeareD
Please read whole posts and whole threads before posting comments.

I always do.

Quote:
Originally Posted by FeareD
P.S Dave did input something but that something is also flawed and doesn't even get the program to run.

Your program, perhaps. We didn't see it, you only made a suggestion to change a line of code.

I can't believe I am spending my 1000th post arguing semantics. Have it your way - if you are happy with it, good for you.
But I am not going to let this thread end with your mistaken suggestion.
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #8  
Old 15-Jan-2009, 15:21
FeareD FeareD is offline
New Member
 
Join Date: Jan 2009
Posts: 4
FeareD is on a distinguished road

Re: Navigating


....Wow so you think everybody has to be perfect?
Okay fix it yourself mister "But I am not going to let this thread end with your mistaken suggestion."

Oh by the way about you saying you always read all the posts that's utter bullcrap because you would have read that I said
"the only problem now is if you press the button more than once it adds to many "http://" which isn't a big of a problem but it works"

Go wank you bloody Romanian and correct I made a suggestion unlike you, you made no suggestion except for trying to correct me when there is nothing to correct I said it was flawed okay damnit.
  #9  
Old 15-Jan-2009, 15:33
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,031
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Navigating


Quote:
Originally Posted by FeareD
....Wow so you think everybody has to be perfect?
Okay fix it yourself mister "But I am not going to let this thread end with your mistaken suggestion."

Oh by the way about you saying you always read all the posts that's utter bullcrap because you would have read that I said
"the only problem now is if you press the button more than once it adds to many "http://" which isn't a big of a problem but it works"

Go wank you bloody Romanian and correct I made a suggestion unlike you, you made no suggestion except for trying to correct me when there is nothing to correct I said it was flawed okay damnit.

I believe we have a communication problem - me trying to help and you taking the defensive stance.

The fact that the code is flawed is not an offense, as you seem to believe. Your last post however, is.
Please refrain from this language in the future.

Do you understand that using "StartsWith" with an empty string as a parameter makes no sense? Do you disagree with my assessment that removing the "if" statement and the else branch results in the same behavior? If yes, is there a point to them being in the code?

Quote:
Originally Posted by FeareD
"the only problem now is if you press the button more than once it adds to many "http://" which isn't a big of a problem but it works"

I did read that. And I told you why it happens.
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
Last edited by LuciWiz : 15-Jan-2009 at 16:58.
  #10  
Old 15-Jan-2009, 16:12
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,031
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Navigating


I created a program with a WebBrowser object named "webBrowser1", a button called "button6" which will perform the code posted by Dave for OnClick and a TextBox "textBox1" where I input the name of the site.

So the code I used was exactly:

C-SHARP / C# Code:
        private void button6_Click(object sender, EventArgs e)
        {
            website = textBox1.Text;
            if (!textBox1.Text.StartsWith("http://"))
            {
                website = ("http://" + website);
            }
            webBrowser1.Navigate(new Uri(website.ToString()));

        }

When introducing in the text box "www.gidforums.com" and pressing the button, the code added "http://" to the name of the site (making it "http://www.gidforums.com") and the page loaded (after I confirmed to my Firewall it's OK ).

Introducing in the text box "http://www.gidforums.com" from the start resulted in the string remaining unchanged and the page loading again.

Like I said, Dave's code is perfectly valid for what I consider sane input - a well formed site name. Obviously the function can be tricked by entering gibberish in the text box, but the code does its intended business.

Quote:
Originally Posted by davekw7x
Isn't the logic in the original post exactly backwards?

Negating the condition in the "if" was indeed all that was needed, as stated.

Quote:
Originally Posted by FeareD
you made no suggestion except for trying to correct me

There were no more suggestions to be made. Dave already solved the OP's problem.

Regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:59.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.