Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 10th, 2007, 10:25 AM   #1
J-V
Unverified User
 
Join Date: Jan 2007
Location: Estonia
Posts: 4
Rep Power: 0 J-V is on a distinguished road
Function doesnt work!

I have a form and it got 2 buttons on...
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
    {
        public Form1()
        {
            InitializeComponent();
        }


        public void MessageShow()
        {
        MessageBox.Show("Yo!"+Var1,"",MessageButton.OK);
        }

        private void button1_Click(object sender, EventArgs e)
        {
        MessageShow();
        string Var1;
        Var1 = @"Man";
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
        MessageShow();
        string Var1;
        Var1 = @"Dude";
        }
    }
}

If i click button1 then messagebox should popup with message "Yo! Man" but if i click button2 then there should be message "Yo! Dude". My problem is that this code example doesnt work. Maybe someone can direct me to right way.
J-V is offline   Reply With Quote
Old Feb 10th, 2007, 10:56 AM   #2
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 3 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Did you use an IDE to write this code? Your problem is the lack of a MessageBox in C#. VB has it but in C# you have to make your own.
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Feb 10th, 2007, 1:37 PM   #3
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 381
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
[quote]Your problem is the lack of a MessageBox in C#[quote]
NewsFlash

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
    {
        public Form1()
        {
            InitializeComponent();
        }

        string Var1 = "" ;
        public void MessageShow()
        {
        MessageBox.Show("Yo!"+Var1,"",MessageButton.OK);
        }

        private void button1_Click(object sender, EventArgs e)
        {
             Var1 = @"Man";   
             MessageShow();
        }
        
        private void button2_Click(object sender, EventArgs e)
        {        
          Var1 = @"Dude";
          MessageShow();        
        }
    }
}

I haven't tried it but the problem i think was that Var1 was defined in every function and it existed only inside that function. Now I've declared as a global variable. Also you need to set Var1 to Dude before u call MessageShow().
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Feb 10th, 2007, 3:13 PM   #4
J-V
Unverified User
 
Join Date: Jan 2007
Location: Estonia
Posts: 4
Rep Power: 0 J-V is on a distinguished road
Thank you xavier, it works perfect.
J-V is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining languages titaniumdecoy Other Programming Languages 12 Jul 13th, 2006 2:03 PM
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 5:41 PM
BH Hotkeys brownhead Visual Basic 1 Apr 27th, 2006 5:42 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC