Diskuze – Lekce 3 - Práce s textovými soubory v C# .NET
ZpětUpozorňujeme, že diskuze pod našimi online kurzy jsou nemoderované a primárně slouží k získávání zpětné vazby pro budoucí vylepšení kurzů. Pro studenty našich rekvalifikačních kurzů nabízíme možnost přímého kontaktu s lektory a studijním referentem pro osobní konzultace a podporu v rámci jejich studia. Toto je exkluzivní služba, která zajišťuje kvalitní a cílenou pomoc v případě jakýchkoli dotazů nebo projektů.


Kotyza Lukáš:26.4.2016 20:08
kód designeru
/*
* Created by SharpDevelop.
* User: kotyza lukas
* Date: 13.4.2016
* Time: 19:11
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace a
{
partial class MainForm
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.vnt001 = new System.Windows.Forms.NumericUpDown();
this.vnt002 = new System.Windows.Forms.NumericUpDown();
this.vnt003 = new System.Windows.Forms.NumericUpDown();
this.vnt004 = new System.Windows.Forms.NumericUpDown();
this.btnvyrob1 = new System.Windows.Forms.Button();
this.numnasobic = new System.Windows.Forms.NumericUpDown();
this.panel1 = new System.Windows.Forms.Panel();
this.btnkontrola = new System.Windows.Forms.Button();
this.panel2 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.odpovedlbl = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.vnt001)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.vnt002)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.vnt003)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.vnt004)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numnasobic)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(12, 59);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(189, 20);
this.label1.TabIndex = 1;
this.label1.Text = "VNT003";
//
// label2
//
this.label2.Location = new System.Drawing.Point(12, 33);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(189, 20);
this.label2.TabIndex = 2;
this.label2.Text = "VNT002";
//
// label3
//
this.label3.Location = new System.Drawing.Point(9, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(189, 20);
this.label3.TabIndex = 3;
this.label3.Text = "VNT001 ( kondenzátor )";
//
// label4
//
this.label4.Location = new System.Drawing.Point(12, 85);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(189, 20);
this.label4.TabIndex = 4;
this.label4.Text = "VNT004";
//
// vnt001
//
this.vnt001.BackColor = System.Drawing.Color.Silver;
this.vnt001.Increment = new decimal(new int[] {
100,
0,
0,
0});
this.vnt001.Location = new System.Drawing.Point(207, 7);
this.vnt001.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.vnt001.Minimum = new decimal(new int[] {
1410065408,
2,
0,
-2147483648});
this.vnt001.Name = "vnt001";
this.vnt001.Size = new System.Drawing.Size(74, 20);
this.vnt001.TabIndex = 5;
this.vnt001.Value = new decimal(new int[] {
1000,
0,
0,
0});
//
// vnt002
//
this.vnt002.BackColor = System.Drawing.Color.Silver;
this.vnt002.Increment = new decimal(new int[] {
100,
0,
0,
0});
this.vnt002.Location = new System.Drawing.Point(207, 31);
this.vnt002.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.vnt002.Minimum = new decimal(new int[] {
1410065408,
2,
0,
-2147483648});
this.vnt002.Name = "vnt002";
this.vnt002.Size = new System.Drawing.Size(74, 20);
this.vnt002.TabIndex = 6;
this.vnt002.Value = new decimal(new int[] {
500,
0,
0,
0});
//
// vnt003
//
this.vnt003.BackColor = System.Drawing.Color.Silver;
this.vnt003.Increment = new decimal(new int[] {
100,
0,
0,
0});
this.vnt003.Location = new System.Drawing.Point(207, 57);
this.vnt003.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.vnt003.Minimum = new decimal(new int[] {
1410065408,
2,
0,
-2147483648});
this.vnt003.Name = "vnt003";
this.vnt003.Size = new System.Drawing.Size(74, 20);
this.vnt003.TabIndex = 7;
this.vnt003.Value = new decimal(new int[] {
500,
0,
0,
0});
//
// vnt004
//
this.vnt004.BackColor = System.Drawing.Color.Silver;
this.vnt004.Increment = new decimal(new int[] {
100,
0,
0,
0});
this.vnt004.Location = new System.Drawing.Point(207, 83);
this.vnt004.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.vnt004.Minimum = new decimal(new int[] {
1410065408,
2,
0,
-2147483648});
this.vnt004.Name = "vnt004";
this.vnt004.Size = new System.Drawing.Size(74, 20);
this.vnt004.TabIndex = 8;
this.vnt004.Value = new decimal(new int[] {
500,
0,
0,
0});
//
// btnvyrob1
//
this.btnvyrob1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnvyrob1.Location = new System.Drawing.Point(534, 255);
this.btnvyrob1.Name = "btnvyrob1";
this.btnvyrob1.Size = new System.Drawing.Size(79, 38);
this.btnvyrob1.TabIndex = 9;
this.btnvyrob1.Text = "výrobek 1 ";
this.btnvyrob1.UseVisualStyleBackColor = true;
this.btnvyrob1.Click += new System.EventHandler(this.Btnvyrob1Click);
//
// numnasobic
//
this.numnasobic.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.numnasobic.BackColor = System.Drawing.Color.Silver;
this.numnasobic.Location = new System.Drawing.Point(482, 266);
this.numnasobic.Maximum = new decimal(new int[] {
100000,
0,
0,
0});
this.numnasobic.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numnasobic.Name = "numnasobic";
this.numnasobic.Size = new System.Drawing.Size(46, 20);
this.numnasobic.TabIndex = 10;
this.numnasobic.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Maroon;
this.panel1.Location = new System.Drawing.Point(190, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(11, 10);
this.panel1.TabIndex = 11;
this.panel1.Visible = false;
//
// btnkontrola
//
this.btnkontrola.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnkontrola.Location = new System.Drawing.Point(12, 270);
this.btnkontrola.Name = "btnkontrola";
this.btnkontrola.Size = new System.Drawing.Size(75, 23);
this.btnkontrola.TabIndex = 12;
this.btnkontrola.Text = "kontrola";
this.btnkontrola.UseVisualStyleBackColor = true;
this.btnkontrola.Click += new System.EventHandler(this.BtnkontrolaClick);
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Maroon;
this.panel2.Location = new System.Drawing.Point(190, 33);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(11, 10);
this.panel2.TabIndex = 12;
this.panel2.Visible = false;
//
// panel3
//
this.panel3.BackColor = System.Drawing.Color.Maroon;
this.panel3.Location = new System.Drawing.Point(190, 56);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(11, 10);
this.panel3.TabIndex = 12;
this.panel3.Visible = false;
//
// panel4
//
this.panel4.BackColor = System.Drawing.Color.Maroon;
this.panel4.Location = new System.Drawing.Point(190, 82);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(11, 10);
this.panel4.TabIndex = 13;
this.panel4.Visible = false;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Silver;
this.ClientSize = new System.Drawing.Size(625, 305);
this.Controls.Add(this.odpovedlbl);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel3);
this.Controls.Add(this.panel4);
this.Controls.Add(this.btnkontrola);
this.Controls.Add(this.panel1);
this.Controls.Add(this.numnasobic);
this.Controls.Add(this.btnvyrob1);
this.Controls.Add(this.vnt004);
this.Controls.Add(this.vnt003);
this.Controls.Add(this.vnt002);
this.Controls.Add(this.vnt001);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "MainForm";
this.Text = "SKLAD THT - VNT";
((System.ComponentModel.ISupportInitialize)(this.vnt001)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.vnt002)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.vnt003)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.vnt004)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numnasobic)).EndInit();
this.ResumeLayout(false);
}
private System.Windows.Forms.Label odpovedlbl;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Button btnkontrola;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.NumericUpDown numnasobic;
private System.Windows.Forms.Button btnvyrob1;
private System.Windows.Forms.NumericUpDown vnt004;
private System.Windows.Forms.NumericUpDown vnt003;
private System.Windows.Forms.NumericUpDown vnt002;
private System.Windows.Forms.NumericUpDown vnt001;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
}
}
Tomáš Brůna:26.4.2016 20:17
abych pravdu řekl, tak netuším leda že by jsi poslal celý projekt, toto:
using (StreamWriter sw = new StreamWriter(@"uloziste.txt"))
{
decimal x = vnt001.Value;
sw.WriteLine(x.ToString());
}
using (StreamReader sr = new StreamReader(@"uloziste.txt"))
{
string s;
while ((s = sr.ReadLine()) != null)
{
MessageBox.Show(s);
/*zatím to mám poslané do massage boxu ale to teď neřeším*/
}
}
u mně normálně jede
Kotyza Lukáš:26.4.2016 20:35
http://www.itnetwork.cz/dev-lighter/716
http://www.itnetwork.cz/dev-lighter/715
http://www.itnetwork.cz/dev-lighter/714
a ještě nejspíš by to nemělo mít vliv ale v jakém programu to otvíráš já to otvírám v sharpdevelopu
konečně.....
...
snažíš se číst z neexistujícího numericUpDownu, teda snažíš ze z něj
číst něž ho vůbec vytvoříš,
takže přesuň tohle:
InitializeComponent();
před to kde čteš.
Kotyza Lukáš:26.4.2016 21:07
už to funguje strašně moc děkuji zase jsem o něco chytřejší
Ahoj, rád bych se zeptal, zda jde nějak zjistit počet řádků v textovém dokumentu? Děkuji
Neaktivní uživatel:2.5.2016 16:22
Založ si int, který při každém přečení řádku ve while cyklu inkrementuješ.
Mám takovej podivnej problém. Pokud vytvořím .txt soubor a napíšu do
něj text, program mi umí přečíst jen ASCII znaky a ostatní zobrazí jako
otazníky. Pokud do něj ale nejdřív něco zapíšu přes StreamWriter, pak to
najednou umí číst bez problému. Hádám, že to bude ve formátu nebo
kodování toho .txt souboru. Neví někdo?
Je to jako když otevřeš notepad, něco napíšeš a pak dáš uložit -
dole máš nabídku kódování. Je tam ASCII, ANSI a UTF-8 StreamWriter má defaultní
kódování UTF-8, dá se ovlivnit nastavením příslušné vlastnosti, jméno
teď z hlavy nevím, ale bude to něco jako StreamWriter.Encoding
Zobrazeno 10 zpráv z 64.