Askjerry
Member
- Joined
- Aug 25, 2014
- Messages
- 10
- Programming Experience
- 10+
I feel like such a NOOBE... been programming in C# for about 3 hours now... so I guess I am. :rapture:
Anyway... I'm stuck on what is likely C# 101 stuff... I programmed code to talk to a USB device, create a file, pull data from the device... I just want to print it to the file.
I have a textbox called "file_name" and I dropped the name/path of the file into it... and I can look at the directory and see the file is actually created...
That works... I'll skip the bunch of code to configure the device, etc... herre is where I am getting the data and TRYING to output the results to the file...
In the places I have "//--- INSERT WRITE here" I want to send out the string of text that is being kicked out in the line just above...
In VB I would have opened the file and done something like...
So in this case I want to do something like...
write to myfile, Qarray[myCounter].ToString("D2") + ",";
Obviously... the issue is that "write to myfile" isn't the method/function to use.... "myfile.Write()" wants a bunch of BYTE values...
I can define a string... myText... and do something like...
So how to I get myText out to the file????? (grrrr)
Thanks,
Jerry
Anyway... I'm stuck on what is likely C# 101 stuff... I programmed code to talk to a USB device, create a file, pull data from the device... I just want to print it to the file.
I have a textbox called "file_name" and I dropped the name/path of the file into it... and I can look at the directory and see the file is actually created...
C#:
//----------- Put a file somewhere -----------------------------------------------------------
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Excel CSV|*.csv|All Files|*.*";
saveFileDialog1.Title = "Save Data File";
saveFileDialog1.ShowDialog();
//----------- Now do something ---------------------------------------------------------------
file_name.Text = saveFileDialog1.FileName;
That works... I'll skip the bunch of code to configure the device, etc... herre is where I am getting the data and TRYING to output the results to the file...
C#:
if (saveFileDialog1.FileName != "")
{
System.IO.FileStream myfile = (System.IO.FileStream)saveFileDialog1.OpenFile();
//============================================================================================
textBox1.Text += "Iarray Data\r\n";
for (int myCounter = 0; myCounter < 512; myCounter++)
{
textBox1.Text += Iarray[myCounter].ToString("D2") + ",";
//--- INSERT WRITE here
}
textBox1.Text += "\r\n";
//============================================================================================
textBox1.Text += "\r\n" + "Qarray Data\r\n";
for (int myCounter = 0; myCounter < 512; myCounter++)
{
textBox1.Text += Qarray[myCounter].ToString("D2") + ",";
//--- INSERT WRITE here
}
textBox1.Text += "\r\n";
//============================================================================================
myfile.Close();
}
In the places I have "//--- INSERT WRITE here" I want to send out the string of text that is being kicked out in the line just above...
In VB I would have opened the file and done something like...
C#:
Print #1, myText
So in this case I want to do something like...
write to myfile, Qarray[myCounter].ToString("D2") + ",";
Obviously... the issue is that "write to myfile" isn't the method/function to use.... "myfile.Write()" wants a bunch of BYTE values...
I can define a string... myText... and do something like...
C#:
string myText = Iarray[myCounter].ToString("D2") + ",";
So how to I get myText out to the file????? (grrrr)
Thanks,
Jerry
Last edited: