|
If your still around I cant get thee files to assign the values of the temp file. Ill keep working on it as usual. When I assign i.toString it just names the files 1-20 in order and does not assign the actual number read from the other file.
private void button2_Click(object sender, EventArgs e)
{
string path = @"C:Random # File.txt";
StreamReader readtext = new StreamReader(path);
StreamWriter writetext = new StreamWriter("write.txt");
for (int j = 0; j < 20; j++)
{
string readmetext = readtext.ReadLine();<br />
writetext.WriteLine(Convert.ToInt32(readmetext));
<pre>
}
writetext.Close();
readtext.Close();
StreamReader rt = new StreamReader("write.txt");
File.WriteAllText(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\"
+ i.ToString("0000") + ".txt", i.ToString());
MessageBox.Show("temp created");</pre>
|
|
|
|
|
Stop guessing, and look at your code.
This isn't a subject where guesswork is rewarded - you have to think about what you are doing!
Your code writes sequential numbers into the files, because that is exactly what you told it to do.
Instead of using the number you read from the input file, you are creating the files using a random value of "i"...
And what do you expect your code in the actual loop to do? What does writing pretty much exactly what you read do that is useful?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ok I got some sleep and looked at it again and your right I was guessing. I did what I thought would work. I read the method description and how it works and sent the actual line value to the file names and it only produced files with numbers that were not ones that were being read from the lines in the imported file.
for (int i = 0; i < 20; i++)
{
int files = rt.Read();
File.WriteAllText(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp.txt"
+ files.ToString("0000") + ".txt", files.ToString());
}
MessageBox.Show("temp created"); lang="cs">
|
|
|
|
|
That looks a bit better!
Now, remove the "temp.txt" bit, and use an empty folder!
Create a folder in "My Documents", and give it read and write permissions to everybody.
then
File.WriteAllText(@"C:\Users\grantlinhart\Documents\WorkingFolder\" + files.ToString("0000") + ".txt", files.ToString()); And you should get the files (and just the files)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yeah when I ran it in that version it called every file temp0001, temp0002....etc.
I fixed that bit I put them in a temp folder all by themselves and this is what I get when i run it now. it should be the random #s that are in the random file as individual files right? now when i run it i get 12 files named 0010 0013 0048 0049 0050 0051 0052 0053 0054 0055 0056 0057 all of the files values correspond to the name, however the random numbers generated by my file are from 1-40 and shouldn't there be 20 files since the loop iterated 20 times or should i use a while loop that iterates to the end of the file?
I tried to put it in the workingfolder but it always threw an exception. Is there a way to paste a picture on these posts
}
<pre>writetext.Close();
readtext.Close();
StreamReader rt = new StreamReader(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\write.txt");
<pre>
for (int i = 0; i < 20; i++)
{
int files = rt.Read();
File.WriteAllText(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\"
+ files.ToString("0000") + ".txt", files.ToString());
}
}</pre></pre>
|
|
|
|
|
this is what I tried to do to sort the #s into files: I found a getFiles method in a Process directory method and my intent was to import the whole directory and read each file and write the contence to the sorted file as you suggested, however nothing appears in the Sorted file after I run it. If you see why please let me know I will still keep trying to debug it but if a glaring error pops out to you please let me know, thanks
private void button2_Click(object sender, EventArgs e)
{
string path = @"C:Random # File.txt";
StreamReader readtext = new StreamReader(path);
StreamWriter writetext = new StreamWriter("write.txt");
for (int j = 0; j < 20; j++)
{
string readmetext = readtext.ReadLine();
writetext.WriteLine(Convert.ToInt32(readmetext));
<pre>
}
writetext.Close();
readtext.Close();
StreamReader rt = new StreamReader(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\write.txt");
for (int i = 0; i < 20; i++)
{
int files = rt.Read();
File.WriteAllText(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\"
+ files.ToString("0000") + ".txt", files.ToString());
}
rt.Close();
ProcessDirectory(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\");
}
public static void ProcessDirectory(string targetDirectory)
{
string variable1;
StreamReader readToSort = new StreamReader(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\write.txt");
StreamWriter writeSorted = new StreamWriter(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\Sorted_File.txt");
string[] fileEntries = Directory.GetFiles(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\");
foreach (string fileName in fileEntries)
{
variable1 = readToSort.ReadLine();
writeSorted.WriteLine(variable1.ToString() + "\n");
}
}</pre>
|
|
|
|
|
the text file looks like this it is all #s and it is randomly generated each time
the app is run
I have to do 2 things with the text file that is generated. I have to put the #s in order
and find the lowest one without using an array or assigning variables to be parsed. I have been researching the file class trying to see if i could create a temp file to hold them and then sort the temp file contents in some way. It is a hard problem given the constraints of not being able to use an array and a simple sort. there is one # per line this thread does not show it that way
40
21
2
1
7
18
32
10
|
|
|
|
|
i spoke too soon, now its just pulling the first # in the line of random numbers and not comparing the other #s that come after it in the list oh well back to the drawing board
|
|
|
|
|
Hi, how to split list to two columns in winform gridview.
I have some list
public static string[] addresses = { "192.168.1.45", "10.36.15.1", "10.36.47.1", "10.36.63.1", "10.36.50.1", "10.36.15.16", "10.36.47.11", "10.36.63.11", "10.36.50.16" };
and results are shown in a single column.
List<string> resultsList = new List<string>();
Parallel.ForEach(addresses, address =>
{
string ip = "";
<pre>
Ping pinger = new Ping();
PingReply reply = pinger.Send(address);
if (reply.Status.ToString() != "Success")
ip = address + " Failed";
else
ip = reply.Address.ToString() + " , Time: " + reply.RoundtripTime.ToString() + "ms , " + " OK";
pinger.Dispose();
resultsList.Add(ip);
});
foreach (var something in resultsList)
{
dataGridView1.Rows.Add(something);
}</pre>
I want to separate the results in two columns. Especially ip, especially time
Please help
|
|
|
|
|
arsale wrote: I want to separate the results in two columns.
dataGridView1.Rows.Add(new object[] { "Row 1, Col 1", "Row 1, Col 2" });
dataGridView1.Rows.Add(new object[] { "Row 2, Col 1", "Row 2, Col 2" }); Would only work if the dgv actually has two columns.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, but i want to split ping result (var something in resultsList) on two columns.
|
|
|
|
|
arsale wrote: Yes, but i want to split ping result (var something in resultsList) on two
columns. Which two ping-results would you want in there?
dataGridView1.Rows.Add(new object[] { reply.Address.ToString(), reply.RoundtripTime.ToString() + "ms" });
dataGridView1.Rows.Add(new object[] { reply.Address.ToString(), reply.RoundtripTime.ToString() + "ms" }); Further, I'd recommend Convert.ToString(T) over (T).ToString, as the former does not throw an exception on null values.
--edit;
along the lines of
dataGridView1.Rows.Add(new object[] { Convert.ToString(reply.Address), string.Format("{0} ms", reply.RoundtripTime) });
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
We did not understand. I have a list that should be every line splitted into two parts and display each in a separate column. The problem is how to separate the list into two parts and display them in the same row. When you split variable, gridview each part put into a separate row.
Thanks for advice
|
|
|
|
|
Ah, indeed, I misunderstood.
foreach (var something in resultsList)
There's only one "something" that needs to be splitted over multiple columns?
ip = reply.Address.ToString() + " , Time: " + reply.RoundtripTime.ToString() + "ms , " + " OK"; The "var" should contain a string. A string.Split[^] should do the trick;
foreach (string s in resultsList)
{
string[] parts = s.Split(",", StringSplitOptions.RemoveEmptyEntries);
dataGridView1.Rows.Add(parts[0], parts[1]);
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm sorry i not a purify code.
ip = reply.Address.ToString() + " , Time: " + reply.RoundtripTime.ToString() + "ms"
In part
string[] parts = s.Split(",", StringSplitOptions.RemoveEmptyEntries);
i I'm getting a error "cannot convert from 'string' to 'char[]'"
modified 1-Apr-15 6:04am.
|
|
|
|
|
VOILA, bravo! Thanks for good advice.
I'm use only
string[] parts = s.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
insted above and works like a charm.
Thanks again
|
|
|
|
|
Sorry, forgot that it requires an array - but well done
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, it's very useful piece of code.
My regards
|
|
|
|
|
I have 2 User control added on the main form??
UserControl1 have TextBox which accept the input.
UserControl2 Will display the text From TextBox which is on UserControl1.
UserControl1
{
public delegate void TextChangeHandler(string strText);
public event TextChangedHandler _textChanged;
UserControl1()
{
this._textChanged+=new TextChangeHandler(UserControl2.onTitleChanged);
}
textBox1_textEntered()
{
if(_textChanged!=null)
{<br />
_textChanged(textBox1.text);
}
}
}
UserControl2
{
OnPaint()
{
drawString(text,..);
}
onTitleChanged(strText)
{
text = strText();
this.Refresh();
}
}
Could not refresh here.
Is It require to register TextChangeHandler in uSerControl2 also??
because I register It in USerControl1.
|
|
|
|
|
Yes, if you want it to be available to the outside world.
Unless classes are derived from each other (class2 derived from class1 for example) they do not automatically inherit any behaviour!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
then How Should I register iT??
|
|
|
|
|
The same way you do in UserControl1?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
still could not repaint.Actually I added 2 control on the panel.Could It be the issue for repainting??
May be due to added on the panel we could not repaint??
|
|
|
|
|
Step back a moment and remember that we can't see your screen, access your HDD, or read your mind.
So try posting the relevant code fragments which show exactly what you are doing, and what you expect to get.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
HI,
I have 3 tables. I wish to select the latest Unit Rate from those tables....like SQL Cross Apply.Is it possible from Ms-Access?
The below SQL-Query Select the latest unit_price, price_date from three tables..... Itemmst, Pomst, Grinmst
Actually the query checks those three tables and will select the greatest Price_date and Unit_Rate
Select i.itm_code,i.itm_description,i.unit_measure,t.unit_rate,t.price_date from itemmst i cross apply ( select top 1 unit_rate,price_date from( select im.unit_rate,''as price_date,0 as ord from itemmst im where im.itm_code=i.itm_code and im.unit_rate is not null union all select unit_price as unit_rate,po_date as price_date,1 as ord from pomst where pomst.itm_code =i.itm_code and pomst.unit_price is not null union all select grinmst.unit_rate,grinmst.grn_date,1 from grinmst where grinmst.itm_code =i.itm_code and grinmst.unit_rate is not null )r order by price_date desc,ord desc )t
Output :-
- Item1, Pencil, Nos, 25.00, 26/03/2015 => from Grimst
- Item2, Pen, Nos, 22.00, 21/03/2015 => from Pomst
- Item3, Paper, Nos, 65.00, 01/04/2014 => from Itemst
Thanks
|
|
|
|
|