Tak jsem tu zas, tentokrát mám problém:
System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
Source="nepravidelnaSlovesa"
StackTrace:
at nepravidelnaSlovesa.startup.kontrola() in C:\Documents and Settings\Kuba\Dokumenty\VCS2008-hlaseniVlaky\nepravidelnaSlovesa\nepravidelnaSlovesa\Form1.cs:line 121
at nepravidelnaSlovesa.startup.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Kuba\Dokumenty\VCS2008-hlaseniVlaky\nepravidelnaSlovesa\nepravidelnaSlovesa\Form1.cs:line 183
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at nepravidelnaSlovesa.Program.Main() in C:\Documents and Settings\Kuba\Dokumenty\VCS2008-hlaseniVlaky\nepravidelnaSlovesa\nepravidelnaSlovesa\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
To byla ta chyba. Zkouším s tím dvě hodinky něco provést a nic. Hlásí to až v debuggeru, v editoru kódu to nehlásí nic. Je toho dost no :/ Snad někdo bude tak hodný :smile10:
´using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace nepravidelnaSlovesa
{
public partial class startup : Form
{
public startup()
{
InitializeComponent();
}
string[,] slovesa = { { "beat", "beat", "beaten", "bít/tlouci" }, { "become", "became", "become", "stát se" }, { "begin", "began", "begun", "začít" } };
string key = "6315711492";
string path = @"%APPDATA%\NepravSlov\licensekey.lk";
int chyb;
int vporadku;
int zkontrolovanychSloves;
int sloveso = 0;
public static void kontrolaVerze(bool plnaVerze,string klic, string cesta)
{
try
{
if (!File.Exists(cesta))
{
using (StreamWriter sw = File.CreateText(cesta))
{
sw.WriteLine("DEMO");
}
}
else
{
using (StreamReader sr = File.OpenText(cesta))
{
string s = "";
while ((s = sr.ReadLine()) != "DEMO")
{
if (s == klic)
{
plnaVerze = true;
}
else
{
plnaVerze = false;
}
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Kritická chyba aplikace", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
}
}
public static void zpracujLicencniKlic(bool uspech, string cesta, string zadanyKlic, string spravnyKlic)
{
if (zadanyKlic == spravnyKlic)
{
using (StreamWriter sw = File.CreateText(cesta))
{
sw.WriteLine(zadanyKlic);
}
uspech = true;
}
else
{
uspech = false;
}
}
public void odemkniPole(bool vycisti)
{
TextBox poleCeskyVyznam = ceskyVyznam;
TextBox poleAnglInfinitiv = anglickyInfinitiv;
TextBox poleDruhyClen = druhyClen;
TextBox poleTretiClen = tretiClen;
NumericUpDown numericPocetSloves = pocetSlovesZkouseni;
poleCeskyVyznam.Enabled = true;
poleAnglInfinitiv.Enabled = true;
poleDruhyClen.Enabled = true;
poleTretiClen.Enabled = true;
numericPocetSloves.Enabled = true;
if (vycisti == true)
{
poleCeskyVyznam.Text = "";
poleAnglInfinitiv.Text = "";
poleDruhyClen.Text = "";
poleTretiClen.Text = "";
}
}
private void dalsiSloveso()
{
NumericUpDown numericPocetSloves = pocetSlovesZkouseni;
TextBox poleCeskyVyznam = ceskyVyznam;
TextBox poleAnglInfinitiv = anglickyInfinitiv;
TextBox poleDruhyClen = druhyClen;
TextBox poleTretiClen = tretiClen;
poleCeskyVyznam.Text = slovesa[sloveso, 3];
poleAnglInfinitiv.Text = slovesa[sloveso, 0];
sloveso++;
}
private void kontrola()
{
int indexSlovesa = sloveso;
TextBox poleCeskyVyznam = ceskyVyznam;
TextBox poleAnglInfinitiv = anglickyInfinitiv;
TextBox poleDruhyClen = druhyClen;
TextBox poleTretiClen = tretiClen;
bool vseSpravne = true;
string infinitiv = slovesa[indexSlovesa, 0];
string spravnyDruhyClen = slovesa[indexSlovesa, 1];
string spravnyTretiClen = slovesa[indexSlovesa, 2];
string stavovyradekCeskyVyznam = slovesa[indexSlovesa, 3];
if (poleDruhyClen.Text != spravnyDruhyClen)
{
vseSpravne = false;
}
else if (poleTretiClen.Text != spravnyTretiClen)
{
vseSpravne = false;
}
if (vseSpravne == true)
{
label4.Text = "Správně";
label4.ForeColor = Color.Green;
vporadku++;
zkontrolovanychSloves++;
}
else
{
label4.Text = "Špatně";
label4.ForeColor = Color.Red;
chyb++;
zkontrolovanychSloves++;
}
bool vycisti = true;
odemkniPole(vycisti);
poleCeskyVyznam.Enabled = false;
poleAnglInfinitiv.Enabled = false;
poleDruhyClen.Focus();
dalsiSloveso();
}
private void zacniTest_Click(object sender, EventArgs e)
{
zacniTest.Enabled = false;
prerusTest.Enabled = true;
pocetSlovesZkouseni.Enabled = false;
dalsiSloveso();
}
private void prerusTestMetoda()
{
zacniTest.Enabled = true;
prerusTest.Enabled = false;
bool vycisti = true;
odemkniPole(vycisti);
ceskyVyznam.Enabled = false;
anglickyInfinitiv.Enabled = false;
double uspesnost = (Convert.ToDouble(chyb) + Convert.ToDouble(vporadku)) / Convert.ToDouble(zkontrolovanychSloves);
MessageBox.Show("Sloves zkoušeno: " + Convert.ToString(zkontrolovanychSloves) + "\n Správně odpovězeno: " + Convert.ToString(vporadku) + "\n Chybně zodpovězeno: " + Convert.ToString(chyb) + "\n Průměr: " + Convert.ToString(uspesnost), "Zkoušení dokončeno", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void prerusTest_Click(object sender, EventArgs e)
{
prerusTestMetoda();
}
private void button1_Click(object sender, EventArgs e)
{
if (zkontrolovanychSloves == pocetSlovesZkouseni.Value)
{
prerusTestMetoda();
}
kontrola();
}
}
}
Díky :(