8 Replies - 19596 Views - Last Post: 14 July 2010 - 04:33 PM Rate Topic: -----

#1 kevinsyel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 15-June 10

Windows Forms and Strings from a textBox

Posted 13 July 2010 - 03:32 PM

Hi, I have a coding problem where I have an entire string of data in a text box, and I want to parse it into a string Data type

I know if you want an Int, you can simply do: int number = Int32::Parse(textBox1->Text); or double number =Double::Parse(textBox1->Text)

I was wondering if it is possible to pull the entire string and place it in a string data type.

I have string temp;

OR

Is there a way to concatenate other strings into a single string? using temp = string1 + int1.ToString() + string2 doesnt work.

Windows forms is being very picky.

Kevin

Is This A Good Question/Topic? 0
  • +

Replies To: Windows Forms and Strings from a textBox

#2 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Windows Forms and Strings from a textBox

Posted 13 July 2010 - 03:47 PM

Maybe like this:

String ^ temp = textBox1->Text;

System::Windows::Forms::MessageBox::Show(temp);

temp = temp + ", " + temp;

System::Windows::Forms::MessageBox::Show(temp);


Was This Post Helpful? 1
  • +
  • -

#3 kevinsyel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 15-June 10

Re: Windows Forms and Strings from a textBox

Posted 13 July 2010 - 03:57 PM

that works, thank you. Am I able to reuse temp after this declaration, or do I need to delete it?

Kevin
Was This Post Helpful? 0
  • +
  • -

#4 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Windows Forms and Strings from a textBox

Posted 13 July 2010 - 04:00 PM

Within the scope it's declared in, sure. It's a managed type so will be disposed of automagically when it is out of scope.
Was This Post Helpful? 1
  • +
  • -

#5 kevinsyel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 15-June 10

Re: Windows Forms and Strings from a textBox

Posted 13 July 2010 - 04:02 PM

hmm, this doesnt allow me to make textFile[element] = temp;
Any other ideas?
Was This Post Helpful? 0
  • +
  • -

#6 kevinsyel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 15-June 10

Re: Windows Forms and Strings from a textBox

Posted 13 July 2010 - 04:33 PM

Essentially, what I'm trying to do is to copy an entire BAT file line for line into an array of strings, then I find the string I want to edit, based on user input,

So I'm trying to go to line 28 of the BAT file (element 27 of the array) and rewrite the line with the new values.

I first realized that that I couldn't concatenate parts of the string into one whole string, so I decided that I could concatenate the entire string into a textbox, and then pull it back out.

Now I can't get the information back out of the textBox.

What I want to do is take my values:

int iterations = 60; //set to 60 for this demonstation
int delay = 60;

and concatenate them into a string

textFile[element] = "@ECHO pwrtest.exe /sleep /c:" + iterations.ToString() + " /d:" + delay.ToString() + " /p:" + delay.ToString() + " /h:n /s:3 /IgnoreUsbHub";

Is there any way I can concatenate these strings together, or do I need to somehow read every individual in as a character to be able to use strcpy and strcat?
Was This Post Helpful? 0
  • +
  • -

#7 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Windows Forms and Strings from a textBox

Posted 13 July 2010 - 04:56 PM

Please post your code.
Was This Post Helpful? 1
  • +
  • -

#8 kevinsyel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 15-June 10

Re: Windows Forms and Strings from a textBox

Posted 13 July 2010 - 05:26 PM

I got it working, but I'm nearly certain it can be improved upon. Here is the gist of my button click code:

#define LINES_IN_BATCH 70
#define ECHO_LINE 27
#define EXEC_LINE 28
#define ECHO_ENTRY "@ECHO pwrtest.exe /sleep /c:"
#define EXEC_ENTRY "pwrtest.exe /sleep /c:"
#define D_COUNT " /d:"
#define P_COUNT " /p:"
#define S3_EXIT " /h:n /s:3 /IgnoreUsbHub"
#define S4_EXIT " /h:n /s:4 /IgnoreUsbHub"

int test_number = 0;

//SKIPPING WINDOWS FORM REGION

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 //File manipulation variables
				 ifstream infile;
				 ofstream outfile;
				 
				 //Array of strings to hold the BAT
				 string textFile[LINES_IN_BATCH];
			
				 //variables to change in BAT
				 int iterations, delay;

				 //int to string streams
				 std::ostringstream iterate;
				 std::ostringstream del;

				 //If no radio button is clicked, no test can be run
				 if (test_number == 0)
				 {
					MessageBox::Show("No test has been selected!","ERROR!");

				 }

				 //either S3 or S4 loop tests have been selected
				 else
				 {
					 //retrieve data from textBoxes
					 iterations = Int32::Parse(textBox1->Text);
					 delay = Int32::Parse(textBox2->Text);

					 if(test_number == 3)
					 {
						 //open the BAT file and ensure it has been opened
						 infile.open("S3_Resume_Loop.bat");
						 if(!infile.is_open())
						 {
							MessageBox::Show("S3_Resume_Loop.bat Not Found!", "ERROR!");
						 }
						 else
						 {
							//retrieve all the lines of the BAT file
							getline(infile, textFile[0], '\n');
							for(int i = 1; i < LINES_IN_BATCH; i++)
							{
								getline(infile, textFile[i], '\n');
							}
							//close file
							infile.close();
							
							//pass in integers into stringstreams
							iterate << iterations;
							del << delay;

							//edit lines of the  array
							textFile[ECHO_LINE].clear();
							textFile[ECHO_LINE].append(ECHO_ENTRY);
							textFile[ECHO_LINE].append(iterate.str());
							textFile[ECHO_LINE].append(D_COUNT);
							textFile[ECHO_LINE].append(del.str());
							textFile[ECHO_LINE].append(P_COUNT);
							textFile[ECHO_LINE].append(del.str());
							textFile[ECHO_LINE].append(S3_EXIT);

							textFile[EXEC_LINE].clear();
							textFile[EXEC_LINE].append(EXEC_ENTRY);
							textFile[EXEC_LINE].append(iterate.str());
							textFile[EXEC_LINE].append(D_COUNT);
							textFile[EXEC_LINE].append(del.str());
							textFile[EXEC_LINE].append(P_COUNT);
							textFile[EXEC_LINE].append(del.str());
							textFile[EXEC_LINE].append(S3_EXIT);

							//open BAT for outputting
							outfile.open("S3_RESUME_LOOP.BAT");

							//loop to output string arrays into BAT
							for(int i = 0; i < LINES_IN_BATCH; i++)
							{
								outfile << textFile[i];
								outfile << '\n';
							}
							
							//close BAT file
							outfile.close();
						 }
					 }
					 else
					 {}


					 
				 }



			 }

private: System::Void radioButton1_CheckedChanged(System::Object^  sender, System::EventArgs^  e) 
		 {
			 test_number = 3;
		 }

private: System::Void radioButton2_CheckedChanged(System::Object^  sender, System::EventArgs^  e) 
		 {
			 test_number = 4;
		 }



should be pretty self explanatory

This post has been edited by kevinsyel: 13 July 2010 - 05:28 PM

Was This Post Helpful? 0
  • +
  • -

#9 kevinsyel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 15-June 10

Re: Windows Forms and Strings from a textBox

Posted 14 July 2010 - 04:33 PM

I think what I should have done on this code, was use an array of char* to load the file as a c-string.
Then afterwards, I would have easy use of methods like strcpy_s and srtcat_s to manipulate the c-strings.

The issue I'm having now is that, when I build release, the exe crashes on other computers. I can run it just fine on computers with Visual Studio 2010 installed.

I go to the configuration manager, set the build from debug to release. I also set the platform to x64. I then build the application.
When I navigate to the solution's folder, there is an I can work down the chain of PowerTestGUI\x64\release\ and there are 2 files, my exe, and a pdb.
but inside where the code is, there is also a PowerTestGUI\PowerTestGUI\x64\release\ which contains many TLOG files, a few .OBJ files, and others like a precompiled header, a LASTBUILDSTATE and other information
are there some files from VS2010 that I should be transfering over as well to other machines in order to get my program running?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1