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".

DdoubleD 315 Posting Shark

Using the name "Main" for your form: I highly recommend you change this name to be something else that is more meaningful. Only because Main() is a reserved entry point symbol to the execution of an application and it is confusing (though I admit I didn't know you could do what you have done anyway).

DdoubleD 315 Posting Shark

Does it make a difference if I am just hiding the parent form? I am not actually destroying, am I?

What you say is true. Are you resetting the variable to the form's data as suggested?: user = main.user

What I don't understand is what the form is capable of doing since you are hiding it immediately after a modeless call to the Show() method, which prevents any user interaction with the form. e.g.

main.Show();
main.Hide();
DdoubleD 315 Posting Shark

This is a little weird how you are doing this--no big deal though. Can you paste the entire code or zip it up and attach as Serkan suggested?

DdoubleD 315 Posting Shark

GUESS: If you passing in the variable in the constructor, this won't work because the reference will be reset. After your call to ShowDialog(), reset your variable's content before the Form object is destroyed, e.g.:

frm.ShowDialog();
user = frm.user;
DdoubleD 315 Posting Shark

I am setting the variable on another form and passing it over. I know it is passing it because I tested it.

Show the line of code you are using to pass the variable to the form.

DdoubleD 315 Posting Shark

You have defined a List containing type Monster, but you have not created any items for the list using the "new" operator. Thus, any attempt to access an element of the array (List) will cause an error.

Try using the Add(Monster) method to add the items to your list, then define monster:

monsterList.Add(new Monster());
monsterList[0].CreateMonster(...);
DdoubleD 315 Posting Shark

My guess is you are never actually setting the variable "user" or User property. Where is the code that assigns the TextBox value? e.g.

User = textBox1.Text;

Also, you probably want to rewrite your if statement to be:

if (User == admin)

instead of using the literal "Admin", since you already assigned it to variable 'admin', which is never used in this example.

DdoubleD 315 Posting Shark

QUESTIONS:
1) Where/when are you executing this code?
2) Where/how are you setting the value of the string "user"?
3) Can you include the whole code text?

kvprajapati commented: Good questions. +10
DdoubleD 315 Posting Shark

I see DoubleD's suggestion of the the caret Index or just creating a single custom control to accomplish it all to be the only two viable options so far to accomplish this.

Unfortunately, I lied about the CaretIndex property.:icon_redface:
That exists only for .ASPX code, which also uses C#--don't ask me why they didn't extend the functionality.

Anyway, here are a couple of methods that should accomplish the manipulation you described:

static int GetCaretPos(TextBox tbx)
        {
            return tbx.SelectionStart; // current position (won't work for you if user has selected some text)
        }
        static void SelectCharAtPos(TextBox tbx, int pos)
        {
            tbx.Select(pos, 1); // select one char beginning at pos
        }

However, you are really opening a can of worms when you begin to implement the behavior you described because: What happens if the user tries to select any portion of the text manually?--etc. I used to create controls to do funky stuff for clients years ago in WinAPI, which I could probably dig up, but do you really want to go to all this trouble?

DdoubleD 315 Posting Shark

A better way that captures what I said in a finally block, but, ideally, you would also put both your Stream creations inside of a try block themselves or ensure the caller is doing so.

public static void DoStreamReader()
        {
            StreamReader iFile = new StreamReader("Input.txt");
            StreamWriter oFile = new StreamWriter("output.txt");

            int totalScore = 0;
            int scoreCount = 0;
            decimal averageTestScore;



            if (File.Exists("input.txt"))
                try
                {
                    while (iFile.Peek() > 0)
                    {
                        totalScore = totalScore + Convert.ToInt32(iFile.ReadLine());
                        scoreCount++;
                    }
                    averageTestScore = totalScore / scoreCount;
                    oFile.Write(String.Format("The average of these scores is: {0}", averageTestScore));

                }

                catch (System.IO.IOException exc)
                {
                    //lblOutput.Text = exc.Message;
                }
                finally
                {
                    iFile.Close();
                    oFile.Flush(); // flush memory to your output file
                    oFile.Close(); // close your output file
                }
        }
DdoubleD 315 Posting Shark

Here are the changes I made for my test that worked:

public static void DoStreamReader()
        {
            StreamReader iFile = new StreamReader("Input.txt");

            int totalScore = 0;
            int scoreCount = 0;
            decimal averageTestScore;



            if (File.Exists("input.txt"))
                try
                {
                    while (iFile.Peek() > 0)
                    {
                        totalScore = totalScore + Convert.ToInt32(iFile.ReadLine());
                        scoreCount++;
                    }
                    averageTestScore = totalScore / scoreCount;
                    StreamWriter oFile = new StreamWriter("output.txt");
                    oFile.Write(String.Format("The average of these scores is: {0}", averageTestScore));
                    oFile.Flush(); // flush memory to your output file
                    oFile.Close(); // close your output file

                }

                catch (System.IO.IOException exc)
                {
                    //lblOutput.Text = exc.Message;
                }
                finally
                {
                    iFile.Close();
                }
        }
DdoubleD 315 Posting Shark

SUGGESTION: Remove the reference to the complete path and just use the filename. This way, you can move the exe and the input.txt file anywhere and it will run.

NEVERMIND: I see you already edited the code to do this.

DdoubleD 315 Posting Shark

If you make those changes, I just ran a test and it was successful--good luck.

DdoubleD 315 Posting Shark

Duh(me)!
Leave your iFile.Close(), but add oFile.Flush and oFile.Close()

This means you will have to either move the instantiation of the oFile object outside of the try block, or simply add the calls after your oFile.Write statement.

DdoubleD 315 Posting Shark

QUESTIONS:
1) What does the input file data look like?
2) Is it throwing an IOException?

COMMENT: I would put iFile.Flush(); call prior to the iFile.Close(); in your "finally" block to ensure the memory buffer is flushed to the file.

DdoubleD 315 Posting Shark

true and i agree with you but if he needs to create it it wouldn't already exist lol

Yea, I fired that one off a little quick and didn't notice the Read-Only attribute condition at first. I've never seen that static method before and I was afraid at first if the program was run more than once since there are no Open mode flags being passed in.

I like to toss message boxes in to check variables to be sure the correct output is coming during testing.

Not sure if you've seen this, but there is also an output window method you can use while in the debugger to output information, which you can go back and evaluate during execution and after exiting as well: System.Diagnostics.Debug.Write... methods.

DdoubleD 315 Posting Shark

If you pursue your customized editing (overwrite mode with char highlighting of caret position), you will need to manipulate how the control functions by checking the cursor/caret position.

You can use the TextBox.CaretIndex property to determine and set position.

You can use the TextBox.Select method to highlight/select the character at the current position.

Most programmers would create a custom control to do all of the things you are trying to achieve, but this sounds like a homework assignment you have decided to enhance even further. If so, kudos for your curiosity and extra effort!

DdoubleD 315 Posting Shark

WriteAllLines will fail if the file already exists and is Read-Only:

The following conditions may cause an exception:
* The file exists and is read-only.
* The path name may be too long.
* The disk may be full.

You should be sure you put into a try-catch block at least.

DdoubleD 315 Posting Shark

Check out the String.Length property to see how you can determine the number of characters already entered, then see if you can figure out where to put it in the code I gave you to prevent more than 16 being entered--good luck.

DdoubleD 315 Posting Shark

If you attach (wire) the following key events to your control, it will limit the chars to uppercase A thru P. You can also modify this code to convert lower chars to upper if you wish.

// uses boolean set in KeyDown event to determine whether this was an allowed character pressed
        private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Check for the flag being set in the KeyDown event.
            if (!charAllowed)
            {
                // Stop the character from being entered into the control
                e.Handled = true;
            }
            else if (e.KeyChar < 'A' || e.KeyChar > 'P')
                e.Handled = true;
        }

        // Used to set flag to stop specific charactrs from entry into our control
        // Works in conjunction our KeyPress event handler.
        private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            // Initialize the flag.
            charAllowed = true;

            // Determine whether the keystroke is allowed
            // Exclude those with the following modifiers
            if (Control.ModifierKeys == Keys.Control ||
                Control.ModifierKeys == Keys.Alt)
            {
                charAllowed = false;
            }
        }
DdoubleD 315 Posting Shark

Hi, I have a class object that I have created a DataSource on.
e.g.:

public class TestDataSource
{
    string fld1;

    public string Field1
    {
        get { return fld1; }
        set { fld1 = value; }
    }
}

When the DataSource object is created via the wizard, it will create a TextBox for "Field1", by default, that can then be dragged onto a form. Above example is only a working example, because I use many more defined fields.

One of the fields is intended to be a read only HTML Link that it is autogenerated/parsed from the text of another field. This is how I would like it to be displayed and function--to function like a LinkLabel control.

Problem or goal is that I would like to either:
1) customize the property of the Field1 to force the DataSource created by the wizard to be LinkLabel; or,
2) modify the field's default TextBox control to act similar to a LinkLabel without recreating the control; or,
3) if I must recreate the control as a LinkLabel control, determine how I would restore the binding it already has (as a TextBox) with my BindingSource object

Your help is appreciated--thanks!

DdoubleD 315 Posting Shark

How do you intend to use the search engine?

DdoubleD 315 Posting Shark

Try Listbox.FindString to lookup the typed text, then use the returned index to set ListBox.TopIndex = index, which will make those items beginning with your typed text appear at the top of the listbox.

DdoubleD 315 Posting Shark

Do you have a line of code where the exception is occurring to show everyone?

DdoubleD 315 Posting Shark

Don't know that much about it, but I ran across this article on sending facebook and twitter messages a few weeks ago. Maybe it will get you closer to your goal: http://www.dreamincode.net/iem/display.php?M=327187&C=8e0d5b7e5d902fedbacaeaf6e3b4fa46&S=21&L=1&N=8

DdoubleD 315 Posting Shark

That is a little more tricky, but not too much. Here is a code snippet written in Python that should give you the general idea. If you don't know Python (I don't), the syntax is similar enough I think you will understand it: http://stackoverflow.com/questions/493174/is-there-a-way-to-convert-number-words-to-integers-python

DdoubleD 315 Posting Shark

Some things to check:
1) using subreports pointing to datasource with invalid path
2) are you saving data with report? this used to cause a variety of problems and although it might not be the exact cause, you might get different results if you change this option
3) are the schemas exactly the same for each of the datasource locations?

DdoubleD 315 Posting Shark

Here is an interesting article that allows you to code your own using mixed-language: http://www.blackwasp.co.uk/NumberToWords.aspx

DdoubleD 315 Posting Shark

It's been years since I worked with CRPE, but I believe you need to create a text field with a formula that uses an expression, such as:

if (pmtType == 0)
    text = "Cheque";
else // or, else if
    text = "Cash";
DdoubleD 315 Posting Shark

It's hard to determine exactly what/how you are trying to achieve this. If you have a handle to the thread, you could have it Sleep() in a loop until you are ready for it to resume processing:

bool suspend = true;//  set to false to continue processing
void SuspendRun ()
{
    suspend = true;
    while (suspend)
        thread.Sleep(1000);
}
void ContinueRun()
{
    suspend = false; // will cause loop above to break and continue processing
}
DdoubleD 315 Posting Shark

Name: David
Nickname: Dr. Dave, Super Dave (these are very old and nobody uses them anymore)
Height: 5'8''
Weight: 150
Hair: Brownish Blonde
Eyes: Bluish Green
Location: AZ
Age: 43

Hobbies: Watching TV (waste of time...I know), shooting pool, playing guitar, laughing as much as possible, cooking, naps, a cold pint here and there, travel--especially travel with a pint here and there--places I have visited include Aruba, Brazil, Canada, England, France, Mexico, Switzerland, Vietnam, and a few islands.

Relationship Status: single/divorced

Fav Music: like it all, but classic rock seems to fit any mood

Education: Computer Information Systems, some Electronic Engineering

Work: Not for more than four years now, but am ready to do it again. Prior to my long sabbatical: 14 years in software sector

Favorite Food: Almost all food cuisine; trying something new is a favorite

Favorite Movies: Too many to list or call any one of them favorites

Favorite TV Shows: "NCIS" and "Law and Order: SVU" for now (I DVR everything I watch); most marathons ran on Sci-Fi channel (or should I say SyFy--what's up with that?)

Favorite Video Games: Haven't played any video games since my kids left home. Used to be big into pinball, Tempest, Galaga, Space Invaders, Donkey Kong--LOL, I guess I'm old!

Stuff you Dislike: Hypocrites, liars, cheaters, thieves, ex-wife, did I mention ex-wife?; commercials that aren't funny; political 180's; people that have bad attitudes …