Szpilona 18 Light Poster

Can you be a little bit more specific? What kind of system have you created? Where the database is located (f. ex. on a remote server or you simply have the file with the database)? etc.

Szpilona 18 Light Poster

After making some more research on the subject I actually found freely available articles of experts in the field (people working with those norms)... Inside of them you can find not only the explanation of the concepts but also citations of the norm... for example:
http://www.ewsolutions.com/resource-center/rwds_folder/rwds-archives/issue.2009-10-12.0790666855/document.2009-10-12.3367922336/view?searchterm=ISO%208000%20data%20quality
as you can find quite a lot of such articles in the Internet and some of the authors actually come from USA I assume what was discussed in this thread is not intellectual property theft also in USA...
so the thread is solved... :-)

jephthah commented: yawn. +0
Szpilona 18 Light Poster

ok... as you were not willing or not able to give me any explanation for the questions I posed and I was very, very curious how it is treated I contacted my friend who is a lawyer... he is not the specialist from the field of penal law but in Poland you must have the bases of all the fields if you want to pass the exam... and the case is a little bit more tricky than I thought... according to our law, it is subjective... meaning it depends on the situation how it would be treated... more or less it is treated like that = main conclusions on examples (we talked about that for a couple of hours so those are really main conclusions):
1. if company A would ask a company B to provide it with the text or part of the text of the norm or other document because they don't want to pay for that, and both parties would know about who is who etc. it would be treated as a nice workaround for actual crime and treated/judged as it... so it would be intellectual property crime for both parties... (that is the worst case because both parties act in bad faith...)
2. if anybody would copy or provide somehow (not give as a donation or gift etc.) the whole text to somebody else in most cases it would be treated as a workaround too... in most cases because imagine you teach somebody lyrics …

Szpilona 18 Light Poster

accusing once again... without taking any effort to check or read what I stated... nice & classy...
1. licenses for universities for educational purposes are payed too but in different rate (they are cheaper I guess)... and to give students the possibility to use software at homes is payed in other way... not every company is willing to organize something like MSDN AA... for example in my roommate university they start teaching programming from Pascal... have licences for Delphi for labs but despite negotiations with the company they did not get licenses for students for use at homes - in the way is for example available with MSDN AA... many other companies are not willing too to invest in future stuff or customers or in education... and some things we cannot afford...
2. I try not to use any software that I do not license for... most of the software I need I have got from MSDN AA, I tried Corel draw with trial version but right now I'm perfectly happy with inkscape which is free, instead of Microsoft Office use Led (Latex) or Open Office and to open ".doc" documents I use google aps, electronic dictionaries I've managed to get from some Personal Development Programs organized by European Union (form of investment in human capital programs)... summarizing I make the effort to find open source products or get the license in some way or use trial versions... so once again you abuse me without any proof...

Szpilona 18 Light Poster

could you please use plain, "official english"... IANAL - what does it mean? it is sometimes difficult to understand such things for non-english speakers...

all of the people taking part in this discussion think that providing me with the information how data quality is defined in the ISO norm is a crime but no one actually is willing to explain me how... even though I kindly asked you for the explanation... I'm pretty sure that stating "according to norm the concept X is Y and Z" doing that with one's own word is NOT A THEFT - only reference or citation or sth like that... from mine point of view in the same way wikipedia works... wikipedia function in a lot of countries... also in USA where the servers of that forum are probably located... and you try to tell me that for example me going to wikipedia and writing in the article that "according to the source X the concept Y is defined as Z" is crime and intellectual property theft... I have doubts in here (but as I stated earlier asking for explanation I am not from legal field so I CAN BE WRONG and it can be differently treated in USA and other countries)... so what I think is that you actually took for granted that I am a consultant or an IT firm which just do not want to pay for that or a very, very lazy student who is just too lazy to go …

Szpilona 18 Light Poster

No, plagiarism is you USING the document as your own. Theft is you giving something you don't own to someone else -- sort of. It's definitely not plagiarism.

Thank you...
+ according to Polish law (I can not say how it is regulated in other countries) saying in other word, naming the source (sometimes even with exact words - it depends - there's more regulations), what was stated in a book, art etc. is not theft that's why initiatives like wikipedia can function...

i can't imagine a university, even in a Second World country, that is unable or unwilling to make journals and standards documents accessible to students.

You cannot? come to Poland... the only university which have access to norms in my city has only partial access and that particular norm is not available (and I study in one of the biggest university cities)...
+ not being sarcastic because it is sad and difficult for us (I just state the fact)... in most countries it will be unimaginable to put in the same ONE plane the most important persons in the country... and look what happened in Poland (if you do not know what I refer to, find something about recent death of Polish president, 6 most important generals etc. like f.ex.

http://en.wikipedia.org/wiki/2010_Polish_Air_Force_Tu-154_crash#Notable_passengers

, http://en.wikipedia.org/wiki/List_of_casualties_of_the_2010_Polish_Air_Force_Tu-154_crash)

Szpilona 18 Light Poster

1. ok... may be my point of view is wrong... but if so please explain me in which way stating that according to source X the concept Y is Z is intellectual property theft or plagiarism... for me it is just a citation... but may be I'm wrong - if so explain me how it works and refer to appropriate sources supporting your point of view... and explain why in such cases Wikipedia and similar sites can function... and if so why are you tolerate giving thorough, theoretical explanations to forum questions - those explanations actually are based on some books or arts and often they are not even acknowledged...
2. probably in most countries degree thesis must contain the SOTA (state of the art) part... and how can I give state of the art part without referring to other sources, to authors that are experts in the field? you probably too have written a degree thesis or something like that... if so you had to have some references in it...
3.

I say, you work for some crappy software consulting gig, and they want you to steal a copy of it because they don't want to pay for it.

no... I'm unfortunally a student who want to have well done SOTA part of thesis to have it well marked (or graded) but cannot afford to buy all the articles, norms etc. that can be useful...

Szpilona 18 Light Poster

it depends on how you will do that... straight copy of a text or part of it may be in some cases treated as plagiarism (NOT ALL)... but saying that "according to the norm X the concept Y is defined as Z" (what I need) is NOT treated as intellectual property theft..... according to what you're saying a lot of forums should be closed and their admins and moderators sued for intellectual property theft as on the domain specific forums it is normal that explaining somebody a concept you refer to the authorities in the field (f. ex. saying that for X, who's definitely the guru in Y, the concept Z is treated as D)... according to what you're saying wikipedia should be closed too... and yeap... doing something similarly to what was previously done/showed on MSDN is definitely a plagiarism too... so if you're programmer find yourself another way to open the file because just changing the name of the file in statement presented first on MSDN is plagiarism too...

so summarizing before saying something check the binding law first... and remember the law can NOT always be consistent with what you're thinking...

btw I would buy it if I could afford it... you can say that not eating for a couple of days to invest in my future is still good for me and even better for my figure... but... I will not fast for a couple of days - I'm not as big enthusiast of …

Szpilona 18 Light Poster

1. as far as I know (at least according to Polish law) a plagiarism is use or use after some slight changes of other person's product (it is thought, code, photo etc.) AS ONE'S OWN meaning WITHOUT NAMING THE AUTHOR WHICH OBVIOUSLY IS NOT THE CASE... to have well done state of the art I want to cite (so WITH MARKING THE SOURCE), in addition to other definitions, the norm... and yes I know that having other sources cited, so having other definitions, I not probably need that one too... but I'm rather meticulous person and when I do something I do what I can to do that right, accurately etc. and obviously the ISO norms are important and can give some more insight...
2.

almost certainly a university library containing documents like the one you're looking for

<rotfl> I'm not sure where are you come from but guess not from Poland... In my university we've got NO ACCESS to such databases as ACM, IEEE... lately and probably only till the end of this semester we've got partial access on ONLY ONE POSITION IN THE LIBRARY (so to one person at the moment) to springer link... with norms it is even bigger problems as I'm not from technician university... and the only technician university in my city has only partial access to norms and that one is not available... so not to write even more on the subject to get that doc I will have to pay for that …

Szpilona 18 Light Poster

Hi,
As most of you are IT profs probably some of you have access to ISO norms... I'm looking for one particular definition which should be contained in ISO 8000-102:2009 it is definition of data quality... As I need only that one info for my master thesis I'm not willing for paying of the whole doc especially that it is very expensive relative to my earnings... :( so if you've got access to it please copy and paste that one def...

jephthah commented: how's it feel to be so full of [FAIL] +0
Szpilona 18 Light Poster

as InterestedCompany is a class in the student class you have to create the instance of it... preferably create constructor for student class:

public Student()
{
   this.x = new InterestedCompany();
}

or create an instance like that:

InterestedCompany x = new InterestedCompany();

inside of Student class...
I'm not sure which solution is better... I personally usually for such things create constructor...

Szpilona 18 Light Poster

well... I've recently created a bot too but as I needed some fancy features I've created my own class and for proxy support used WebProxy class... there's also other classes to accomplish that (like GlobalProxySelection)...

if it comes to webBrowser control as far as I know it does not nativaly support proxies but as it somehow refer to Internet Explorer it supports its settings... in here you will find some more information and probably the solution you are looking for (check comments for the art):
http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx

Szpilona 18 Light Poster

well... I'm not good in that but:
1. create query more or less like that:

string query = "update tableName set money=" + textbox1.Text.Trim() + "where id=2";

2. construct connection string... if you do not know how to do that use wizard... to do that select from main menu of VS: Data -> Add new data source -> Choose a datasource tylpe (database) -> click New connection and copy the connection string constructed by the wizard...
3. connect to a database and execute query:

using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader sqlReader = command.ExecuteReader();

                 while (sqlReader.Read())
                 {
                     // check the result
                 }
            }
Szpilona 18 Light Poster

to copy the lines from richtextbox or textbox (with multiline set to true) you can use Lines property:

string[] lines = textBox1.Lines;
            foreach (string line in lines)
            {
                if (line.Contains(""))
                    rtbResults.Text += line;
            }

if you need some more sophisticated checks on lines probably you will have to use regular expressions (Regex class itd.)... for simple checks standard string functions are sufficient...

if it comes for coping the text directly from webBrowser class I can't see any property for that (it does no mean that it does not exist... :) ) but for sure there are properties that takes html code of the currently loaded page... according to what you want to do with the code there are 3 of them:

HtmlDocument docCode = webBrowser1.Document;
            Stream docStream = webBrowser1.DocumentStream;
            string docString = webBrowser1.DocumentText;
Szpilona 18 Light Poster

actually my cut-n-paste from msdn is absurdly overdone...

eh... don't be so sure... as the code is from MSDN there can be some kind of performance differences... taking for example your little mistake (List<string> imgTagsHtml = new ArrayList<string>(); i guess typo) there is a big performance difference between List and ArrayList... according to microsoft and benchmarks List is much faster than ArrayList...
there can be such a difference also in that case...

Szpilona 18 Light Poster

if he wants to find something on the page that is currently loaded in the WebBrowser control what to use WebClient for? it will unnecessary once again send HTML request to the server which can takes some time... so basically from my point of view it's waste of resources...

Szpilona 18 Light Poster

Hey guys

and girls... ;-P

if you want to do that inside of your program the easiest way is probably to use DocumentText property... in that case you get the code of the current page (in string which is convenient in that case; to get html code use Document property) and you can parse it using regular expressions...

Szpilona 18 Light Poster

sorry I've made a mistake... read your question a little bit too fast... you want to select a folder not a file so as PierlucSS suggested you have to use FolderBrowserDialog... you can link this with the rest of your code in many different ways... I usually accomplish that by adding the dialog and button from toolbox, putting the button by the right side of the control which will be provided with results from the dialog, changing the text property of the button to "..." and adding the:

private void button11_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                cbDirectorySearcher.Text = folderBrowserDialog1.SelectedPath;
        }

many programs use that pattern... but as I've said it is not the only way...

Szpilona 18 Light Poster

you can also add the button and OpenFileDialog control from toolbox... change the text property of the button to "...", add button click event and paste the code (change only the names of the controls):

private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            textBox1.Text = openFileDialog1.FileName;
        }
Szpilona 18 Light Poster

ok...
1. there is a good practice to always name the components added to the form to reflect their functions (= what they were added for)... and there are some conventions of naming the components... I use the one which suggest to give at the beginning the abbreviated name of the component and then something that suggest what the component do... so:
cbDirectorySearcher = cb (for ComboBox) and DirectorySearcher (as in that combo box I want to specify the directory from which I will start searching for the files)
tbPattern = tb (for TextBox) and Pattern (as in that text box I want the user to provide the name of the file or part of it)
rtbDirectories it should probably be called rtbFound or sth like that... rtb is for richTextBox... in here I add the results...
2. Directory is a class from System.IO namespace... so add
using System.IO...
3. if it comes to what PierlucSS suggested, in the example that I've provided above you can apply those properties to combobox... it can be set in Properties window for combobox and it will help the user specify the directory from which to start searching...

Szpilona 18 Light Poster

well... to find all the files you can use Directory class and GetFiles(), GetDirectories() method... below I've pasted the code snippet showing how it can be used... it seems to work but I did that in the hurry so you can find there some mistakes...
btw I added the comboBox to give the method the start point and paste some information to richtextbox:

// here I add all logical drive to combobox
        private void Form1_Load(object sender, EventArgs e)
        {
            string[] logicalDrives = Directory.GetLogicalDrives();
            for (int i = 0; i < logicalDrives.Length; i++)
            { 
                cbDirectorySearcher.Items.Add(logicalDrives[i]);
            }
        }
       // recursive function
        private void checkFiles(string pattern, string path)
        {
            string[] directories = Directory.GetDirectories(path);
            string[] files = Directory.GetFiles(path);
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Contains(pattern))
                    rtbDirectories.Text += files[i].Substring(files[i].LastIndexOf('\\') + 1) + "\t" + files[i] + "\n";
            }
            for (int i = 0; i < directories.Length; i++)
            {
                checkFiles(pattern, directories[i]);
            }
        }
        // main method - in here I call recursive function
        private void button10_Click(object sender, EventArgs e)
        {
            string pattern = tbPattern.Text;
            if (pattern == String.Empty)
                return;
            string path = cbDirectorySearcher.SelectedItem.ToString();
            checkFiles(pattern, path);
            MessageBox.Show("Finished");
        }

btw searching the files can take a lot of time... so I recommend put it to another thread...

Szpilona 18 Light Poster

1. If you want to do any operations on array of values it does must have some values so fill array with values:

int[] value = new int[5] { 5, 1, 2, 4, 3 };

you can also give the user the possibility to specify the values:

int[] value = new int[5];
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Specify number " + (i + 1).ToString() + ": ");
                value[i] = Convert.ToInt32(Console.ReadLine());
            }

but remember that conversion from string to int is not always possible so you should put it in the try catch block (if you're already familiar with errors handling)...
2. using

arrayName[index]

syntax you get the value form array!

You're code after corrections... I did not added any sophisticated code trying to make it easier for you...

int[] value = new int[5] { 5, 1, 2, 4, 3 };
            /*
            int[] value = new int[5];
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Specify number " + (i + 1).ToString() + ": ");
                value[i] = Convert.ToInt32(Console.ReadLine());
            }
            */ 
           
            int sum = 0, multip = 1;
            string tpl= "", crp= "";
            for (int i = 0; i < 5; i++)
            {
                sum += value[i];
                multip *= value[i];
                if (i != 4)
                {
                    tpl += value[i].ToString() + " + ";
                    crp += value[i].ToString() + " * ";
                }
                else
                {
                    tpl += value[i].ToString();
                    crp += value[i].ToString();
                }
            }

            Console.Clear();
            Console.Write(tpl + " = " + sum.ToString() + "\n"); …
ddanbe commented: Very helpfull. +6
Szpilona 18 Light Poster

set enable property to false....

Szpilona 18 Light Poster

if it comes to combo box there is no ReadOnly property... so depending on what you want to do you can f.ex. use DropDownStyle property (if you select DropDownList there's no way to put values other than from list) or Enable..

Szpilona 18 Light Poster

answers to questions from private message:
yeap... there's a little error in the code... in the:

private void button1_Click(object sender, EventArgs e)

line 18 - it was:

for (int i = textFromRTB2.Length + 1; i < textFromRTB1.Length; i++)

it should be:

for (int i = textFromRTB2.Length; i < textFromRTB1.Length; i++)

and similarly, line 29... it was:

for (int i = textFromRTB1.Length + 1; i < textFromRTB2.Length; i++)

it should be:

for (int i = textFromRTB1.Length; i < textFromRTB2.Length; i++)

if it comes to other questions there will be NO answer... from my point of view you show no effort - you only try to find somebody to do your job for you... finding that little mistake was very, very easy even for somebody completely new to C#...

Szpilona 18 Light Poster

TextBox class has the property ReadOnly... set it to true... you can do that in the properties window or in the code...

Szpilona 18 Light Poster

I did not have any time to take a closer look to that problem (a lot of work... ;()... so that's probably not the best way to accomplish that, but it works...
enjoy the code:

private void compareLines(int linesCount, string[] textFromRTB1, string[] textFromRTB2)
        {
            bool checker = true;
            for (int i = 0; i < linesCount; i++)
            {
                checker = String.Equals(textFromRTB1[i], textFromRTB2[i]);

                if (!checker)
                {
                    if (textFromRTB1[i] == String.Empty)
                        richTextBox1.SelectionBackColor = Color.Green;
                    else
                        richTextBox1.SelectionBackColor = Color.Red;
                    if (textFromRTB2[i] == String.Empty)
                        richTextBox2.SelectionBackColor = Color.Green;
                    else
                        richTextBox2.SelectionBackColor = Color.Red;
                    richTextBox1.SelectedText = (i + 1).ToString() + ". " + textFromRTB1[i] + "\n";
                    richTextBox2.SelectedText = (i + 1).ToString() + ". " + textFromRTB2[i] + "\n";
                }
                else
                {
                    if (textFromRTB1[i] == String.Empty)
                    {
                        richTextBox1.SelectionBackColor = Color.Green;
                        richTextBox2.SelectionBackColor = Color.Green;
                    }
                    else
                    {
                        richTextBox1.SelectionBackColor = Color.Yellow;
                        richTextBox2.SelectionBackColor = Color.Yellow;
                    }
                    richTextBox1.SelectedText = (i + 1).ToString() + ". " + textFromRTB1[i] + "\n";
                    richTextBox2.SelectedText = (i + 1).ToString() + ". " + textFromRTB2[i] + "\n";
                }
            }
        }

and then:

private void button1_Click(object sender, EventArgs e)
      {
          string[] textFromRTB1 = richTextBox1.Lines;
          string[] textFromRTB2 = richTextBox2.Lines;
          richTextBox1.Clear();
          richTextBox2.Clear();
          int linesCount = 0;

          if (textFromRTB1.Length == textFromRTB2.Length)
              compareLines(textFromRTB1.Length, textFromRTB1, textFromRTB2);
          else
          {
              linesCount = Math.Min(textFromRTB1.Length, textFromRTB2.Length);
              compareLines(linesCount, textFromRTB1, textFromRTB2);

              if (textFromRTB1.Length > textFromRTB2.Length)
              {
                  for (int i = textFromRTB2.Length + 1; i < textFromRTB1.Length; i++)
                  {
                      if (textFromRTB1[i] == String.Empty)
                          richTextBox1.SelectionBackColor = Color.Green;
                      else
                          richTextBox1.SelectionBackColor = Color.Red;
                      richTextBox1.SelectedText = (i + 1).ToString() + ". " + textFromRTB1[i] + "\n";
                  }
              }
              else
              {
                  for (int …
Szpilona 18 Light Poster

So there will be a problem... as far as I know richtextbox does not support selecting and coloring a line - I mean you cannot select a blank line... so any line consisting of "\r", "\n" or "\r\n" is a problem... the easiest workaround for that problem is filling empty line from left to right margin with spaces... but as in your app a user can edit the files using the same richtextboxes it would be very difficult to differentiate between empty lines and actual spaces... so basically in that case you can create your own control which inherit from richtextbox or find good workaround for your app... you can for example provide user with checkbox and one more richtextbox for editing selected file...
btw if you will always leave the lines' numbers visible the problem will be very easily solved - for empty lines only the line numbers will be highlighted...

Szpilona 18 Light Poster

I feel a little bit like doing your homework but OK...
Some questions:
1. what exactly do you want to do? you just want to compare 2 files and show the differences? or you give users the possibility to change the text in the boxes and compare the text?
2. do you need some fancy text formating like changing the font color, shape or size?
3. if it comes to empty line highlighting - you have to highlight the whole line or it not really important - you can highlight half of the line as well?
I need more details... but if you really need all of sophisticated features of richtextbox it can be difficult to achieve...

Szpilona 18 Light Poster

To be honest I'm a little bit lost... I'm not sure what you're heading to... I only guess that you've got a file with data organized as follows:
string1,string2,double\n
string1,string2,double\n
...
string1,string2,double
then you've got a class conversioninfo which should hold infos from file and a list of its instances...
if so probably you want to do something like this:

public class conversionInfo
        {
            string name;
            string type;
            double version;

            public conversionInfo(string name, string type, double version)
            {
                this.name = name;
                this.type = type;
                this.version = version;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            LinkedList<conversionInfo> list = new LinkedList<conversionInfo>();
            string path = Environment.CurrentDirectory + "\\convert.txt";
            StreamReader reader = null;
            char[] delimiters = { ';' };

            if (!(File.Exists(path)))
            {
                MessageBox.Show("The file with data does not exist!");
                return;
            }

            try
            {
                reader = new StreamReader(path);
                string line = String.Empty;
                while ((line = reader.ReadLine()) != null)
                {
                    string[] tokens = line.Split(delimiters);
                    conversionInfo conInfo = new conversionInfo(tokens[0], tokens[1], Double.Parse(tokens[2]));
                    list.AddLast(conInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            // do something usefull with the list
        }
Szpilona 18 Light Poster

No line is highlighted... so I am not sure if you refer to the code proposed by me or to your modified version... But:
1. there's many ways to connect to the database but you have to choose one in any case and stick to it... so you open the connection using your own class:

DB db = new DB();
db.openConnection();
db.closeConnection();

or you do that in the way I proposed

using (SqlConnection connection = new SqlConnection(connectionString)) {}

or choose another possibility to do that but simply decide to something...
2. If you ask a question add all the information that can be useful to find the solution - in that case, as you mentioned that an error occurred, you could copy and paste the message...
if you referred to your version of the code certainly you are missing the closing bracket ")" in the end of the line... you typed:

using(SqlConnection connection = new SqlConnection(connectionsrting)

it should be:

#
using (SqlConnection connection = new SqlConnection(connectionString))

3. You do NOT have to close the connection to the database in the above example (at least if you will decide to stick to my version). As the connection is open in the using statement outside of the defined scope it will be disposed... (refer to MSDN documentation of using statement)...
4. I guess there's more errors in your code snippet but it is a little bit hard to process - correct it using above …

Szpilona 18 Light Poster

The fact that you create console app only change two things. Firstly you have to create a method to put in the code (you can also leave all of the code in the main() but in that way, probably, it will become very long - difficult to understand and to track errors).
Then you have to replace MessageBox.Show() with Console.WriteLine

MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

Console.WriteLine("An error occurred: " + ex.Message);

In the end of the Main() you can add Console.ReadLine() to see the results.
btw Environment.CurrentDirectory gets/sets the fully qualified path of the current WORKING directory so of the directory from which you start your app (so where the exe file is placed)... so if you use F5 or Ctrl+F5 in Visual to debug or start without debugging you refer to "...ProjectName\bin\Debug" (of course assuming you did not change anything from standard settings).

Szpilona 18 Light Poster

The exact solution (means an effective one) depends on what you want to do with the data.
Sample code:

private void button4_Click(object sender, EventArgs e)
        {
            LinkedList<string> list = new LinkedList<string>();
            // path to your file... in my example I placed the file in program directory
            string path = Environment.CurrentDirectory + "\\convert.txt";
            FileStream file = null;
            StreamReader reader = null;
            string fileContent = String.Empty;
            // that array consists of only 1 character as you have your data separated by commas
            char[] delimiters = { ',' };

            // here I read data from the file
            if (File.Exists(path))
            {
                file = new FileStream(path, FileMode.Open, FileAccess.Read);
            }
            else
            {
                MessageBox.Show("The file with data does not exist!");
                return;
            }
            try
            {
                reader = new StreamReader(file);
                fileContent = reader.ReadToEnd();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            // as you've got the fileContent you can split it into tokens (parts)
            string[] tokens = fileContent.Split(delimiters);
            // as the tokens array contains the needed parts you can add them to your list
            for (int i = 0; i < tokens.Length; i++)
            {
                list.AddLast(tokens[i]);
            }

            // do something usefull with the list
        }
Szpilona 18 Light Poster

You do not know the proper definition of that operator.
The syntax:
boolean_expression ? expression1 : expression2
Expression is any operation which returns a value. Void is not a value. Void specifies that no value is returned. If your get this message, at least one of your methods, must return void value. What is more you must in that context assign the value returned by the "?:" operator.
Proper usage of that operator:

private int m1(int a)
        {
            return a;
        }
        private int m2(int a)
        {
            return a + a;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int j = 0;
            for (int i = 0; i < 10; i++)
            {
                j = (i > 5) ? m1(i) : m2(i);
            }
        }

If you don't want to use a value returned by the operator - you just want to decide which method to execute, use if - else or switch - case expressions.

ddanbe commented: Well explained. +6
Szpilona 18 Light Poster

There's many ways to handle such a situation. Probably when a user log in you connect to the database to check his/her data. In that moment you can just add to the combobox his/her first name, last name and remember in variable his/her UserID (so the field which uniquely identify users). Then you can use a method like below:

private void FillComboBox(string connectionString, string loggedUserID)
        {
            string query = "select UserID, FirstName, LastName from DaniWeb.dbo.Users;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader sqlReader = command.ExecuteReader();
                try
                {
                    while (sqlReader.Read())
                    {
                        if (sqlReader[0].ToString() != loggedUserID)
                            comboBox2.Items.Add(sqlReader[1] + " " + sqlReader[2]);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    sqlReader.Close();
                }
            }
        }
Szpilona 18 Light Poster

Please, give some more details... What kind of app have you created, how have you created the installer, some information about the machine on which you created the app and about the machines on which you try to run the installer... Also if some messages pop up, what is their content...

Szpilona 18 Light Poster

That's very easy... All you have to do is to add a boolean variable which will remember the user's choice (you can use for example a combobox to give a user the chance to choice). Then according to that variable you add the line number or not.
Sample code:

private void button1_Click(object sender, EventArgs e)
        {
            string[] textFromRTB1 = richTextBox1.Lines;
            string[] textFromRTB2 = richTextBox2.Lines;
            richTextBox1.Clear();
            richTextBox2.Clear();
            int linesCount = 0;
            bool lineNumVisible;
            if (comboBox1.SelectedIndex == 0)
                lineNumVisible = true;
            else
                lineNumVisible = false;

            if (textFromRTB1.Length != textFromRTB2.Length)
            {
                linesCount = Math.Min(textFromRTB1.Length, textFromRTB2.Length);
                MessageBox.Show("Boxes have different number of lines.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
                linesCount = textFromRTB1.Length;

            bool checker = true;
            for (int i = 0; i < linesCount; i++)
            {
                checker = String.Equals(textFromRTB1[i], textFromRTB2[i]);

                if (!checker)
                {
                    richTextBox1.SelectionBackColor = Color.Red;
                    richTextBox2.SelectionBackColor = Color.Red;
                    if (lineNumVisible)
                    {
                        richTextBox1.SelectedText = (i + 1).ToString() + ".  " + textFromRTB1[i] + "\n";
                        richTextBox2.SelectedText = (i + 1).ToString() + ".  " + textFromRTB2[i] + "\n";
                    }
                    else
                    {
                        richTextBox1.SelectedText = textFromRTB1[i] + "\n";
                        richTextBox2.SelectedText = textFromRTB2[i] + "\n";
                    }
                }
                else
                {
                    richTextBox1.SelectionBackColor = Color.Green;
                    richTextBox2.SelectionBackColor = Color.Green;
                    if (lineNumVisible)
                    {
                        richTextBox1.SelectedText = (i + 1).ToString() + ".  " + textFromRTB1[i] + "\n";
                        richTextBox2.SelectedText = (i + 1).ToString() + ".  " + textFromRTB2[i] + "\n";
                    }
                    else
                    {
                        richTextBox1.SelectedText = textFromRTB1[i] + "\n";
                        richTextBox2.SelectedText = textFromRTB2[i] + "\n";
                    }
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // set the default value of the combobox
            comboBox1.SelectedIndex = 0;
        }

        private void btClear_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            richTextBox2.Clear();
            richTextBox1.SelectionBackColor = Color.White;
            richTextBox2.SelectionBackColor = Color.White;
        }
Szpilona 18 Light Poster

ListBox class does not support editing items in runtime (at least I do not know anything about it ;-P). So you have to handle yourself... As you want to give the user opportunity to change data after double clicking use DoubleClick event of the ListBox class and add in there the code. Depending on how you want a user to provide data to the app it will look differently.
Probably the simplest way to achieve what you want is to add TextBox control to the form. Then the DoubleClick event can look somehow like this:

private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            int selectedElement = listBox1.SelectedIndex;
            listBox1.Items[selectedElement] = editText.Text;
        }

To be more sophisticated you can hide the textbox and show it only when it will be needed.
Sample code:

public partial class Form1 : Form
    {
        private TextBox editText;
        private int selectedElement;

        public Form1()
        {
            InitializeComponent();
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            selectedElement = listBox1.SelectedIndex;
            editText.Show();
            editText.Focus();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            editText = new TextBox();
            editText.Location = new Point(10, 0);
            editText.Size = new Size(100, 20);
            editText.Text = "";
            editText.Hide();
            listBox1.Controls.Add(this.editText);
            editText.LostFocus += new System.EventHandler(this.FocusLost);
        }

        private void FocusLost(object sender, System.EventArgs e)
        {
            listBox1.Items[selectedElement] = editText.Text;
            editText.Text = "";
            editText.Hide();
        }
    }

Having that you have to just work on the specific location of the textbox when it shows and other less important details...

Szpilona 18 Light Poster

Well I would do that in completely different way... probably using regular expressions... but here's the way to count spaces in the provided text:

static public int spaces(string text)
        {
            char[] delimiters = { ' ' };
            text = text.Trim();
            string[] words = text.Split(delimiters);
            return words.Length - 1;
        }

hope it helps...

Szpilona 18 Light Poster

It may be a little bit vague but hope it will help you...

Firstly you created an instance of the Elephant class:

Elephant lloyd = new Elephant() { Name = "Lloyd", EarSize = 40 };

so the variable lloyd is now containing the reference to that object.
Then using:

lucinda.SpeakTo(lloyd, "Hello");

you passed the reference to lloyd.
SpeakTo function got the reference to lloyd. As the function is declared as follows:

public void SpeakTo(Elephant talkTo, string message)

locally talkTo refer to lloyd.
So, using:

talkTo.TellMe(message, this);

you refer to lloyd function TellMe.

Szpilona 18 Light Poster

I've got no time to give you more elaborate example but the following code should give you the idea what to do:

private void button1_Click(object sender, EventArgs e)
        {
            string[] textFromRTB1 = richTextBox1.Lines;
            string[] textFromRTB2 = richTextBox2.Lines;
            richTextBox1.Clear();
            richTextBox2.Clear();
            int linesCount = 0;

            if (textFromRTB1.Length != textFromRTB2.Length)
            {
                linesCount = Math.Min(textFromRTB1.Length, textFromRTB2.Length);
                MessageBox.Show("Boxes have different number of lines.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
                linesCount = textFromRTB1.Length;

            bool checker = true;
            for (int i = 0; i < linesCount; i++)
            {
                checker = String.Equals(textFromRTB1[i], textFromRTB2[i]);

                if (!checker)
                {
                    richTextBox1.SelectionBackColor = Color.Red;
                    richTextBox2.SelectionBackColor = Color.Red;
                    richTextBox1.SelectedText = textFromRTB1[i] + "\n";
                    richTextBox2.SelectedText = textFromRTB2[i] + "\n";
                }
                else
                {
                    richTextBox1.SelectionBackColor = Color.Green;
                    richTextBox2.SelectionBackColor = Color.Green;
                    richTextBox1.SelectedText = textFromRTB1[i] + "\n";
                    richTextBox2.SelectedText = textFromRTB2[i] + "\n";
                }
            }
        }

To do more sophisticated comparisons use regular expressions (class Regex and e.x. Match).
If you want to parse the text when it is written you can use TextChanged Event...

Szpilona 18 Light Poster

Well I don't know the class TSQLBeginTransactionBlock_Ext so I guess that's your own class. To make a deep copy of the Object in C# you should use Clone method from IClonable. You can also add a constructor to TSQLBeginTransactionBlock_Ext which takes as a parameter a variable of the same type as the class in which it is defined.
Simple example:

struct Point
    {
        private int x;
        private int y;

        public int X { get { return x; } set { x = value; } }
        public int Y { get { return y; } set { y = value; } }

        public Point(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }

    class Location
    {
        private Point position;
        private string locationName;

        public Location(string locationName, Point position)
        {
            this.locationName = locationName;
            this.position = position;
        }
        // makes deep copy
        public Location(Location prototype)
        {
            locationName = prototype.locationName;
            position = prototype.position;
        }

        public void ChangeLocation(int x, int y)
        {
            this.position.X = x;
            this.position.Y = y;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Point pkt = new Point(10, 20);
            Location loc = new Location("New York", pkt);
            Location deepCopy = new Location(loc);
            loc.ChangeLocation(30, 50);
            Console.ReadLine();
        }
    }
Szpilona 18 Light Poster

Read() method reads the next (only 1 character) from the standard input so you get ASCII codes of the number...
Try that instead:

nr1 = Convert.ToInt32(Console.ReadLine());

But put it into "try catch"...
btw make the fields private... and move temp declaration to InternGhange() function...
Sample code after little corrections:

class Numbers
    {
        private int nr1 = 0;
        private int nr2 = 0;
     
        public void GetNr1()
        {
            Console.WriteLine("Read nr1:");
            try
            {
                nr1 = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
            Console.ReadLine();
        }
        public void GetNr2()
        {
            Console.WriteLine("Read nr2:");
            try
            {
                nr2 = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
            Console.ReadLine();
        }
        public void InternGhange()
        {   
            int temp = nr1;
            nr1 = nr2;  
            nr2 = temp;
            Console.WriteLine("The numbers are now:");
            Console.ReadLine();
            Console.WriteLine("nr1={0}",nr1);
            Console.ReadLine(); 
            Console.WriteLine("nr2={0}",nr2);
        }
    }
ddanbe commented: Nice. +6
Szpilona 18 Light Poster

Sample code:

StreamReader sr = null;
            FileStream file = null;
            string fileData = String.Empty;

            try
            {
                file = new FileStream("test.txt", FileMode.Open, FileAccess.Read);
                sr = new StreamReader(file, Encoding.UTF8);
                string outputData = String.Empty;
                while (true)
                {
                    string temp = String.Empty;
                    temp = sr.ReadLine();
                    if (temp != null)
                    {
                        temp = temp.Replace("the", "THE");
                        outputData += temp + "\n";
                    }
                    else
                        break;
                }
                Console.WriteLine("OUTPUT:\n{0}", outputData);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
            finally
            {
                if (sr != null)
                    sr.Close();
                if (file != null)
                    file.Close();
            }
            Console.ReadLine();

You can also use the method ReadToEnd to read everything to one string and then use String.Replace method.
Depending on what you want to do you can also consider using regular expressions.

Szpilona 18 Light Poster

Hi,

I've created a lexer using flex. Now I want this lexer to be used in my C# application. I've tried to do this with code below:

private void btParse_Click(object sender, EventArgs e)
        {
            Process lex = new Process();
            StreamWriter sIn = null;
            StreamReader sOut = null;
            StreamReader fileReader = null;

            try
            {
                lex.StartInfo.UseShellExecute = false;
                lex.StartInfo.FileName = tbLexerName.Text.Trim();
                lex.StartInfo.RedirectStandardInput = true;
                lex.StartInfo.RedirectStandardOutput = true;
                lex.StartInfo.CreateNoWindow = true;

                lex.Start();

                sIn = lex.StandardInput;
                sOut = lex.StandardOutput;

                fileReader = new StreamReader(".\\" + tbInputFile.Text.Trim(), Encoding.UTF8);
                sIn.WriteLine(fileReader.ReadToEnd());
                fileReader.Close();
                sIn.Close();

                tbOutput.Text = sOut.ReadToEnd();
                sOut.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (sIn != null)
                    sIn.Close();
                if (sOut != null)
                    sOut.Close();
                if (fileReader != null)
                    fileReader.Close();
                lex.Close();
            }
        }

It works fine until the response from the lexer getting bigger than about 20KB. NO exception is thrown it just gets stuck. Lexer, not executed from the app, even with much bigger files works great, very fast. Any idea how to handle this?

Thanks in advance,
Szpilona

Szpilona 18 Light Poster

Hi,

I've got a lexer created with flex (under cygwin). Normally I compile it to an .exe file.

For the newest project I need a lexer to use in a bigger C# program running on Windows XP. Of course I can execute a file using System.Diagnostics.Process. But it is not the best solution for me as I want that program to run on several machines.

How can I create a dll having the source code of the lexer?

I've already tried to run flex on my grammar and then compile the obtained c file with:

gcc -c lekser.c 
gcc -shared -o lekser.dll lekser.o

Dll file was created but it does not work. I've tried to access the library using the code:

[DllImport("lekser.dll")] public static extern int yylex();

but the DllNotFoundException occured. The file, for sure, is placed in the right directory and the C# code is correct (at least it works with another dll I've created to test this).

Thanks in advance...
Szpilona