VB programer having a C# newby question...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

In Visual Basic there are modules where I can store public variables, Constants, etc.
I have in a C# program a class that have a method to open a form.

public void GUIGestaoAcessos(string sDBUser, string sDBPassw, string sDBDsn)
{
Form oform=new FrmSeguranca();
oform.Show(); //He will connect to DB using the method parameters...
}

How can I pass the method parameters (string sDBUser, string sDBPassw, string sDBDsn) into the form so that He can use them...

Thanks for your help,
Bernardo
 
Use the constructor of the Form. You can (just like any other 'function')
overload it.

So you should get something like :

FrmSeguranca oform = new FrmSeguranca(sDBUsern DBPassw, sDBDsn); // notice
i'm not using Form here
oform.Show();

And then in your class FrmSeguranca you have the following

class FrmSeguranca {
// some things like private variables, other constructors, ...

// The constructor you wish to use
public FrmSeguranca(string username, string password, string dsn)
{
// and here you do your connection
}
}

HTH

Yves

Bernardo said:
Hi,

In Visual Basic there are modules where I can store public variables, Constants, etc.
I have in a C# program a class that have a method to open a form.

public void GUIGestaoAcessos(string sDBUser, string sDBPassw, string sDBDsn)
{
Form oform=new FrmSeguranca();
oform.Show(); //He will connect to DB using the method parameters...
}

How can I pass the method parameters (string sDBUser, string sDBPassw,
string sDBDsn) into the form so that He can use them...
 
Hi Bernardo

There are some ways to do that

You can pass that parameters to FrmSeguranca class constructor

public void FrmSeguranca(string sDBUser, string sDBPassw, stringsDBDsn

..... now you can use the sDBUser and rest of the fields her


and then you can initialize your form in that way

public void GUIGestaoAcessos(string sDBUser, string sDBPassw, string sDBDsn

Form oform=new FrmSeguranca(sDBUser, sDBPassw, sDBDsn)
oform.Show(); //He will connect to DB using the method parameters..


or you can declare properties in FrmSeguranca class

class FrmSeguranca(

private string sDBUser
public string sDBUse

get

return sDBUser

se

sDBUser = value



... rest of FrmSeguranca class cod


Now you can use that properties

public void GUIGestaoAcessos(string sDBUser, string sDBPassw, string sDBDsn

Form oform=new FrmSeguranca()
oform.sDBUser = sDBUser
oform.Show(); //He will connect to DB using the method parameters..


Hope this helps

Cheers
Chri
 
Back
Top