|
|
My advice is twofold:
- download Visual Studio Express Edition, it is free and it works really well;
- buy at least one up-to-date introductory book on the programming language of your
choice, make sure the book targets Windows and if it relies on a specific IDE it better be
Visual Studio; and then work your way through the book to make sure you fully understand
the language; it will teach you the most important classes, and it will probably
show you how to do console apps first, windows apps later.
At first, don't try to figure it all out yourself, let the book be your guide !
It will be much much faster, and much more thorough at the same time.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Stick with learning just the language via the console. Learning with a GUI will distract you from learning the fundamentals. You need to crawl (console) before you walk (GUI).
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks for all the input on command vs gui for noobs...
also thanks for the express edition link
much appreciated and if you have any wisdom regarding programming please share
Thanks alot
Mark Nooby programmer
|
|
|
|
|
If you were new to programming and starting with C++ I would suggest a non-GUI application. However C# is made for the GUI interface and makes learning GUI programming very easy. Still, the approach for commandline programs in C# and C++ is quite a bit different.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Yes, you are right. In C++ and C++/CLI, you can write a simple program inside of the main function. However, C# requires you write your simple program inside of a class inside of a static method. Thus, a new programmer has to contend with OOP at the start before learning about the fundamentals such as variable scope and iteration. When you add the GUI in the picture, you are dropping a lot of learning overhead that overwhelms many new programmers. Thus, they may miss learning what they really need to be solid programmers.
In a nutshell, keep it simple and build on a solid base. Fancy GUI programming can be learned later with the fundamentals under their belts.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I have two ArrayLists, about 120 nodes in length. Each node contains a struct that contains about 24 variables. I want to easily compare the two ArrayLists. Am I going to have to create a method that simply goes through every node of both lists, comparing every variable? That seems tedious. Any help would be appreciated. Thanks
|
|
|
|
|
One method to compare one node to another, returning True or False.
One method to traverse the ArrayLists, passing the two nodes for comparison to method #1.
Now you can modify method #2 to traverse sequentially, compare 1 node of one array against all of the second array, etc., etc. Method #2 does not change.
Gary
|
|
|
|
|
For two ArrayLists A and B it all depends on how you define equality:
1. do you require the same number of elements? if so, check that first.
2. do you require the elements to be present in the same order? if so, just read through
both lists at the same time, and compare A[i] with B[i].
3. if not, first sort both lists according to whatever rule you can come up with that
defines a unique order, then go back to 2.
4. if you would allow for doubles then after sorting, remove (or skip) the doubles.
5. if you don't want to sort, you basically must compare N items of A with N items of B,
which is a quadratic job; you can improve a bit by removing the items you discover
are the same (copy them into two new ArrayLists). This reduces the job by a factor of 2
That's all.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I am very new and trying to do something very advanced.
Can you open a file with StreamReader, format with StringBuilder, and then pass the results of the StringBuilder to a StringCollection? or am I out of my mind.
Here is my StringBuilder routine;
----------------------------------
public static string LayoutInput(string input)
{
StreamReader sr = File.OpenText(input);
StringBuilder sb = new StringBuilder(input.Length);
bool firstLine = true;
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.Trim() == "")
continue;
if (line.Length < 29) { throw new InvalidOperationException("invalid input"); }
if (line[29] != ' ')
{
int txPos;
int rxPos = -1;
int len = 0;
if (firstLine)
firstLine = false;
else
sb.Append("\r\n");
if (((txPos = line.IndexOf("TX")) > -1) || ((rxPos = line.IndexOf("RX")) > 0))
{
int charactersTillPoint;
if (txPos > -1)
{
charactersTillPoint = txPos;
len = line.Substring(txPos).Length;
}
else
{
charactersTillPoint = rxPos;
len = line.Substring(rxPos).Length;
}
string part0 = line.Substring(0, charactersTillPoint);
string part1 = line.Substring(charactersTillPoint);
sb.Append(part0.PadRight(86));
sb.Append(part1);
}
else
sb.Append(line);
sb.Append(' ');
if (len == 12)
sb.Append(' ');
}
else
{
sb.Append(line.Substring(31));
}
}
return sb.ToString();
}
#endregion
}
----------------------------------
And here is my StringCollection Routine;
----------------------------------
StringCollection ReadFileIntoStringCollection()
{
const int MaxBytes = 65536;
StreamReader sr = new StreamReader(chosenFile);
StringCollection result = new StringCollection();
int nBytesRead = 0;
string nextLine;
while ((nextLine = sr.ReadLine()) != null)
{
nBytesRead += nextLine.Length;
if (nBytesRead > MaxBytes)
break;
result.Add(nextLine);
}
sr.Close();
return result;
----------------------------------
|
|
|
|
|
it seems from your second method you need to parse your string from string builder to lines like what you read from the Stream Am I right?
if it is what you need you can do with Split method from string instances like
string s = "hello \r\n how are you? \r\n";
string[] sArr = s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
StringCollection col = new StringCollection();
col.AddRange(sArr);
it was the easiest way with least code change
however your methods are not efficient you can add your string to StringCollection instance instead of writing sb.Append("/r/n")
hope the post would be useful
good luck
|
|
|
|
|
You are correct in your assumption.
I am not following what you are suggesting.
I am not asking for a rewrite of the code, maybe a snipit within the sample I sent as I tend to understand it better from a practical example(what I am working on).
Hessam Jalali wrote: string s = "hello \r\n how are you? \r\n";string[] sArr = s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);StringCollection col = new StringCollection();col.AddRange(sArr);
Hessam Jalali wrote: however your methods are not efficient you can add your string to StringCollection instance instead of writing sb.Append("/r/n")
Thanks,
Brian
|
|
|
|
|
solutionsville wrote: or am I out of my mind.
Nothing here leads me to that conclusion.
If I understand correctly what you mean by incorporating the two routines, you might be able to do something like this.
StringCollection ReadFileIntoStringCollection()
{
const int MaxBytes = 65536;
StreamReader sr = new StreamReader ( chosenFile );
StringCollection result = new StringCollection();
int nBytesRead = 0;
string nextLine;
while ( ( nextLine = sr.ReadLine() ) != null )
{
nBytesRead += nextLine.Length;
if ( nBytesRead > MaxBytes )
break;
result.Add ( nextLine );
}
sr.Close();
return result;
}
When I say "guts" I mean leave out the first few lines, start with the declaration of sb and go through the end of the while loop. Once you do that there may be some compilation errors or warnings to fix, but I think it should work. Or can be made to work.
Hope that's more or less what you had in mind.
BDF
|
|
|
|
|
Big Daddy, you are the man!
This have been driving me nuts for about a week. This is what it looks like combined and working.
--------------
So if I want to add this piece to the same method above, where would I put this?
private void findSequenceNumbers()
{
toolStripStatusLabel.Visible = toolStripProgressBar.Visible = true;
toolStripProgressBar.Value = 0;
int lineNum = 0;
bool startingNewLine = true;
FontStyle style = FontStyle.Bold;
string[] lines = rtbDoc.Lines;
string text = rtbDoc.Text;
toolStripProgressBar.Maximum = text.Length;
for (int i = 0; i < text.Length; i++)
{
if (startingNewLine)
{
if ((lines[lineNum].Contains("ARES_EINDICATION")) || (lines[lineNum].Contains("ARES_INDICATION")))
{
i += 169;
rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont, rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}
else if (lines[lineNum].Contains("]CODELINE_INDICATION_MSG"))
{
i += 160;
rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont, rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}
else
{
i += lines[lineNum].Length - 1;
}
startingNewLine = false;
Application.DoEvents();
}
if (text[i] == '\n')
{
startingNewLine = true;
lineNum++;
}
toolStripProgressBar.Value = i;
}
toolStripStatusLabel.Visible = toolStripProgressBar.Visible = false;
rtbDoc.Select(0, 0);
rtbDoc.ScrollToCaret();
}
Thanks and have a good weekend!
-- modified at 15:53 Saturday 25th August, 2007
|
|
|
|
|
Hi Brian,
I had a good weekend, hope you did too.
That's going to be a bit more involved. There are two approaches that I see, no doubt there are others as well.
First approach is to get the data from the file into memory using ReadFileIntoStringCollection() which now also does the work formerly done in LayoutInput() . Now the data is in a StringCollection object, from there it needs to go into the RichTextBox control. I don't know the best way to do this, it will take a little bit of experimentation. It might be as simple as rtbDoc.Text = result.ToString(); but I'm not sure that will work. You might have to iterate through result appending each string element onto rtbDoc.Lines or something like that. Once that data is in the RichTextBox control you can just call findSequenceNumbers() . This would offer the advantage of still being able to Select() a portion of the text and change the SelectionFont and SelectionColor . A big disadvantage might be the effort of getting the data into the RichTextBox control and the possible time used by findSequenceNumbers() .
Second approach involves more hacking up of the findSequenceNumbers() function and copying it into ReadFileIntoStringCollection() . To do this, instead of searching for your targets in lines[lineNum] you'll search in an element of result . Probably you can still use the [] array notation, seems to work with most Collection objects. But now you can't just set the SelectionFont and SelectionColor properties because we have just a plain old string, not the contents of a RichTextBox control. Instead you'll need to insert the raw rtf formatting sequences. Also you'll need to put some other rtf stuff into the beginning elements ofresult as well as some ending stuff once the file reading is done.
If you use the second approach, we find ourselves back to the problem of getting the StringCollection object into the RichTextBox control. Except now we're hoping that rtbDoc.Rtf = result.ToString(); is the silver bullet. You might consider putting in a temporary statement like
string temp = result.ToString();
in the while loop when reading the file. Just so you can see in the debugger what is going to returned by calling ToString() on a StringCollection object. Another thing to beware of is that you proably need to append "\r\n" to the end of each string element of result in order to see the line breaks in the RichTextBox control.
I would probably do the searching of each line just after it's been read and preprocessed. I haven't thought too much about handling the ProgessBar etc., but I'd worry about that after the other stuff gets worked out.
Hope this helps a little.
BDF
|
|
|
|
|
Hey BDF, yes I had a great weekend, time on the Harley, etc...
I had the same thought you did, and tried it. I didn't get any more speed performance from the routine doing it either way.
What did cut the time down on the load to RTB was to disable the RTB control until the routine is complete. It went from 3 1/2 minutes to about 20 seconds for a 8MB file.
I am gonna move on.
You have provided me great insight as to what I was missing.
Thank you very much for you help!
V/R
Brian
|
|
|
|
|
solutionsville wrote: disable the RTB control until the routine is complete
Good idea. Wish I'd thought of that!
I suppose the code was chugging along putting in lots of the rtf commands and each time the control had to redisplay itself. Only having to do that one time would account for the big time difference.
Good luck with your project!
BDF
|
|
|
|
|
plz can someone help me to get a FREE version of infragistics NetAdbantage for .Net from onother source of "www.infragistics.com" ?
|
|
|
|
|
well...I know that there is an evaluation license for NetAdvantage, but I haven't ever had to deal with it because I have access to an Enterprise license. ...Is there any specific reason why you don't want to get the eval versions from infragistics.com?
"I need build Skynet. Plz send code"
|
|
|
|
|
I presume because the eval versions time out after X days or are crippled in some way.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
I want that after the last no. I should get a full stop instead of a comma.Pl correct my code.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ch11Ex03yield
{
public class Primes
{
private long min;
public long max;
public Primes()
: this(2, 100)
{
}
public Primes(long i, long j)
{
if (i < 2)
{
min = 2;
}
min = i;
max = j;
}
public IEnumerator GetEnumerator()
{
for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)
{
bool isPrime = true;
for (long possibleFactor = 2; possibleFactor <=
(long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)
{
long remainderAfterDivision = possiblePrime % possibleFactor;
if (remainderAfterDivision == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
yield return possiblePrime;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Primes myPrimes = new Primes(2,1000);
foreach (long i in myPrimes)
Console.Write("{0}{1} ",i,
(i==myPrimes.max )?".":",");
Console.ReadKey();
}
}
}
|
|
|
|
|
System.Console.Write ( "\b." ) ;
|
|
|
|
|
...or you could just do that
"I need build Skynet. Plz send code"
|
|
|
|
|
for One...you're gonna wanna repost that code placed inside pre tags. ...That code is not illegible as is, but it's just an eyesore.
For two...well, format your code first
btw...you wouldn't happen to know how to build Skynet would you?
"I need build Skynet. Plz send code"
|
|
|
|
|
Did you read the reponses from when you posted this earlier?
|
|
|
|