Error casting string to Decimal - c#

I am getting these two errors :
the type string cannot convert to decimal
at:
(str1 = (Decimal) (num1 / num3).ToString("0.00").Replace(".00", string.Empty);)
and
(str2 = (Decimal) (num4 / num5).ToString("0.00").Replace(".00", string.Empty);)
How do I fix this?
private void TotalMB_Click(object sender, EventArgs e)
{
uint num1 = (uint) (this.K10Ks.Value + this.S12Ks.Value + this.DSRKs.Value + this.PeaceKs.Value + this.M1216Ks.Value + this.SCARKs.Value + this.CQBKs.Value + this.ANKs.Value + this.R870Ks.Value + this.BallistaKs.Value + this.KSGKs.Value + this.M27Ks.Value + this.TypeKs.Value + this.MP7Ks.Value + this.PDWKs.Value + this.MTARKs.Value + this.MSMCKs.Value + this.EVOKs.Value + this.TacKs.Value + this.SMRKs.Value + this.FivesKs.Value + this.KAPKs.Value + this.B23RKs.Value + this.SWATKs.Value + this.MK48Ks.Value + this.XPRKs.Value + this.M8A1Ks.Value + this.LSATKs.Value + this.ExeKs.Value + this.HAMRKs.Value + this.FALKs.Value + this.QBBKs.Value + this.SVUKs.Value + this.BowKs.Value + this.BallKnifeKs.Value + this.SMAWKs.Value + this.RPGKs.Value + this.ShieldKs.Value + this.FHJKs.Value + this.K9Oth.Value + this.StikOth.Value + this.HtOth.Value + this.SwrOth.Value + this.LodsOth.Value + this.CPacOth.Value + this.VTOLOth.Value + this.MisOth.Value + this.SenyOth.Value + this.ChopOth.Value + this.GdiOth.Value + this.DrnOth.Value + this.WathOth.Value + this.DrgOth.Value + this.RXOth.Value + this.WarOth.Value + this.AGROth.Value + this.DetOth.Value);
uint num2 = (uint) (this.K10Hd.Value + this.S12Hd.Value + this.DSRHd.Value + this.PeaceHd.Value + this.M1216Hd.Value + this.SCARHd.Value + this.CQBHd.Value + this.ANHd.Value + this.R870Hd.Value + this.BallistaHd.Value + this.KSGHd.Value + this.M27Hd.Value + this.TypeHd.Value + this.MP7Hd.Value + this.PDWHd.Value + this.MTARHd.Value + this.MSMCHd.Value + this.EVOHd.Value + this.TacHd.Value + this.SMRHd.Value + this.FivesHd.Value + this.KAPHd.Value + this.B23RHd.Value + this.SWATHd.Value + this.MK48Hd.Value + this.XPRHd.Value + this.M8A1Hd.Value + this.LSATHd.Value + this.ExeHd.Value + this.HAMRHd.Value + this.FALHd.Value + this.QBBHd.Value + this.SVUHd.Value + this.BallKnifeHd.Value);
uint num3 = (uint) (this.K10De.Value + this.S12De.Value + this.DSRDe.Value + this.PeaceDe.Value + this.M1216De.Value + this.SCARDe.Value + this.CQBDe.Value + this.ANDe.Value + this.R870De.Value + this.BallistaDe.Value + this.KSGDe.Value + this.M27De.Value + this.TypeDe.Value + this.MP7De.Value + this.PDWDe.Value + this.MTARDe.Value + this.MSMCDe.Value + this.EVODe.Value + this.TacDe.Value + this.SMRDe.Value + this.FivesDe.Value + this.KAPDe.Value + this.B23RDe.Value + this.SWATDe.Value + this.MK48De.Value + this.XPRDe.Value + this.M8A1De.Value + this.LSATDe.Value + this.ExeDe.Value + this.HAMRDe.Value + this.FALDe.Value + this.QBBDe.Value + this.SVUDe.Value + this.BowDe.Value + this.BallKnifeDe.Value + this.ShieldDe.Value);
uint num4 = (uint) (this.TDMWin.Value + this.FreeForAllWin.Value + this.SDWin.Value + this.DominationWin.Value + this.HardpointWin.Value + this.HeadquartersWin.Value + this.DemolitionWin.Value + this.CTFWin.Value + this.KillConfirmedWin.Value + this.GunGameWin.Value + this.OneintheChamberWin.Value + this.SharpshooterWin.Value + this.SticksandStonesWin.Value + this.HCTDMWin.Value + this.HCSDWin.Value + this.HCDominationWin.Value + this.HCKillConfirmedWin.Value);
uint num5 = (uint) (this.TDMLos.Value + this.FreeForAllLos.Value + this.SDLos.Value + this.DominationLos.Value + this.HardpointLos.Value + this.HeadquartersLos.Value + this.DemolitionLos.Value + this.CTFLos.Value + this.KillConfirmedLos.Value + this.GunGameLos.Value + this.OneintheChamberLos.Value + this.SharpshooterLos.Value + this.SticksandStonesLos.Value + this.HCTDMLos.Value + this.HCSDLos.Value + this.HCDominationLos.Value + this.HCKillConfirmedLos.Value);
string str1;
double num6;
if ((int) num1 != 0 && (int) num3 != 0)
{
str1 = (Decimal) (num1 / num3).ToString("0.00").Replace(".00", string.Empty);
}
else
{
num6 = 0.0;
str1 = num6.ToString();
}
string str2;
if ((int) num4 != 0 && (int) num5 != 0)
{
str2 = (Decimal) (num4 / num5).ToString("0.00").Replace(".00", string.Empty);
}
else
{
num6 = 0.0;
str2 = num6.ToString();
}
int num7 = (int) MessageBox.Show("Kills: " + (object) num1 + "\nDeaths: " + (object) num3 + "\nWins: " + (object) num4 + "\nLosses: " + (object) num5 + "\nHeadshots: " + (object) num2 + "\nK/D: " + str1 + "\nW/L: " + str2 + "\n\nDon't Include Medals");
}

Just remove the casts to Decimal and it works like expected:
private void TotalMB_Click(object sender, EventArgs e)
{
uint num1 = (uint) (this.K10Ks.Value + this.S12Ks.Value + this.DSRKs.Value + this.PeaceKs.Value + this.M1216Ks.Value + this.SCARKs.Value + this.CQBKs.Value + this.ANKs.Value + this.R870Ks.Value + this.BallistaKs.Value + this.KSGKs.Value + this.M27Ks.Value + this.TypeKs.Value + this.MP7Ks.Value + this.PDWKs.Value + this.MTARKs.Value + this.MSMCKs.Value + this.EVOKs.Value + this.TacKs.Value + this.SMRKs.Value + this.FivesKs.Value + this.KAPKs.Value + this.B23RKs.Value + this.SWATKs.Value + this.MK48Ks.Value + this.XPRKs.Value + this.M8A1Ks.Value + this.LSATKs.Value + this.ExeKs.Value + this.HAMRKs.Value + this.FALKs.Value + this.QBBKs.Value + this.SVUKs.Value + this.BowKs.Value + this.BallKnifeKs.Value + this.SMAWKs.Value + this.RPGKs.Value + this.ShieldKs.Value + this.FHJKs.Value + this.K9Oth.Value + this.StikOth.Value + this.HtOth.Value + this.SwrOth.Value + this.LodsOth.Value + this.CPacOth.Value + this.VTOLOth.Value + this.MisOth.Value + this.SenyOth.Value + this.ChopOth.Value + this.GdiOth.Value + this.DrnOth.Value + this.WathOth.Value + this.DrgOth.Value + this.RXOth.Value + this.WarOth.Value + this.AGROth.Value + this.DetOth.Value);
uint num2 = (uint) (this.K10Hd.Value + this.S12Hd.Value + this.DSRHd.Value + this.PeaceHd.Value + this.M1216Hd.Value + this.SCARHd.Value + this.CQBHd.Value + this.ANHd.Value + this.R870Hd.Value + this.BallistaHd.Value + this.KSGHd.Value + this.M27Hd.Value + this.TypeHd.Value + this.MP7Hd.Value + this.PDWHd.Value + this.MTARHd.Value + this.MSMCHd.Value + this.EVOHd.Value + this.TacHd.Value + this.SMRHd.Value + this.FivesHd.Value + this.KAPHd.Value + this.B23RHd.Value + this.SWATHd.Value + this.MK48Hd.Value + this.XPRHd.Value + this.M8A1Hd.Value + this.LSATHd.Value + this.ExeHd.Value + this.HAMRHd.Value + this.FALHd.Value + this.QBBHd.Value + this.SVUHd.Value + this.BallKnifeHd.Value);
uint num3 = (uint) (this.K10De.Value + this.S12De.Value + this.DSRDe.Value + this.PeaceDe.Value + this.M1216De.Value + this.SCARDe.Value + this.CQBDe.Value + this.ANDe.Value + this.R870De.Value + this.BallistaDe.Value + this.KSGDe.Value + this.M27De.Value + this.TypeDe.Value + this.MP7De.Value + this.PDWDe.Value + this.MTARDe.Value + this.MSMCDe.Value + this.EVODe.Value + this.TacDe.Value + this.SMRDe.Value + this.FivesDe.Value + this.KAPDe.Value + this.B23RDe.Value + this.SWATDe.Value + this.MK48De.Value + this.XPRDe.Value + this.M8A1De.Value + this.LSATDe.Value + this.ExeDe.Value + this.HAMRDe.Value + this.FALDe.Value + this.QBBDe.Value + this.SVUDe.Value + this.BowDe.Value + this.BallKnifeDe.Value + this.ShieldDe.Value);
uint num4 = (uint) (this.TDMWin.Value + this.FreeForAllWin.Value + this.SDWin.Value + this.DominationWin.Value + this.HardpointWin.Value + this.HeadquartersWin.Value + this.DemolitionWin.Value + this.CTFWin.Value + this.KillConfirmedWin.Value + this.GunGameWin.Value + this.OneintheChamberWin.Value + this.SharpshooterWin.Value + this.SticksandStonesWin.Value + this.HCTDMWin.Value + this.HCSDWin.Value + this.HCDominationWin.Value + this.HCKillConfirmedWin.Value);
uint num5 = (uint) (this.TDMLos.Value + this.FreeForAllLos.Value + this.SDLos.Value + this.DominationLos.Value + this.HardpointLos.Value + this.HeadquartersLos.Value + this.DemolitionLos.Value + this.CTFLos.Value + this.KillConfirmedLos.Value + this.GunGameLos.Value + this.OneintheChamberLos.Value + this.SharpshooterLos.Value + this.SticksandStonesLos.Value + this.HCTDMLos.Value + this.HCSDLos.Value + this.HCDominationLos.Value + this.HCKillConfirmedLos.Value);
string str1;
double num6;
if ((int) num1 != 0 && (int) num3 != 0)
{
// Cast removed here
str1 = (num1 / num3).ToString("0.00").Replace(".00", string.Empty);
}
else
{
num6 = 0.0;
str1 = num6.ToString();
}
string str2;
if ((int) num4 != 0 && (int) num5 != 0)
{
// Cast removed here
str2 = (num4 / num5).ToString("0.00").Replace(".00", string.Empty);
}
else
{
num6 = 0.0;
str2 = num6.ToString();
}
int num7 = (int) MessageBox.Show("Kills: " + (object) num1 + "\nDeaths: " + (object) num3 + "\nWins: " + (object) num4 + "\nLosses: " + (object) num5 + "\nHeadshots: " + (object) num2 + "\nK/D: " + str1 + "\nW/L: " + str2 + "\n\nDon't Include Medals");
}

You are converting to String and then cast it to a string actually.
Like this you would cast first:
((Decimal) (num1 / num3)).ToString()

Related

How to print stars depending on value of an array?

I recently make a program to calculate sum and avg of a given array. The program also want to print the histogram or stars pattern match with value of index.
Like this:
This is the code I wrote so far:
private void process_Click(object sender, EventArgs e)
{
string temp2 = null;
string temp3 = null;
float sum=0;
int countingNumber = 1;
string message;
int count = Convert.ToInt32(inputArray.Text);
int[] varray = new int[count];
for (int i = 0; i < count; i++)
//for (int j = 1; j <= count; j++)
{
varray[i] = Convert.ToInt32(Interaction.InputBox(message = "enter the value of array number " + countingNumber));
sum = sum+ varray[i];
temp += countingNumber + " "+varray[i] + Environment.NewLine;
temp2 += countingNumber + " " + varray[i] + " *" + Environment.NewLine;
box1.Text = Convert.ToString("Index Value" + Environment.NewLine + temp);
boxSum.Text = Convert.ToString(sum);
boxAvg.Text = Convert.ToString(sum/count);
countingNumber++;
}
for (int stars = 0; stars <= i; stars++)
{
temp3 = " ";
box2.Text = Convert.ToString("Element Value Histogram" + Environment.NewLine + temp2+temp3);
}
}
}
My code won't print the stars match with the value. Could anybody help me?
Try replacing this line:
temp2 += countingNumber + " " + varray[i] + " *" + Environment.NewLine;
with this line:
temp2 += countingNumber + " " + varray[i] + " " + new String('*', i) + Environment.NewLine;

In a C# console app, how would I create 'images' for playing cards in a blackjack game? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm working on a simple C# blackjack console application game for my school and I was given an example to look at. This example somehow draws a picture of the card in the console window and I can't figure out how to replicate this without specifying hundreds of Console.Write's for each of the 52 unique cards.
in game scene
This is what it looks like when you're actually playing the game. Quite nice.
shuffle and show deck
There is also an option from the main menu to shuffle and display all 52 cards.
So what is this wizardry? Did they actually spend a TON of time hard-coding how every single unique card prints out? I sure hope not. This is what I'm trying to replicate and I'm at a loss for ideas besides hard-coding. Thanks for your help.
Thanks to Damien_The_Unbeliever's comment, I was able to come up with these 2 methods within my card class. Also thanks to vik_78's comment for letting me know that I needed UTF8 encoding to be able to see the card symbols.
public void PrintCard()
{
if (_value == 1)
{
_printString =
" V " +
" " +
" " +
" S " +
" " +
" " +
" V " ;
PrintMethod();
}
if (_value == 2)
{
_printString =
" V " +
" S " +
" " +
" " +
" " +
" S " +
" V ";
PrintMethod();
}
if (_value == 3)
{
_printString =
" V " +
" S " +
" " +
" S " +
" " +
" S " +
" V ";
PrintMethod();
}
if (_value == 4)
{
_printString =
" V " +
" S S " +
" " +
" " +
" " +
" S S " +
" V ";
PrintMethod();
}
if (_value == 5)
{
_printString =
" V " +
" S S " +
" " +
" S " +
" " +
" S S " +
" V ";
PrintMethod();
}
if (_value == 6)
{
_printString =
" V " +
" S S " +
" " +
" S S " +
" " +
" S S " +
" V ";
PrintMethod();
}
if (_value == 7)
{
_printString =
" V " +
" S S " +
" S " +
" S S " +
" " +
" S S " +
" V ";
PrintMethod();
}
if (_value == 8)
{
_printString =
" V " +
" S S " +
" S " +
" S S " +
" S " +
" S S " +
" V ";
PrintMethod();
}
if (_value == 9)
{
_printString =
" V " +
" S S S " +
" " +
" S S S " +
" " +
" S S S " +
" V ";
PrintMethod();
}
if (_value == 10 || _value == 11 || _value == 12 || _value == 13)
{
_printString =
" V " +
" S S " +
" S " +
" S S S S " +
" S " +
" S S " +
" V ";
PrintMethod();
}
}
private void PrintMethod()
{
bool hasWrittenFirstNumber = false;
switch (_suit)
{
case "Hearts":
case "Diamonds":
Console.ForegroundColor = ConsoleColor.Red;
break;
case "Clubs":
case "Spades":
Console.ForegroundColor = ConsoleColor.Black;
break;
}
for (int i = 0; i < _printString.Length; i++)
{
Console.BackgroundColor = ConsoleColor.White;
if (i % 11 == 0 && i != 0)
{
Console.CursorLeft -= 11;
Console.CursorTop += 1;
}
if (_printString[i] == 'S')
{
switch (_suit)
{
case "Hearts":
Console.Write('♥');
break;
case "Clubs":
Console.Write("♣");
break;
case "Diamonds":
Console.Write("♦");
break;
case "Spades":
Console.Write("♠");
break;
}
continue;
}
else if (_printString[i] == 'V')
{
if (_value == 10)
{
if (hasWrittenFirstNumber == false)
{
Console.Write(10);
hasWrittenFirstNumber = true;
i++;
}
else
{
Console.CursorLeft--;
Console.Write(10);
}
continue;
}
else if (_value == 11)
{
Console.Write("J");
}
else if (_value == 12)
{
Console.Write("Q");
}
else if (_value == 13)
{
Console.Write("K");
}
else if (_value == 1)
{
Console.Write("A");
}
else
{
Console.Write(_value);
}
}
else
{
Console.Write(_printString[i]);
}
}
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
}
vik_78's answer
Damien_The_Unbeliever's comment
You don't need images for cards. You already have them. Press from alt + 3 to alt + 6 (on numericpad)
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("♥ ♦ ♣ ♠");

How to print given data in datagridview?

The program read data from hrm file and parse heading along with data. The data is stored in a variable. By concatenating string testOutput, the data is printed in console. Now how to print in datagridview?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project_Test.Data
{
class Params : Data
{
float Version;
int Monitor;
bool IsSMode = true;
Dictionary<string, char> ModeOrSMode = new Dictionary<string, char>();
DateTime Date;
String StartTime;
String Length;
int Interval;
int Upper1;
int Lower1;
int Upper2;
int Lower2;
int Upper3;
int Lower3;
String Timer1;
String Timer2;
String Timer3;
int ActiveLimit;
int MaxHR;
int RestHR;
int StartDelay;
int VO2max;
int Weight;
public Params(string[] lines)
{
ParseAndStoreData(lines);
}
protected override void ParseAndStoreData(string[] rawData)
{
string tempStore;
Version = float.Parse(rawData[0].Split('=')[1]) / 100;
Monitor = int.Parse(rawData[1].Split('=')[1]);
setModeOrSModeValues(rawData[2].Split('=')[1]);
tempStore = rawData[3].Split('=')[1];
Date = new DateTime(int.Parse(tempStore.Substring(0, 4)), int.Parse(tempStore.Substring(4, 2)), int.Parse(tempStore.Substring(6, 2)));
StartTime = rawData[4].Split('=')[1];
Length = rawData[5].Split('=')[1];
Interval = int.Parse(rawData[6].Split('=')[1]);
Upper1 = int.Parse(rawData[7].Split('=')[1]);
Lower1 = int.Parse(rawData[8].Split('=')[1]);
Upper2 = int.Parse(rawData[9].Split('=')[1]);
Lower2 = int.Parse(rawData[10].Split('=')[1]);
Upper3 = int.Parse(rawData[11].Split('=')[1]);
Lower3 = int.Parse(rawData[12].Split('=')[1]);
Timer1 = rawData[13].Split('=')[1];
Timer2 = rawData[14].Split('=')[1];
Timer3 = rawData[15].Split('=')[1];
ActiveLimit = int.Parse(rawData[16].Split('=')[1]);
MaxHR = int.Parse(rawData[17].Split('=')[1]);
RestHR = int.Parse(rawData[18].Split('=')[1]);
StartDelay = int.Parse(rawData[19].Split('=')[1]);
VO2max = int.Parse(rawData[20].Split('=')[1]);
Weight = int.Parse(rawData[21].Split('=')[1]);
}
private void setModeOrSModeValues(string values)
{
switch (Version.ToString())
{
case "1.05":
{
SetModeValues(values);
}
break;
case "1.06":
{
SetSModeValues(values);
}
break;
case "1.07":
{
SetSModeValuesWithAirPressure(values);
}
break;
default:
break;
}
}
private void SetModeValues(string values)
{
IsSMode = false;
ModeOrSMode.Add("Cad/Alt", values[0]);
ModeOrSMode.Add("CC data", values[1]);
ModeOrSMode.Add("US/Euro unit", values[2]);
}
private void SetSModeValues(string values)
{
ModeOrSMode.Add("Speed", values[0]);
ModeOrSMode.Add("Cadenence", values[1]);
ModeOrSMode.Add("Altitude", values[2]);
ModeOrSMode.Add("Power", values[3]);
ModeOrSMode.Add("Power Left Right Balance", values[4]);
ModeOrSMode.Add("Power Pedalling Index", values[5]);
ModeOrSMode.Add("HR/CC data", values[6]);
ModeOrSMode.Add("US/Euro unit", values[7]);
}
private void SetSModeValuesWithAirPressure(string values)
{
SetSModeValues(values);
ModeOrSMode.Add("Air Pressure", values[8]);
}
public void TestDisplayData()
{
string testOutput = "Params Data \n";
testOutput += "Version: " + Version.ToString() + "\n";
testOutput += "Monitor: " + Monitor.ToString() + "\n";
testOutput += ((IsSMode) ? "S" : "") + "Mode :" + "\n";
foreach (KeyValuePair<string, char> item in ModeOrSMode)
{
testOutput += "\t\t" + item.Key + " = " + item.Value + "\n";
}
testOutput += "\n";
testOutput += "Date: " + Date.ToString() + "\n"; // date can be formatted
testOutput += "Start Time: " + StartTime + "\n";
testOutput += "Length: " + Length + "\n";
testOutput += "Interval: " + Interval + "\n";
testOutput += "Upper1: " + Upper1 + "\n";
testOutput += "Lower1: " + Lower1 + "\n";
testOutput += "Upper2: " + Upper2 + "\n";
testOutput += "Lower2: " + Lower2 + "\n";
testOutput += "Upper3: " + Upper3 + "\n";
testOutput += "Lower3: " + Lower3 + "\n";
testOutput += "Timer1: " + Timer1 + "\n"; // 07:04 can be shown as 7 min and 4 seconds
testOutput += "Timer2: " + Timer2 + "\n";
testOutput += "Timer3: " + Timer3 + "\n";
testOutput += "ActiveLimit: " + ActiveLimit + "\n";
testOutput += "MaxHR: " + MaxHR + "\n";
testOutput += "RestHR: " + RestHR + "\n";
testOutput += "StartDelay: " + StartDelay + "\n";
testOutput += "Vo2max: " + VO2max + "\n";
testOutput += "Weight: " + Weight + "\n";
Console.WriteLine(testOutput); // display in console
// how to display above data in datagridview
}
}
}

Hamming code extension

I have taken the code from this website of Hamming code. If I wanted to implement it on 12 bits of message and 7 bits of Parity what changes do I have to do? I have added till DI[11] and CI[6] bit couldn't get to inter-prate it's logic
string NrBinary;
long pp, Key=8, number;
double x, y;
Console.WriteLine("Give binary value till 12 bit: ");
NrBinary = Console.ReadLine();
if (NrBinary.Length <= 12)
{
if (NrBinary.Length == 1)
NrBinary = "000000000000" + NrBinary;
if (NrBinary.Length == 2)
NrBinary = "00000000000" + NrBinary;
if (NrBinary.Length == 3)
NrBinary = "0000000000" + NrBinary;
if (NrBinary.Length == 4)
NrBinary = "000000000" + NrBinary;
if (NrBinary.Length == 5)
NrBinary = "00000000" + NrBinary;
if (NrBinary.Length == 6)
NrBinary = "0000000" + NrBinary;
if (NrBinary.Length == 7)
NrBinary = "000000" + NrBinary;
if (NrBinary.Length == 8)
NrBinary = "00000" + NrBinary;
if (NrBinary.Length == 9)
NrBinary = "0000" + NrBinary;
if (NrBinary.Length == 10)
NrBinary = "000" + NrBinary;
if (NrBinary.Length == 11)
NrBinary = "00" + NrBinary;
if (NrBinary.Length == 12)
NrBinary = "0" + NrBinary;
pp = NrBinary.Length;
number = Convert.ToInt64(NrBinary);
Console.WriteLine("PP = " + pp);
for (Key = 0; Key < pp; ++Key)
{
x = Math.Pow(2, Key) - 1;
y = pp + Key;
if (x >= y)
{
goto Mess;
}
}
Mess:
Console.WriteLine("Controlled bit needed Key = " + Key + "\n");
long[] parity = new long[pp];
long[] DI = new long[pp];
long[] CI = new long[Key];
DI[0] = number % 10;
DI[1] = (number / 10) % 10;
DI[2] = (number / 100) % 10;
DI[3] = (number / 1000) % 10;
DI[4] = (number / 10000) % 10;
DI[5] = (number / 100000) % 10;
DI[6] = (number / 1000000) % 10;
DI[7] = (number / 10000000) % 10;
DI[8] = (number / 100000000) % 10;
DI[9] = (number / 1000000000) % 10;
DI[10] = (number / 10000000000) % 10;
DI[11] = (number / 100000000000) % 10;
CI[0] = DI[11] ^ DI[0] ^ DI[1];
CI[1] = DI[1] ^ DI[2] ^ DI[3];
CI[2] = DI[3] ^ DI[4] ^ DI[5];
CI[4] = DI[5] ^ DI[6] ^ DI[7];
CI[5] = DI[7] ^ DI[8] ^ Convert.ToInt64(DI[9]);
CI[6] = CI[1] ^ CI[2] ^ CI[3] ^ CI[4] ^ CI[5] ^ CI[6];
Console.WriteLine("\n = " + CI[0] + "" + CI[1] + "" + CI[2] + "" + CI[3] + "" + CI[4] + "" + CI[5] + "" + CI[6] + "\n");
Console.Write("Bit with Hamming code: ");
Console.WriteLine(DI[11] + "" + DI[10] + "" + DI[9] + "" + DI[8] + "" + DI[7] + "" + DI[6] + "" + DI[5] + "" + DI[4] + "" + DI[3]
+ "" + DI[2] + "" + DI[1] + "" + DI[0] + "" + CI[6] + "" + CI[5] + "" + CI[4] + "" + CI[3] + "" + CI[2] + "" + CI[1] + "" + CI[0]);
/*Console.WriteLine(DI[7] + "" + DI[6] + "" + DI[5] + "" + DI[4] + "" + CI[3] + "" + DI[3]
+ "" + DI[2] + "" + DI[1] + "" + CI[2] + "" + DI[0] + "" + CI[1] + "" + CI[0]);*/
}
else
{
Console.WriteLine("\n\n 8 bit character maximally:)");
}
Console.ReadKey();
}

Printing colored words in RichTextBox

I am writing in a RichTextBox .
How do I make the lineItems and the j+1 variable be printed in red.
For example(in bold = red): Element Growthougth in 4 th column, has not been writen right.
private void button2_Click(object sender, EventArgs e)
{
// Numbers-IDs
if (colB[j] == "int_number")
{
if (!arithmos(lineItems[j]))
richTextBox1.Text += "Element " + lineItems[j] + "\t in " + (j + 1) + "th coloumn,has not been writen right" + Environment.NewLine;
}
// Alphanumeric
else if (colB[j] == "alpharithmitiko")
{
if (!numword(lineItems[j]))
richTextBox1.Text += "Element " + lineItems[j] + " in " + (j + 1) + "th coloumn,has not been writen right " + Environment.NewLine;
}
//Words
else if (colB[j] == "words")
{
if (!word(lineItems[j]))
richTextBox1.Text += "Το στοιχείο " + lineItems[j] + " in " + (j + 1) + "th coloumn,has not been writen right" + Environment.NewLine;
}
//Date
else if (colB[j] == "date")
{
if (!date(lineItems[j]))
richTextBox1.Text += "Το στοιχείο " + lineItems[j] + " in " + (j+1) + "th coloumn,has not been writen right" + Environment.NewLine;
}
}
You can try this..
if (!arithmos(lineItems[j]))
richTextBox1.Text += "Element " + lineItems[j] + "\t in " + (j + 1) + "th coloumn,has not been writen right" + Environment.NewLine;
richTextBox1.SelectionColor = Color.Red;
richTextBox1.AppendText(j + 1);

Categories