15,746,202 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View Javascript questions
View C++ questions
View Python questions
View Java questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 11561872 (Top 42 by date)
Member 11561872
2-May-15 16:16pm
View
Actually the setting the Index to 0 each time the button was clicked fixed everything. I figured it was a simple mistake since i was getting a semi accurate answer. Thanks for pointing that out though. And I'm actually doing this for a class and thats the positions he asked us to put the items in the code at. The final project can be seen here if your curious: http://jbwyatt.com/202/a/a5/a5DNA.htm
otherwise thanks for help!
Member 11561872
2-May-15 15:03pm
View
Ill keep that and mind and change it. However i still can't figure out whats wrong. It reads correctly no matter where i check it. But It still will not work correctly on the second click.
Member 11561872
2-May-15 13:53pm
View
I also updated the question with the class level code. Theres only one other button at the moment but it isn't function so I'm not using it yet
Member 11561872
2-May-15 13:49pm
View
Actually neither file increments lines. Lines is a line count of the file being read. The line value being incremented is actually just raising a variable to display which line is being output to the listbox. Line =1 and goes up so the display shows "Line 001: xxx xxx xxx xxx xxx, Line 002: xxx xxx xxx xxx xxx". The incremented integer only raises a displayed value
Member 11561872
30-Apr-15 18:23pm
View
Ok so fixed that. I updated the question again but it now outputs the same 5 lines every time. Now it only reads: "Line 000 = ABC DEF GHI JKL MNO" for every line
Member 11561872
30-Apr-15 17:59pm
View
So i read somewhere else on here you can append to string by using sting += appendage so i tried that. The code is updated now but it just returns "Line 000 = System.String[] System.String[]..." indefinitely
Member 11561872
30-Apr-15 17:31pm
View
ok so I figured out how to get rid of the error. I simply added the line "DNA = "";". But now it won't show the results. It merely adds "Line 001 =" to the list box. Would it reset DNA back to "" after the loop completes?
Member 11561872
30-Apr-15 16:16pm
View
i updated the question to show it
Member 11561872
30-Apr-15 16:05pm
View
ok. How would i do that? I've actually been trying while loops. My current code has this:
public partial class frmDNA : Form
{
int x = 1;
String Path;
StreamReader DNAFile = new StreamReader("/documents/visual studio 2013/Projects/DNA/DNA.txt");
int Index;
int Lines = File.ReadLines("/documents/visual studio 2013/Projects/DNA/DNA.txt").Count();
public frmDNA()
{
InitializeComponent();
}
private void btnPrint_Click(object sender, EventArgs e)
{
String DNA;
string[ ] DNAarray = new string[Lines];
int Begin, end;
Begin = 0;
end = 4;
while (Index < DNAarray.Length && !DNAFile.EndOfStream)
{
DNAarray[Index] = DNAFile.ReadToEnd();
while (Begin < end)
{
DNA = "Lines " + x + " = " + DNAarray[Begin];
Begin++;
}
end += 5;
x++;
Index++;
lstOut.Items.Add(DNA);
}
}
}
But the line lstOut.Items.Add(DNA); says DNA is unassigned.
Member 11561872
30-Apr-15 15:37pm
View
but the problem is the file is organized as such:
ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
YZA
And can be in different formats in other files the user may try. I need the output to be
Line 001: ABC DEF GHI JKL MNO and so on
Member 11561872
30-Apr-15 1:32am
View
I tried a test to make sure the file opened and the path was fine. But I want the path to be changeable in the code. I created a string called Path then when they click open I assign the path of the opened file to the string Path. Next I need to assign that string to the streamreader. But it says it can't assign it to a no static variable in a class setting. I need it to be versatile cause the file needs to be opened and manipulated with other buttons also. Pretty much so they can open one file to this list and change files and open to another list that analyzes it differently.
Member 11561872
30-Apr-15 0:31am
View
Text
Member 11561872
30-Apr-15 0:31am
View
Then I mean read. I need to take lines of a text file and output them to a listbox. I can't do actual code atm as I'm away from the computer but I have the file opened and the data put into a simple string array. But I don't know how to make it so each line reads specific text then has a specific number of groups after.
Member 11561872
30-Apr-15 0:24am
View
It's windows but it's a virtual boot on a Mac. The path works though. When I change it to "Path" it says it can't set it equal to the non static variable in a class setting.
Member 11561872
30-Apr-15 0:03am
View
aren't they the same thing?
Member 11561872
29-Apr-15 23:50pm
View
if i change the DNAFile to equal "new StreamReader(Path); i get errors
Member 11561872
29-Apr-15 23:50pm
View
Ok so i did that. But now i can't assign the streamreader equal to the string. currently it looks like this:
public partial class
{
String Path;
StreamReader DNAFile = new StreamReader("/documents/visual studio 2013/Projects/DNA/DNA.txt");
}
And under private voice btn_click:
{
if (openDNAfile.ShowDialog() == DialogResult.OK)
{
try
{
Path = openDNAfile.FileName;
DNAFile = new StreamReader(Path);
}
catch
{
}
}
}
Member 11561872
29-Apr-15 23:29pm
View
if i change the DNAFile to equal "new StreamReader(Path); i get errors
Member 11561872
29-Apr-15 23:28pm
View
Ok so i did that. But now i can't assign the streamreader equal to the string. currently it looks like this:
public partial class
{
String Path;
StreamReader DNAFile = new StreamReader("/documents/visual studio 2013/Projects/DNA/DNA.txt");
}
And under private voice btn_click:
{
if (openDNAfile.ShowDialog() == DialogResult.OK)
{
try
{
Path = openDNAfile.FileName;
DNAFile = new StreamReader(Path);
}
catch
{
}
}
}
Member 11561872
20-Apr-15 22:44pm
View
Thanks. And +5 for the .AddRange. Actually fixed another problem i ran into once i got the file to load. First it would output "String Array[ ]" for each item in the file. but i took out the for each statement and just added the array and it worked fine!
Member 11561872
30-Mar-15 17:44pm
View
Actually the below solution worked with enetering "E&xit" into the text property. However i do not know what registering the event does. I just did what i could find based on online research.
Member 11561872
30-Mar-15 17:41pm
View
I was not aware I could simply use "&" in designer mode to do this. I worked though. Thanks!
Member 11561872
30-Mar-15 15:29pm
View
ok, so my instructor went over timers today. We created a timer named "timer1" with the toolbox.
i used int time as my counter. Under btnNewProblem i had:
timer1.enabled = true;
and under btnCheckAnswer i had:
timer1.enabled = false;
time = 0;
then by double clicking the timer on the form i created a tick event handler under which i had:
time++;
if (time > 1)
{
lblTimer.text = time.ToString() + "Seconds";
}
else
{
lblTimer.text = time.ToString() + "second";
and i actually understand what happening. The timers ticks trigger everything under it to happen. int time is originally set to 0, but is raised by 1 each time the timer ticks, which is set to an interval of 1000 milliseconds (1 second). So when btnNewProblem is clicked, the timer starts ticking, changing the label until btnCheckAnswer is clicked, stopping the timer and thus stopping the ticks. And by setting int time to 0 after stopping you reset your timer without changing it until the new problem button is pressed. ^.^
Member 11561872
29-Mar-15 23:37pm
View
Sorry, I was doing this at work and my shift ended. It's bedtime now but I'll compile it in the morning and let you know! Thanks!
Member 11561872
29-Mar-15 22:47pm
View
Declare an integer set it = to itself + 1 each time the handler was called between the 2 button presses?
Member 11561872
29-Mar-15 22:39pm
View
Nothing with the timer. It revolves around the user answering math problems. When the user submits their answer (The second button click) it puts the elapsed time into the label
Member 11561872
29-Mar-15 22:33pm
View
Would that just be timer.start( ); ?
Member 11561872
29-Mar-15 22:31pm
View
For which i do thank you. I don't quite understand yet but i am learning!
Member 11561872
29-Mar-15 22:30pm
View
Ok so how is that done?
Member 11561872
29-Mar-15 22:09pm
View
I can't use a stopwatch for this assignment
Member 11561872
29-Mar-15 22:04pm
View
Looking back at the link i can see what's happening better but i still don't see what's happening. What i see is this:
aTimer is the name of the timer
2000 is the interval in milliseconds. its really just 2 seconds.
the elapsed time property is equal to itself plus the OnTimedEvent method. Right?
But when looking at the event method it doesn't have a value to add. it just writes to the console. So where does it get a value?
Member 11561872
29-Mar-15 21:59pm
View
Right but we haven't really gone over them. I got them by double clicking the button on the forms GUI. We haven't discussed the parts or how to create them.
Member 11561872
29-Mar-15 21:58pm
View
ok, so i'm reading event handlers in my book. (I've already looked for timers. they don't even show up in the index). Im guessing it would be useful because the timer needs measured in seconds and it would be called each second independently of when the buttons clicked. So when either of the buttons are clicked would i be able to stop the timer at the current value and call that value specifically? If so then it would be as easy as subtracting the start value from the end value. Or am i thinking to much?
Member 11561872
29-Mar-15 21:42pm
View
I was actually. He hasn't really touched on timers too much and i can't find anything online that explains the difference between the 2
Member 11561872
29-Mar-15 21:39pm
View
To be honest I don't know. But I don't think this is going in the right direction. We haven't even gone over event-handler-methods yet.
Member 11561872
29-Mar-15 21:21pm
View
I still don't understand what I'm doing wrong. Based on everything we've been taught and all the research I've done my problem is occurring in the line:
time += Convert.ToInt32(Timer.Interval) / 1000;
But i don't know what to change. I would imagine I need to change Interval but anything i change it to breaks the code with the error "Input string was not in a correct format."
Member 11561872
29-Mar-15 20:54pm
View
I checked that page already, but i don't see were it outputs it to a label? it outputs to the console with a separate event but i can't have that.
Member 11561872
28-Mar-15 8:35am
View
Ok, First I'm sorry I'm not picking this up right away. This is actually for a introduction class so I'm just a beginner with coding.
Second, if i set x = rnd.Next(0,13); under btnNewProblem like in your example, it will change private x = -1; so that when i write z = x+y; in btnNewProblem, if x=5 and y=6 z should equal 11. So when i write under btnAnswerCheck to compare z to int Answer it should compare 11 to the user input correct? Was that followable?
Member 11561872
28-Mar-15 8:26am
View
Actually looking closer, I have noticed some things that may not work. I need it to be under the btnNewProblem method. This is because it needs to create a new set of random variables each time the button is clicked.
Member 11561872
28-Mar-15 8:21am
View
Thanks OriginalGriff. I can still set x, y, and z to the random variables right? they don't need to be -1? i.e. private int x = rnd.Next();?
Member 11561872
28-Mar-15 7:20am
View
It forces me to create a new class when i create a new event handler. Im using the variable in the event created for the btnNewProblem, and then i need to fetch it and use it in the event for the btnCheckAnswer. I updated with an example of my code.
Member 11561872
28-Mar-15 7:18am
View
I attemped to clarify it and added a snippet of code from my project. All editing was done after the "Edit" line.
Show More