DdoubleD 315 Posting Shark
string x;
x = console.readline();
if (x == "Hello");

it says you can't compare strings.
Hmmm, I thought you could do the "==", but anyway:

private static string CompareStrings(string str1, string str2)
   {

      // compare the values, using the CompareTo method on the first string
      int cmpVal = str1.CompareTo(str2);

      if (cmpVal == 0) // the values are the same
         return "The strings have the same value!";

      else if (cmpVal > 0) // the first value is greater than the second value
         return "The first string is greater than the second string!";

      else // the second string is greater than the first string
         return "The second string is greater than the first string!";
   }
DdoubleD 315 Posting Shark

Hi,

Look I'm new to C# and I have a working knowledge of VB .Net. I would like to learn C# but I'm having a problem. It's probably a basic problem but, for a console program how to I check what someone has typed in so that the console can respond with a Writeline statement?

If they are typing a line:

string s = Console.ReadLine();
            Console.WriteLine(s);
DdoubleD 315 Posting Shark

// inside PrintDocument or parent...

s/b // inside PrintDocument child class or you could place code in dialog class; whereever the pd_PrintPage event method resides.

Does this make sense?

DdoubleD 315 Posting Shark

For example:

// called when the user selects "Print"
        private void genPrint(object sender, EventArgs e)
        {
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
            printDialog1.Document = pd;
            DialogResult result = printDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                pd.LoadPrintBody();
                pd.Print();
            }
        }

        // inside PrintDocument or parent...
        string[] pBody;
        int lastLinePrinted;
        
        // inside PrintDocument or parent...
        public void LoadPrintBody()
        {
            pBody = rtbReport.Text.Split('\n');
            lastLinePrinted = 0;
        }

        private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            //string[] pBody = rtbReport.Text.Split('\n');

            Font printFont = new Font("Courier New", 10);
            float maxLines = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
            float top = ev.MarginBounds.Top;
            float left = ev.MarginBounds.Left;

            // began where left off
            int i = lastLinePrinted + 1;

            for (; i < pBody.Length && i < maxLines; i++)
            {
                float yPos = top + (i * printFont.GetHeight(ev.Graphics));
                ev.Graphics.DrawString(pBody[i], printFont, Brushes.Black, left, yPos);
            }
            if (i < pBody.Length)
            {
                lastLinePrinted = i - 1;
                ev.HasMorePages = true;
            }
            else
                ev.HasMorePages = false;
        }
DdoubleD 315 Posting Shark

You are right about the check on maxLines (I had it backwards).

Can you assign body[] outside of pd_PrintPage? Then retain the lastline printed for each call to pd_PrintPage and pick up where it left off when you make the next call (triggered by ev.HasMorePages)?

DdoubleD 315 Posting Shark

Can you redraw the panel to cover up the broken lines, before you draw your new border?

DdoubleD 315 Posting Shark
FileStream fStream = newFileStream (strPath,FileMode.Append);
fStream.Close();
StreamWriter sWriter = newStreamWriter(strPath);
sWriter.Write(strBuilder);
sWriter.Close();
FileStream fStream = newFileStream (strPath,FileMode.Append);
//fStream.Close();
//StreamWriter sWriter = newStreamWriter(strPath);
StreamWriter = new StreamWriter(fStream);
sWriter.Write(strBuilder);
sWriter.Flush();
sWriter.Close();

The changes should fix your append at least. Not sure if you are even getting it to compile though.

DdoubleD 315 Posting Shark

Try Google'ing: Search Results

DdoubleD 315 Posting Shark

This error message is not very informative, I wish I had a better description of the message.

I guess this is one of those generic catch-all error messages. After some browsing, I've noticed that other applications have somehow hooked into more detailed information related to this error. Does the database or event logs hold details to these error events?

Anyway, wish I could help you more but I don't know your DB, Tables, etc., and there are too many possibilities of what is actually generating this error. Good luck.

DdoubleD 315 Posting Shark

Also, anything other than 0x00000000 in the boolean address would probably be translated true, though I haven't tested that.

DdoubleD 315 Posting Shark

Trick question? In the active code lines, you are overwriting the first byte of your char "theChar", which is two bytes (Unicode) in length, when you assign to your bool "theBool", which is one byte in length; because you have aligned both fields on the first byte ([FieldOffset(0)]) in your structure.

And they said you couldn't do unions in C#. Just don't expect any language support for bitwise manipulation.:icon_smile:

DdoubleD 315 Posting Shark

The libraries (IBMDADB2, DLL's, etc) being access for you database from these calls might be out of sync. Which line (DB call) is throwing the error?

Maybe the OLE DB Provider (IBMDADB2) is not properly registered? You might contact IBM support for this driver and see what they have to say about your error.

DdoubleD 315 Posting Shark

It looks to me like your: string[] pBody = rtbReport.Text.Split('\n') ;
assignment inside of the print page won't work. Don't you need to check for maxlines, return, then reassign pBody where you left off, then allow the print page event to continue?

If you made that adjustment, then this seems logical:

int i = 0;
            for (; i < pBody.Length && i < maxLines; i++) // for each line?
            { 
                float yPos = top + (i * printFont.GetHeight(ev.Graphics));// calc start line
                ev.Graphics.DrawString(pBody[i], printFont, Brushes.Black, left, yPos); // print line
            }
            if (i >= maxLines)
                ev.HasMorePages = false;
            else
                ex.HasMorePages = true;
DdoubleD 315 Posting Shark

It looks to me like your: string[] pBody = rtbReport.Text.Split('\n') ;
assignment inside of the print page won't work. Don't you need to check for maxlines, return, then reassign pBody where you left off, then allow the print page event to continue?

DdoubleD 315 Posting Shark

OK. Instead of initializing "date" outside the loop, restore it inside the loop, but use the Convert.ToDateTime. This is the value from each record we want to compare to to see if it is a min or max value.

Instead of initializing Start and EndDate inside the loop, move those outside the loop (where you have "date" currently): set your StartDate to a very high value; and your EndDate to a very low value.

This should fix it--let me know.

ddanbe commented: Good explanation. +8
DdoubleD 315 Posting Shark

Can you give that to me in c#

Give it a shot yourself in your loop. Then I will help you with questions. Be sure to post your new code.

DdoubleD 315 Posting Shark

If your date strings are formatted correctly for string comparisons, you can just initialize them and do a comparison for min and max for each row in your loop (pseudocode):

if minDate = "" or minDate > date then
    minDate = date;
if maxDate = "" or maxDate < date then
    maxDate = date;
arelius commented: He was execellent at helping me out and solving the probelm I had. Very reliable as well. +1
DdoubleD 315 Posting Shark

or, copy rows explicitly:

//
        // Summary:
        //     Copies all rows from the supplied System.Data.DataRow array to a destination
        //     table specified by the System.Data.SqlClient.SqlBulkCopy.DestinationTableName
        //     property of the System.Data.SqlClient.SqlBulkCopy object.
        //
        // Parameters:
        //   rows:
        //     An array of System.Data.DataRow objects that will be copied to the destination
        //     table.
        public void WriteToServer(DataRow[] rows);
DdoubleD 315 Posting Shark

I don't see where you are actually copying the rows, but to limit them to only the first four, you set the rowState to indicate it should be copied:

//
        // Summary:
        //     Copies only rows that match the supplied row state in the supplied System.Data.DataTable
        //     to a destination table specified by the System.Data.SqlClient.SqlBulkCopy.DestinationTableName
        //     property of the System.Data.SqlClient.SqlBulkCopy object.
        //
        // Parameters:
        //   table:
        //     A System.Data.DataTable whose rows will be copied to the destination table.
        //
        //   rowState:
        //     A value from the System.Data.DataRowState enumeration. Only rows matching
        //     the row state are copied to the destination.
        public void WriteToServer(DataTable table, DataRowState rowState);

If you want to limit it to only rows without NULL values, I suppose you could set that up in the rowState before calling the WriteToServer method.

DdoubleD 315 Posting Shark

You need to determine whether there are still more pages to print and set HasMorePages = true. Following EXAMPLE is from MSDN:

// The PrintPage event is raised for each page to be printed.
   private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
   {
      float linesPerPage = 0;
      float yPos = 0;
      int count = 0;
      float leftMargin = ev.MarginBounds.Left;
      float topMargin = ev.MarginBounds.Top;
      string line = null;

      // Calculate the number of lines per page.
      linesPerPage = ev.MarginBounds.Height / 
         printFont.GetHeight(ev.Graphics);

      // Print each line of the file.
      while(count < linesPerPage && 
         ((line=streamToPrint.ReadLine()) != null)) 
      {
         yPos = topMargin + (count * 
            printFont.GetHeight(ev.Graphics));
         ev.Graphics.DrawString(line, printFont, Brushes.Black, 
            leftMargin, yPos, new StringFormat());
         count++;
      }

      // If more lines exist, print another page.
      if(line != null)
         ev.HasMorePages = true;
      else
         ev.HasMorePages = false;
   }
DdoubleD 315 Posting Shark

Check out these ListView methods:

public ListView.SelectedListViewItemCollection SelectedItems { get; }
//or
        public ListView.SelectedIndexCollection SelectedIndices { get; }

//with
        public bool ListViewItem.Checked { get; set; }
DdoubleD 315 Posting Shark
private void frmAddress_Load(object sender, System.EventArgs e)
        {
            String[] firstName = { "Julie", "Tony", "Frederick", "Betty", "Paul", "David", "Heather" };
            String[] lastName = { "Ostendoft", "Bush", "Slater", "Gardner", "Rivers", "Lee", "Small" };
            String[] address = { "123 Fort St.", "456 Comp St.", "789 Blue Ave", "3452 Missouri Rd.", "43418 Old River Rd.", "457 Addy Ct.", "4233 Harvey St." };
            String[] city = { "Baltimore", "Dallas", "Fort Worth", "Owings Mills", "Miami", "Colorado Springs", "Los Angeles" };
            String[] state = { "Maryland", "Texas", "Texas", "Maryland", "Florida", "Colorado", "California" };
            String[] zipCode = { "21234", "12345", "67890", "32345", "43418", "31241", "31489", "83974" };

            StreamReader iFile = new StreamReader("Address.txt");
            StreamWriter oFile = new StreamWriter("Address2.txt");
            for (int i = 0; i < lastName.Length; i++)

                oFile.Write(String.Format((lastName[i] + "," + lastName[i] + "\n" + address[i] + "\n" +
                    city[i] + "\n" + state[i] + "\n" + zipCode[i])));
            oFile.Close();
            oFile.Close();
        }


1) You are never reading from your input file--you have hard coded the information.
2) You are writing your lastname field twice
3) You are closing your output file twice, but never you input file.

Regarding you other question about whether you should have a delimiter after every line: not necessary because the EOL <CR/LF> is your delimiter separating the fields as far as I can tell.

DdoubleD 315 Posting Shark

You would think that MS would have added all of this Parsing to Volume/Path/Filename class by now, but I guess they don't want to piss off some of their partner's value added resales of libraries or something. Anyway, I would resort to searching existing code available at CodeProject or something. This stuff is like reinventing the wheel many times over in its fundamental IO statistics/demographics/structure.
Anyway, here is what I got from a relative path for your volume info request using "..\*.*":

Console.WriteLine(Directory.GetDirectoryRoot(args[0])); // returns volume as "C:\"

good luck.

DdoubleD 315 Posting Shark

Use StreamWriter.

WAIT!!! Are you trying to read or write? -- LOL

DdoubleD 315 Posting Shark

Use StreamWriter.

DdoubleD 315 Posting Shark

OK. You are in over your head on this I think. So, let's take this a step at a time and see if you can accelerate your understanding of compiler errors and how to reference/interpret the meaning:

Error 4 No overload for method 'Add' takes '0' arguments

private void btnAdd_Click(object sender, System.EventArgs e)
        {
            this.lstBoxDisplay.Items.Add();
        }

This is telling you that the Add() method you are calling requires parameter(s). In other words, you need to give it something to add:

private void btnAdd_Click(object sender, System.EventArgs e)
        {
            string apples = "apples";
            string oranges = "oranges";
            this.lstBoxDisplay.Items.Add(apples);
            this.lstBoxDisplay.Items.Add(oranges);
        }

Above will add two items: apples and oranges.

Given you are working with a contact list, you items will be different. Also, they don't have to be strings. However, to display properly in your list box, the ToString() method will need to return the appropriate string representation--done automatically above because apples and oranges are both declared string objects.

Here is the best part: If you are using Visual Studio, you can right click on a method (like Add()), and select go to definition, which will tell you how the method expects to be called. Also, if you press F1 while in the Error list, hopefully (doesn't always work), it will take you to the help for this error.

I feel you might be in over your head on this. Play around with the environment given this information and become more comfortable in understanding the tools you …

DdoubleD 315 Posting Shark

Oh... where to start... Since you do nothing in the Load event, I assume you press a button or something that causes your first noticeable error? Regardless, let's start with your first noticeable error--where does this happen?

DdoubleD 315 Posting Shark

Here it is:

string path = Path.GetDirectoryName(args[0]);
            string filespec = Path.GetFileName(args[0]);

            Console.WriteLine("Path: " + path);
            Console.WriteLine("Filespec: " + filespec);
            Console.Read();

Tested with "C:\*.*" on command line.
I assume you know how to check args and substitute current directory with *.* if the user does not supply args?

DdoubleD 315 Posting Shark

1) The problems I have with this solution, however, is that it feels strange to have to add the space between the path and the filename.. I'm sure there is some method out there to parse out the information if a single string is given.

2) Also, this would not work if args[] has a 0 length, because the args[0] would be at best null, or "", and either one would cause the program to fail. I've tested this by using both DirectoryInfo currentDir = new DirectoryInfo(); and DirectoryInfo currentDir = new DirectoryInfo(""); .

3) Also... args[0] may not be the specific location of my path in every case. I eventually want to be able to parse other parameters out of the string. But that is another issue to be dealt with.

1) It appeared you wanted to utilize two params--sorry. You are correct that you can parse the filename out of the path.
2) True--that's why I told you to not exceed Length...
3) too many unknowns...

I will attempt to help you with your parse in item 1, to utilize only one parameter in args. BRB

DdoubleD 315 Posting Shark

In that , if i enter words without spaces like"tenthousand" or "minus ten thousand" , its giving zero......
i want that in first case it should give message as"enter words with proper spacing" and in second case it should give "-10000".....

What can i do for this

I am fresh out of tea leaves, but here is a couple of suggestions:
1) instead of trying to determine the user left out a space, just report the string that could not be understood and give them a list of reasons why it might have happened:
...possibly because:
- missing space between words
- ...(another reason),
- etc.
...proper usage is: "..." -- tell the user how to use it and give good examples, and, perhaps, some invalid entries for examples of what not to input.
2) If you are able to translate 10000, then you can probably figure out that you just need to add "minus" to your search/hash table if you really want to allow the usage of the word "minus" for -10000; otherwise, resort to suggestion 1 as a catchall--recommended.

DdoubleD 315 Posting Shark

No problem--glad it worked for you. Please mark this thread as resolved.

DdoubleD 315 Posting Shark

LOL... I think you might be asking multiple questions here, so let's start with the first:

okay, basically i want a completely different and random range of numbers everytime i make a Random instance.

Here is an answer:

// Ensure our numbers are indeed random
            // Passing in the Millisecond is known as "seeding"; without seeding, each instance would probably produce the same result
            Random hit1 = new Random(DateTime.Now.Millisecond);
            System.Threading.Thread.Sleep(5);// 5 milliseconds just in case
            Random hit2 = new Random(DateTime.Now.Millisecond);

            // both of these will produce two different random numbers in range 50 - 99
            int num1 = hit1.Next(50, 100);
            int num2 = hit2.Next(50, 100);

Now, is there another question?

DdoubleD 315 Posting Shark

Here is the code you posted with the changes. I just tested it passing in "c:\ *.*" and it worked find--again, note the space between the arguments. You will want to ensure you don't access "args" outside it's Length, or you will get an exception.

static void Main(string[] args)
        {
            foreach (string s in args)
                Console.WriteLine("arg: " + s);
            Console.Read();

            DirectoryInfo currentDir = new DirectoryInfo(args[0]);// (Environment.CurrentDirectory);

            DirectoryInfo[] dirList = currentDir.GetDirectories();
            FileInfo[] fileList = currentDir.GetFiles(args[1]);//();

            foreach (DirectoryInfo dir in dirList)
                Console.WriteLine("Directory: {0}", dir);
            foreach (FileInfo file in fileList)
                Console.WriteLine("File: {0}", file);
        }
DdoubleD 315 Posting Shark

Second part, with filename search spec:

FileInfo[] fileList = currentDir.GetFiles(args[1]);//();

I tested this using "app.exe ..\..\ *.csproj". Note the space between "..\..\" and "*.csproj".

DdoubleD 315 Posting Shark

Here is an example of a feed from the command line. I tested with "app.exe ..\..\" from the command line and it worked:

DirectoryInfo currentDir = new DirectoryInfo(args[0]);// (Environment.CurrentDirectory);
DdoubleD 315 Posting Shark

Gah: I'm having trouble following this thread. Based on the original code you submitted, what is the line of code you want to modify and from what?

You can leave out all the "game" details and just tell me the number(s) you need and show me the line(s) please (just the logic in other words).

DdoubleD 315 Posting Shark

Reposting method: I don't know why the tags didn't display the code properly. If this fixes your problem, please flag as Solved--thanx.

public static TreeNode FindTreeNodeText(TreeNodeCollection nodes, string findText)
        {
            TreeNode foundNode = null;
            for (int i = 0; i < nodes.Count && foundNode == null; i++)
            {
                if (nodes[i].Text == findText)
                {
                    foundNode = nodes[i];
                    break;
                }
                if (nodes[i].Nodes.Count > 0)
                    foundNode = FindTreeNodeText(nodes[i].Nodes, findText);
            }
            return foundNode;
        }
DdoubleD 315 Posting Shark

Hai,
@DangerDev
I get a input from the user and based on this input there will be corresponding node in my tree view(Can be at any level inside the treeview),and I will know only its name .Have to find this node and append my child node to it..
Where I add my child Node depends on the user and has to be done at runtime..
Hope this Helps..

If you are searching on the TreeNode text, you can use the following recursion:

    public static TreeNode FindTreeNodeText(TreeNodeCollection nodes, string findText)
    {
        TreeNode foundNode = null;
        for (int i = 0; i < nodes.Count && foundNode == null; i++)
        {
            if (nodes[i].Text == findText)
            {
                foundNode = nodes[i];
                break;
            }
            if (nodes[i].Nodes.Count > 0)
                foundNode = FindTreeNodeText(nodes[i].Nodes, findText);
        }
        return foundNode;
    }

The node collection is the TreeView's Nodes (tv.Nodes). If found, you simply foundNode.Add(new TreeNode());

DdoubleD 315 Posting Shark

Hai,
Thanks for the Quick response..
If I do TreeView's TreeNodeCollection Find method it will return me a treenodecollection and any changes I do will not be reflected in the actula treeview.Please correct me if I am wrong..

It will return a reference to the node collection, so your changes will apply.

DdoubleD 315 Posting Shark

If you are not actually using the TreeNode.Name (was unclear), you will need to use recursion on the TreeNode.Text. Let me know if you need help with that.

DdoubleD 315 Posting Shark

Hello,

I have a treeview control and want to add a node to it at a desired location or as the child of a Certain Node X.The problem is I will know nodename[or the Text displayed ] of X only at runtime.

How do I Iterate the tree to find the given Node and add a child to it ??

Do I have to write a recursive function that iterates the nodes of a tree,find the given node and add a child to it OR is there an easier way to do this..

Use the TreeView's TreeNodeCollection Find method:
public TreeNode[] Find(string key, bool searchAllChildren);

Then, peruse the returned array for your specific node and Add your new node.

DdoubleD 315 Posting Shark

i could not understand the logic ,then how can i start............

Start by providing a portion of code logic that you don't understand and we will try to explain so you will understand it.

DdoubleD 315 Posting Shark

Hi!!!!
Example we enter "One crore twenty lakh thirty four thousand seven hundred eighty four" ,
then its corresponding numeral should be "12034784".

This looks familiar. See: http://www.daniweb.com/forums/thread209656.html

DdoubleD 315 Posting Shark

Did you check to see if the report design (.rpt file) is using the option to "save data with report?" The reason I ask is because when this option is used it might be also maintaining the original path to the DB connection; and even though you are supplying an alternate path in your connection string, the report might be trying to validate the path to the data stored with the report. Does this make sense?

DdoubleD 315 Posting Shark

thanks 4 ur rply, but
i m making a window application not web application.
there is no connection to the web.
plz tell me answer with respect to a window application....

So, not in a web browser, but a file parser? And if I read your other post correctly, you want to parse .NET Forms? For what exactly?

DdoubleD 315 Posting Shark

Yes, correct. Another way you could do it is to:

Main main = new Main();
//set value here
if (main.User = "Admin")
    main.btnAdmin.Enabled = true;
else
    main.btnAdmin.Enabled = false;
main.Show();

You would of course need to make the button public to do it this way, and I don't suggest it, just pointing out yet another fix.

DdoubleD 315 Posting Shark

Ok, I understand. I thought I was setting the variable before the Main() constructor occurred. If I move the code that sets the variable inside the Main() constructor, before the IF statement, will that work?

Thanks.

No, you cannot just move code inside the Main() constructor; unless, you pass in the user var into the Main constructor: e.g. Main(string user), which will allow the "if" block to see the current value. Does that make sense?

DdoubleD 315 Posting Shark

Here is the modification:

public Main()
        {
            InitializeComponent();

            //String admin = "Admin"; // not being used?
            this.Load += new System.EventHandler(this.Main_Load);
        }
        private void Main_Load(object sender, EventArgs e)
        {
            if ("Admin" == user)

                btnAdmin.Enabled = true;

            else

                btnAdmin.Enabled = false;
        }
Rhuntsman21 commented: Thanks for the help. +1
DdoubleD 315 Posting Shark

SUGGESTION/SOLUTION: Move the "if' block to check for "Admin" to the form's Load event, which will be called after your call to Show(), allowing the variable to have been set in between. Does this make sense to you?

DdoubleD 315 Posting Shark

Here is the problem: you are setting the button.Enabled property in the Main() constructor. However, you are setting the value of user after you instantiate the Main form, which means the button's if statement has already been evaluated before the User variable gets set to "Admin".