New Posts  All Forums:Forum Nav:

C# Small App Help #2

post #1 of 10
Thread Starter 
Hey guys.
Sorry to start a new thread on this, but Im still having problems, a few new ones too.
Basically, if you haven't already read the first thread, look here.
Please read it if you haven't already.

Now anyway, moving on.
Here are my problems:

1:
Code:
        private void button1_Click(object sender, EventArgs e)
        {
            {

                if (!textBox1.Text.StartsWith("http://")) textBox1.Text = "" + textBox1.Text;
                if (textBox1.Text.StartsWith("www.")) textBox1.Text = "http://" + textBox1.Text;
                if (textBox1.Text.StartsWith(" ")) textBox1.Text = "http://" + textBox1.Text;
                if (textBox1.Text.StartsWith("")) textBox1.Text = "http://" + textBox1.Text;
                if (textBox1.Text.StartsWith("http://www.")) textBox1.Text = "" + textBox1.Text;
               }
       }
How do I make it, so if http:// is already in the Address bar, it wont automatically type http://www. or http:// to the start of text?
If you don't understand, you can download the web browser project yourself and test it for me,
PROJECT FILES
DEMO PROGRAM

2: And Secondly, how do I add two events for one object,
EG:
Code:
        private void txtAddress_KeyPress(object sender, KeyPressEventArgs a, EventArgs e)
        {
            if (a.KeyChar == Strings.Chr(13)) button1.PerformClick();
        }
Thanks,
Anyone who can help gets a nice +REP or two,
Ben
post #2 of 10
To add two events to an object.

Code:
if (i = 2 | i = 3)
{
execute;
}
| Is the symbol for or in C#, C, C++, and more.
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #3 of 10
Thread Starter 
Now to question #1?
post #4 of 10
Its your IF statements.
Because you don't don't break out of them, it runs the next statement.

you enter htttp://www.live.com
So it does.

Code:
if (textBox1.Text.StartsWith("http://")) textBox1.Text = "" + textBox1.Text;
So textbox1 becomes htttp://www.live.com

Then it keeps running down the statements.
Core Power!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9450 @ 3.2Ghz Maximus Extreme Gainward 'Golden Sample' 4850 740/1100 2x 2Gb || PC3-10666 OCZ Gold 
Hard DriveOSMonitorPower
80Gb Seagate Windows 7 19" Ace Widescreen Seasonic 500W 
CaseMouse
Armor LCS Habu 
  hide details  
Reply
Core Power!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9450 @ 3.2Ghz Maximus Extreme Gainward 'Golden Sample' 4850 740/1100 2x 2Gb || PC3-10666 OCZ Gold 
Hard DriveOSMonitorPower
80Gb Seagate Windows 7 19" Ace Widescreen Seasonic 500W 
CaseMouse
Armor LCS Habu 
  hide details  
Reply
post #5 of 10
Right.. You've got multiple IF statments.

Each one evaluates.

If you want something -or- something else do an If ElseIf EndIf

Again, in VB code (giggle)

Code:
If Arg1 = 1 Then
     Do Something If Arg1 = 1
ElseIf Arg1 = 2 Then
     Do Something If Arg1 = 2
EndIf
Now if you want to check for multiple within the same big if you can nest IF ElseIf EndIf statements but too many is a big tax on the code, IMHO, but can be done as such.

Code:
If Arg1 = 1 Then
  If Arg2 = 1 Then
    Do Something If Arg1 AND Arg2 = 1
  ElseIf
    Do Something If Arg1 = 1 and Arg2 = Something Other Than 1
  EndIf
ElseIf Arg1 = 2 Then
     Do Something If Arg1 = 2 Directly w/ No Secondary Check
EndIf
In VB.Net, I'm sure C# has a counter, you can do the AndAlso qualifier. You can use this to concatenate and trim the code down. You can even, since it's just an IF statement with multiple evaluators, do an ElseIf as the secondary...

Code:
If Arg1 = 1 AndAlso Arg2 = 1 Then
  Do Something If Arg1 AND Arg2 = 1
ElseIf Arg1 = 2 Then
  Do Something If Arg1 = 2 Directly w/ No Secondary Check
ElseIf Arg1 = 2 AndAlso Arg2 = 3 Then
  Do Something If Arg1 = 2 and Arg2 = 3 (completely new branch)
EndIf

Edited by Ictinike - 12/18/08 at 5:53pm
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #6 of 10
Thread Starter 
Quote:
Originally Posted by Ictinike View Post
Right.. You've got multiple IF statments.

Each one evaluates.

If you want something -or- something else do an If ElseIf EndIf

Again, in VB code (giggle)

Code:
If arg1 = 1 Then
     Do Something If Arg1 = 1
ElseIf arg1 = 2 Then
     Do Something If Arg1 = 2
EndIf
Now if you want to check for multiple within the same big if you can nest IF ElseIf EndIf statements but too many is a big tax on the code, IMHO, but can be done as such.

Code:
If Arg1 = 1 Then
  If Arg2 = 1 Then
    Do Something If Arg1 AND Arg2 = 1
  ElseIf
    Do Something If Arg1 = 1 and Arg2 = Something Other Than 1
  EndIf
ElseIf Arg1 = 2 Then
     Do Something If Arg1 = 2 Directly w/ No Secondary Check
EndIf
Cheers mate nother +REP.
Now, I found out how to use vB in C#, just add Microsoft.VisualBasic reference.
post #7 of 10
Quote:
Originally Posted by sktfreak View Post
Cheers mate nother +REP.
Now, I found out how to use vB in C#, just add Microsoft.VisualBasic reference.
\\

Nice!

Yea I know the .Net Platforms are all interchangable as I do work primarly in VB.Net but sometimes do Services and Remoting in C#.

Both are great and I've done everything from VBS through VB4/5/6 to now .Net 2008 going 16 years.. Love my work, just not the specific job at times and the client(s) I work for

I'm glad you picked it up and I edited my last post to include something in .Net called the AndAlso meaning to evaluate 2 expressions on the same IF statement.

Check it out and let me know.. Sorry I got totally busy today with manager meetings and some outages that I could'nt get into code today (such is trying to become more of a manager than coder) and I didn't get to make that sample project for ya

Cheers.. Keep at it!
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #8 of 10
C# is easier in my opinion.
Code:
if (textBox1.Text.StartsWith("http://"))
        {
            textBox1.Text = "" + textBox1.Text;
        }
        else if (textBox1.Text.StartsWith("www."))
        {
            textBox1.Text = "http://" + textBox1.Text;
        }
        else if (textBox1.Text.StartsWith(" "))
        {
            textBox1.Text = "http://" + textBox1.Text;
        }
        else
       {
           textBox1.Text = "" + textBox1.Text;
        }
Thats the general idea anyway.

You should have a look at the debuging. Its very handy in C# as you just put your mouse over your objects in your code to find there values.
Core Power!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9450 @ 3.2Ghz Maximus Extreme Gainward 'Golden Sample' 4850 740/1100 2x 2Gb || PC3-10666 OCZ Gold 
Hard DriveOSMonitorPower
80Gb Seagate Windows 7 19" Ace Widescreen Seasonic 500W 
CaseMouse
Armor LCS Habu 
  hide details  
Reply
Core Power!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9450 @ 3.2Ghz Maximus Extreme Gainward 'Golden Sample' 4850 740/1100 2x 2Gb || PC3-10666 OCZ Gold 
Hard DriveOSMonitorPower
80Gb Seagate Windows 7 19" Ace Widescreen Seasonic 500W 
CaseMouse
Armor LCS Habu 
  hide details  
Reply
post #9 of 10
Quote:
Originally Posted by Mebby View Post
C# is easier in my opinion.
It's all what you know. I have a guy that swears by C# but in .NET it's all bytecode anyway.. It's what and how you want to code.

Not doing C# all the time I spend more trying to recall how and not doing it while in VB I can quickly write up an app/service whatever in no time.

Cheers to you tho as a fine example of what we both meant on the multiple IF statments!
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #10 of 10
I don't really know any language to be honest, I've been taught the basics in VB,C,C++,C#,Java,Perl,Delphi and some assembly code. If I had to do something though, C# would most likely be my prefered choice.
Core Power!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9450 @ 3.2Ghz Maximus Extreme Gainward 'Golden Sample' 4850 740/1100 2x 2Gb || PC3-10666 OCZ Gold 
Hard DriveOSMonitorPower
80Gb Seagate Windows 7 19" Ace Widescreen Seasonic 500W 
CaseMouse
Armor LCS Habu 
  hide details  
Reply
Core Power!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9450 @ 3.2Ghz Maximus Extreme Gainward 'Golden Sample' 4850 740/1100 2x 2Gb || PC3-10666 OCZ Gold 
Hard DriveOSMonitorPower
80Gb Seagate Windows 7 19" Ace Widescreen Seasonic 500W 
CaseMouse
Armor LCS Habu 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming