Click here to Skip to main content
15,904,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all
I am beginner on coding. I want to make a program that i can insert details of building and than create the graphic control panel. Structure of graphic control panel is same, but there is different number of floor on each graphic.

PLEASE HELP!! This is my school project

What I have tried:

I am trying to create txt of html to make it but it seem did not work
Posted
Updated 31-Mar-17 22:01pm

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

So just posting a cut down version of your homework question and saying "I tried" isn;t going to get you anywhere.
Creating HTML as a text string is trivial in C#:
C#
string html = "<div style=\"margin-top:25px\">Hi all <br>I" +
            " am beginner on coding. I want to make a program that i can insert details of building" + 
            " and than create the graphic control panel. Structure of graphic control panel is" +
            " same, but there is different number of floor on each graphic.<br>" +
            "<br>PLEASE HELP!! This is my school project<br><br><b>What I have tried:</b><br>" +
            "<br>I am trying to create txt of html to make it but it seem did not work</div>";

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!



Look at your code:
C#
for (int i = 1; i <= 10; i++) ;
StreamWriter File = new StreamWriter(i);
File.Write("<div style=\"margin-top:25px\">Hi all I" +
" am beginner on coding. I want to make a program that i can insert details of building" +
" and than create the graphic control panel. Structure of graphic control panel is" +
" same, but there is different number of floor on each graphic." +
"PLEASE HELP!! This is my school projectWhat I have tried:" +
"I am trying to create txt of html to make it but it seem did not work");
File.Close();

The first line:
C#
for (int i = 1; i <= 10; i++) ;
The semicolon terminates the loop - so the lines below that are executed once, and only when the loop is finished. So i will always have the same value: 11.
Except... since i is declared as local to the for loop, it won't exist for the second line!
And even if it did, the StreamWriter constructor does not have a overload which takes an integer value.

Remove the semicolon; add curly brackets; convert the integer to a string. And it's a good idea to specify a valid folder to store the files in, plus give them a "sensible" extension:
C#
for (int i = 1; i <= 10; i++)
    {
    StreamWriter File = new StreamWriter(string.Format(@"D:\Temp\{0}.txt", i.ToString()));
    File.Write("<div style=\"margin-top:25px\">Hi all I" +
    " am beginner on coding. I want to make a program that i can insert details of building" +
    " and than create the graphic control panel. Structure of graphic control panel is" +
    " same, but there is different number of floor on each graphic." +
    " PLEASE HELP!! This is my school project. What I have tried:" +
    " I am trying to create txt of html to make it but it seem did not work");
    File.Close();
    }


This kind of stuff is pretty basic, and I can't help thinking that you are trying to run before you can walk...
 
Share this answer
 
v2
Comments
Member 13098678 1-Apr-17 4:51am    
I did something like this mass

""""for (int i = 1; i <= 10; i++) ;
StreamWriter File = new StreamWriter(i);
File.Write("<div style=\"margin-top:25px\">Hi all I" +
" am beginner on coding. I want to make a program that i can insert details of building" +
" and than create the graphic control panel. Structure of graphic control panel is" +
" same, but there is different number of floor on each graphic." +
"PLEASE HELP!! This is my school projectWhat I have tried:" +
"I am trying to create txt of html to make it but it seem did not work");
File.Close();""""""

The purpose is create TEXT file which contain html. Not display HTML on C#
Also I am thinking to using for loop to create amount of TEXT file.
OriginalGriff 1-Apr-17 5:08am    
Answer updated
Member 13098678 1-Apr-17 7:12am    
Thank you for remaining I will be careful on it.
I can use this code to create HTML.
Also I am wondering what does -----i.ToString()----- to do?
(string.Format(@"D:\Temp\{0}.txt", i.ToString())

Besides why FOR loop did not create several HTML?
OriginalGriff 1-Apr-17 7:48am    
i.ToString converts a number to it's string equivalent.
So instead of a number that you can do math with:
56 + 9
You get a string you can print:
"56"
You don't need it in string.Format calls, because it'll be generated for you, I added it to show you that numbers and strings are different animals!

And your original for loop didn't do anything because the statement it operated on was empty - the semicolon terminated it.
Normal for loops look like this:
for (int i = 0; i < 10 ; i++)
Console.WriteLine(i);
or this:
for (int i = 0; i < 10 ; i++)
{
int j = i * 2;
Console.WriteLine(j);
}
If you do this:
for (int i = 0; i < 10 ; i++);
Console.WriteLine(i);
The semicolon terminates the for, and it does nothing.

As a beginner, always use curly brackets of loops, if...else, and so on - even if you only write one line of code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900