|
You've only given some of the C# code. Look at a file called Form1.Designer.cs, or something similar. Here are some tips to get you started:
1. I don't see a definition for serialPort1. What type is it?
2. What does serialPort1.Read() return, if anything?
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
i use serialport component from toolbox.i get datas.cause i use breakpoints so i see my variables content.
|
|
|
|
|
Hi,
i want to pick up a file or correctly if i say, if there exist a text file then i want to read the contents of that file then want to send those content to another destination.
the software on which i am working is like Message sender/receiver, so i have to send that content as message to other destination.
so, is there any way by which i can pick a file, i m using c#.net as plateform.
And its my humble request, plz clarify in detail as i m not that good in programming and got confused easily. As i m still in phase of learning.
|
|
|
|
|
|
Hi humdumof, C#.NET provides a namespace System.IO which can be used for handling files and a class StreamReader and StreamWriter which can be used to read from or write to a file. As shown below
<br />
string path = @"D:\file.txt";<br />
<br />
if (File.Exists(path))<br />
{<br />
using (StreamReader sr = new StreamReader(path))<br />
{<br />
textBox1.Text = sr.ReadToEnd();<br />
sr.Close();<br />
}<br />
using (StreamWriter sw = new StreamWriter(@"D:\newfile.txt"))<br />
{<br />
sw.WriteLine(textBox1.Text);<br />
sw.Close();<br />
}<br />
}<br />
else<br />
{<br />
MessageBox.Show("File does not exist.");<br />
}<br />
This code first checks for the existence of the file and if present, it reads the content to a textbox and then copies/send the same data to other destination file, else, reads an error message. Hope it helps you.
|
|
|
|
|
i want add one property to my control.when i put mouse in that property i want to open one more window.same like datagrid table styles.How can i make a property like that?....................
|
|
|
|
|
Go and buy a book on winforms basics, or google and read up.
|
|
|
|
|
Please give code for checking the valid username and password from database
|
|
|
|
|
|
try {
SqlConnection con = new SqlConnection("connectionstring");
string sqlQuery = "select user,pwd from Login where user= ' " + this.TextBox1.Text + " ' and pwd=' " + this.TextBox2.Text + " ' ";
con.Open();
SqlCommand com = new SqlCommand(sqlQuery, con);
int results = com.ExecuteScalar;
if (results == 1)
{
return true;
}
else
{
return false;
}
con.Close();
com.Dispose();
}
catch (SqlException ex) {
MessageBox.Show(ex.ToString);
}
|
|
|
|
|
Ever heard of SQL injection?
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Yes, I do.
But didn't wanted to confuse this guy with such fundas. Seems to be a Beginner.
|
|
|
|
|
If he's that much a beginner, it's all just as confusing, so you could have used parameters. Doing so now will confuse him, so we best leave it.
|
|
|
|
|
I appreciate your good intent on getting him started with minimum pain and confusion.
At the same time, if we can make him understand secure programming concepts even at the inception it would be good. Isn't it?
|
|
|
|
|
thanks for your reply
But this shows the error to conver into string
|
|
|
|
|
I've been reading a lot of posts on how to use delegates to communicated between two forms. However, in every example I have the problem with the strucutre of the examples. In every case I've seen there is a main form, that delegates a function to another form. However the main form first creates the second form and then sends the data that way:
For example:
<br />
private void btnSend_Click(object sender, System.EventArgs e)<br />
{<br />
Form2 frm= new Form2();<br />
delPassData del=new delPassData(frm.funData);<br />
del(this.textBox1);<br />
frm.Show();<br />
}<br />
This is great except I have the issue where once another completely seperate form is created, some information is inputted by the user and then it closes. When this window closes I want to alert the first (main form) that this has happened so it can do some of its own calculations.
From what I've read delegates are the way to go but I have been unable to find a method to make this work. Thanks for your time and any help you give!
David
|
|
|
|
|
DavidNelson wrote: This is great except I have the issue where once another completely seperate form is created, some information is inputted by the user and then it closes. When this window closes I want to alert the first (main form) that this has happened so it can do some of its own calculations.
You can register a delegate with the Form.Closed[^] event. When the second form closes, it will raise this event. Alternatively, you can add an event to the second form. The event can be accompanied by a custom EventArgs derived class you create. This custom event class will carry additional information necessary for the first main form to make its calculations. In the second form, override the OnClosed method. Raise your custom event there. Register a delegate with the event in order to respond to it.
You can skip using events all together if the main form has access to the second form. In the second form, add properties representing the user entered information. The main form can access those properties after the second form is closed.
|
|
|
|
|
You can simply assign an event handler to the FormClosing event of the second form.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
What is the C# equivalent to java's .readInt()?
The following code returns different values when the same file is read.
C#
FileStream fs = new FileStream("file", FileMode.Open);<br />
BinaryReader br = new BinaryReader(fs);<br />
Console.out.WriteLine(br.ReadInt32();
Java
DataInputStream datainputstream = (new DataInputStream(new FileInputStream("file")));<br />
System.out.println(datainputstream.readInt());
|
|
|
|
|
|
i think so.
readInt()
Reads four input bytes and returns an int value.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInput.html
Reads four input bytes and returns an int value. Let a be the first byte read, b be the second byte, c be the third byte, and d be the fourth byte. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) |
((c & 0xff) << 8) | (d & 0xff))
|
|
|
|
|
The Java readInt method reads in big-endian (Motorola) format, while .NET ReadInt32 reads in little-endian (Intel) format.
---
single minded; short sighted; long gone;
|
|
|
|
|
Guffa wrote: The Java readInt method reads in big-endian (Motorola) format, while .NET ReadInt32 reads in little-endian (Intel) format.
How could I forget? Guess I haven't worked with Java in a long time
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Ok so i figured it out.
Now when i write the integer to the file, i would have to write it using Big Endian coding so Java can read it, correct?
Anyone want to point me in the right direction?
|
|
|
|
|
Ok I'm still pretty new to C# and could use some advise. I'm trying to work with the SJPhone API and all the examples that come with it are in VB6. To start the program up you need to initialize the API and it is done like this...
Private Sub StartConnecting()
TextState.Text = "Initializing: stage 1"
Set ApiConnection = New SJxmlApiConnection
If (ApiConnection.Initialize("SJphoneXmlApiDemo.dll")) Then
ToConnectingState
Else
ToConnectfailedState
End If
End Sub
Now if I try to call the dll like that C# has a fit, but I just don't know why yet? What is the C# way of doing this? The Init function requests the dll passed as a string so what can I do different? Thank you for any help here.
|
|
|
|