|
Thx people!
Your replies were very usefull!
Thx,
Nuno
|
|
|
|
|
Sorry for my bad English!
I don't know how to communicate between forms and classes.
At start i have a form form1. From here i create an instance of a class for networking und communication with a server. After couple of hours i found out how i can change elements of form1 from the network class (with referencing). But, what is when i go back to form1 and create with a button a new class of (for example) database. How can I communicate with previously created network class AND change propertys in form1?
In Visual Basic it is very easy, but c++ and c#...
Thank you very much!
waldi
|
|
|
|
|
I did not understand the question
If you believe that it's easier in vb, Please post the vb code that makes the same functionality (or a similar one) and let us convert it to C#.
|
|
|
|
|
ok.
Here is a basic sample in VB .NET
http://www.waldemarhuber.de/vbtest.zip
<VB>
there are two forms and a class.
Form1 initializes Form2 -> Form2.Show()
Form2 declares an instance of a class
-> Dim obj As New Class1()
Here is the code of Class1:
Public Class Class1<br />
<br />
Sub New()<br />
MessageBox.Show("hm")<br />
Form1.Text = "test"<br />
End Sub<br />
<br />
End Class
As you can see, I change the caption of Form1 to "test" without problems.
In C# I can't do any changes from the class on Form1 neither Form2, and when i initializes the class from Form1 I also can't do something with Form1. With referencing in the class like this
<c#>
class network<br />
{<br />
private Form1 form_ref = null;<br />
<br />
public network(Form1 f)<br />
{<br />
this.form_ref = f;<br />
form_ref.Text = "hm";<br />
}<br />
...
it does good job. But if I make an instance of a some new class of (for example) database out of class network, I can't change things on Form1 like filling textboxes and so on.
I hope you understand now.
Thank you!
waldi
|
|
|
|
|
You've got serious design issues. This thing is very quickly degenerating into a pile of spaghetti. The VB.NET code is just about directly convertible to C#. But, just because you could do it in VB.NET, doesn't make it a good thing to do.
For example, you're totally violating the concept of encapsulation. The name of your class is "Network". Why is this class concerned with ANYTHING to do with the UI?? It shouldn't be doing anything with the user interface at all.
The Network class' sole concern should be whatever you're doing with the network. Should it need to pass changes or data back to the form that is calling it, it can do this using properties, callbacks, and/or events. This way, you can have ANY form use your Network class without any worries about having certain TextBox controls on your form.
What if you try to use you new Network class in a Windows Service or in a Console app, neither of which have a form?? Well, you'll have to rewrite this class to support these things...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Does C# have any advanced string parsing functions other than the ones in the System.Text namespace?
|
|
|
|
|
|
System.Text.RegularExpressions
Regular Expressions are about as good as you can get for string parsing...
Hogan
|
|
|
|
|
How much more advanced do you want to get than the System.Text.RegularExpressions namespace?
|
|
|
|
|
A person literally reading the string?
|
|
|
|
|
|
Your Intellisense string. itself has some good ones.
|
|
|
|
|
Have just developed a windows applicatiion with a SQL 2000 Server as a backend. I however want to display a report on a web browser offline from the SQL 2000 Server.
Can anyone help on this procedure?
|
|
|
|
|
Can you explain a bit more clearly what you are trying to accomplish. Are you trying to display a report generated from data from the SQL Server but you want to be able to view this when the server is not online?
|
|
|
|
|
Hello
I've a question about FormatConditions (Interop.Excel)
I need sent to parameter a string empty value, however in execution mode, the app throw a exception "Additional information: The parameter is incorrect."
See the code below:
rng.FormatConditions.Add(XlFormatConditionType.xlCellValue,XlFormatConditionOperator.xlEqual,"",Type.Missing);
How can I sent a empty string param?
Thks all
|
|
|
|
|
What are you trying to accomplish, a conditional format which checks for an empty string or to delete an existing conditional format. If the former have you tried:
rng.FormatConditions.Add(XlFormatConditionType.xlCellValue, XlFormatConditionOperator.xlEqual, "\"\"", Type.Missing);
Which is an escaped "" sequence, i.e. you're passing "" to the function not an empty string (0 characters in length).
|
|
|
|
|
Hi,
I am having a problem of storing a string into TVReturn.amortization.data[0].balanceAmount (class definitions are given below), where I get the error message saying: System.NullReferenceException: Object reference not set to an instance of an object
at this line where I am testing inserting values into the amortization schedule data
tvret.amortization.data[0].balanceAmount = Convert.ToDecimal("100000");
I have the following class definitions:
public class TVReturn
{
public decimal unknownEventAmount;
public double unknownNominalAnnualRate;
public int unknownEventNumber;
public string cashFlowDataXml;
public TVAmortizationSchedule amortization;
}
public class TVAmortizationSchedule
{
public TVAmortizationData[] data;
}
public class TVAmortizationData
{
public int sequenceNumber;
public string eventDate;
public decimal paymentAmount;
public decimal interestAmount;
public decimal principalAmount;
public decimal balanceAmount;
}
|
|
|
|
|
Abbas82 wrote: TVAmortizationData[] data;
This creates an array. Every object in that array is null, until you call new on it. This is why you're getting this error.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: This creates an array. Every object in that array is null, until you call new on it. This is why you're getting this error.
How would I call the new on it? I instantiate the TVReturn object like so
TVReturn tvret = new TVReturn();
what would be my next step?
|
|
|
|
|
You must initialize data like so:
data = new TVAmortizationData [10 ];
you'll probably want to do this in the constructor of the class TVAmortizationSchedule
|
|
|
|
|
jimmanuel wrote: You must initialize data like so:
data = new TVAmortizationData [10 /* 10 is arbitrary, make the array whatever size you want */];
I changed the class to the following, but I still get the same message.
public class TVAmortizationSchedule
{
public TVAmortizationData[] data;
public TVAmortizationSchedule()
{
data = new TVAmortizationData[5];
}
}
|
|
|
|
|
TVAmortizationData[] data = new TVAmortizationData[10];
data[0] = new TVAmortizationData();
...
|
|
|
|
|
I've developed a webservice serving a data set. This is the code:
-----------------------------------------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
[WebService(Namespace = "http://localhost/WSTest/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ERPService : System.Web.Services.WebService
{
public ERPService () {
}
[WebMethod]
public DataSet listaEntidades() {
SqlConnection con = new SqlConnection("[hidden for security reasons]");
SqlDataAdapter daEntidade = new SqlDataAdapter("SELECT * FROM Entidade", con);
DataSet ds = new DataSet();
con.Open();
daEntidade.Fill(ds, "Entidade");
con.Close();
return ds;
}
}
-----------------------------------------------------------------
It works fine in the browser but when I create a new window project and try to add this service as a data source to bind it to a DataGridView, the interface does not add the DataSource to the window.
It reconizes the service ok the reference is added to the project but no data source is displayed.
What's wrong?
André Pires
|
|
|
|
|
Hi all.
Is there a way of Closing or releasing a CryptoStream without closing the underlying stream?
I've created a helper class that encrypts and decrypts streams. The problem is that if I call Clear() or Dispose() on my CryptoStream in order to release the resources its using I'm also closing the underlying Encrypted Stream I'm passing out of my Method.
I could always copy the encrypted stream to a new one (MemoryStream copyStream = new MemoryStream(encryptedStream.ToArray()) and then close the CryptoStream but I cant believe thats the only solution.
Or is it valid not to Close/Dispose a CryptoStream?
thanks for any help.
|
|
|
|
|
You can try Flush .
Personally I don't think that I've had a problem with opening a MemoryStream , then a StreamWriter on top of that, closing the StreamWriter and I was still able to access the MemoryStream .
|
|
|
|