I have written a Switch/Case statement. The purpose of this statement is to check whether a specific checkbox is selected or not. If the checkbox is selected, the case statements get the true value and the name of the checkbox. For example, if I select Ford in the XAML front end interface, a label gets updated and it adds the value of 10 and if it is unselected, it subtracts 10 as to get the value back. However, I'm just getting the value subtracted. Even when I select the checkbox, I end up with -10, -20 etc values.
I can't figure out where I am going wrong with this.
public static int storage = 0;
public static void StorageRequired(string carName, bool state)
{
switch (carName)
{
case "Ford":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
case "Honda":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
case "McLaren":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
case "Mercedes":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
default:
storage = 0;
return;
}
}
Now I have a some checkboxes such as Ford, Honda etc, one for each case. And I am calling them StorageRequired method like this:
private void Single_Checked(object sender, RoutedEventArgs e)
{
if (InstallFord?.IsChecked == true)
{
InstallAE.IsChecked = true;
CarConfigs.StorageRequired("Ford", true);
}
if (InstallFord?.IsChecked == false)
{
InstallAE.IsChecked = false;
CarConfigs.StorageRequired("Ford", false);
}
if (InstallHonda?.IsChecked == true)
{
CarConfigs.StorageRequired("Honda", true);
}
if (InstallHonda?.IsChecked == false)
{
CarConfigs.StorageRequired("Honda", false);
}
if (InstallMcLaren?.IsChecked == true)
{
CarConfigs.StorageRequired("McLaren", true);
}
if (InstallMcLaren?.IsChecked == false)
{
CarConfigs.StorageRequired("McLaren", false);
}
if (InstallMercedesvisitor?.IsChecked == true)
{
CarConfigs.StorageRequired("Mercedes", true);
}
if (InstallMercedesvisitor?.IsChecked == true)
{
CarConfigs.StorageRequired("Mercedes", false);
}
lblRequiredSpace.Content = $"Required space: {CarConfigs.storage} Mb";
}
The problem is that when I click and check a checkbox, for instance Ford, I get -10 instead of 10. And then when I uncheck it again, I get -20. I'd really appreciate some help in figuring out where I am going wrong here. Basically, I should get 10 added if I am checking any of the cars and similarly, 10 subtracted to get back to original value if that car is unchecked.
Note: 10 is just arbitrary here to make things simple.
Here is your problem. Never put return in a switch case, you should use break; instead of return.
I am not really sure what CarConfigs.GetSpaceConsumed is, So I will assume that its a number. So if you are getting a number you should (You don't have to but I reccomend) use return functions.
So this should probably work, however I made the storage to be local variable so it will return number from the switch statement and the whole function in this case would a return function.
public static int StorageRequired(string carName, bool state)
{
int storage = 0;
switch (carName)
{
case "Ford":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
case "Honda":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
case "McLaren":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
case "Mercedes":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
}
return storage;
}
Related
I have this method that I have essentially duplicated and hardcoded three times, but I would like to condense the three into one method and dynamically change the Input.GetKey(). I am just unsure of how to do that.
The main method is:
private void AugmentAbility1(AugmentData augmentData)
{
switch (augmentData.state)
{
case AbilityState.ready:
if (Input.GetKey(ability1Key))
{
augmentIndex = augmentData.index;
augmentList[augmentIndex].augmentSkill.Ability();
augmentData.state = AbilityState.active;
augmentData.activeTime = augmentList[augmentIndex].augmentSkill.activeTime;
}
break;
case AbilityState.active:
if (augmentData.activeTime > 0)
{
augmentData.activeTime -= Time.deltaTime;
}
else
{
augmentData.state = AbilityState.cooldown;
augmentData.cooldownTime = augmentList[augmentIndex].augmentSkill.cooldownTime;
}
break;
case AbilityState.cooldown:
if (augmentData.cooldownTime > 0)
{
augmentData.cooldownTime -= Time.deltaTime;
Debug.Log("TimeLeft: " +augmentData.cooldownTime);
}
else
{
augmentData.state = AbilityState.ready;
Debug.Log("state changed to: " + augmentData.state);
}
break;
}
}
In addition to AugmentAbility1, I have 2 other methods(AugmentAbility2,AugmentAbility3) where I pass in augmentData2 and augmentData3. I know I could easily use a foreach to pass those parameters in. The issue is that each AugmentAbility method has a different ability key.
if (Input.GetKey(abilityXKey))
The separate variables being:
ability1Key = Keycode.Alpha1
ability2Key = Keycode.Alpha2
ability3Key = Keycode.Alpha3
The three methods are currently sitting in my Update() like so, in order to catch the different key inputs.
Update()
{
AugmentAbility1(augmentData1);
AugmentAbility2(augmentData2);
AugmentAbility3(augmentData3);
}
Say hello to C# syntactic sugar in the form of Action and Func
In this case:
private void AugmentAbility(AugmentData augmentData,
KeyCode expectedKeyCode,
Action<AugmentData> completionWhenMatchedKey)
{
switch (augmentData.state)
{
case AbilityState.ready:
if (Input.GetKey(expectedKeyCode))
{
completionWhenMatchedKey(augmentData);
}
break;
case AbilityState.active:
if (augmentData.activeTime > 0)
{
augmentData.activeTime -= Time.deltaTime;
}
else
{
augmentData.state = AbilityState.cooldown;
augmentData.cooldownTime =
augmentList[augmentIndex].augmentSkill.cooldownTime;
}
break;
case AbilityState.cooldown:
if (augmentData.cooldownTime > 0)
{
augmentData.cooldownTime -= Time.deltaTime;
Debug.Log("TimeLeft: " +augmentData.cooldownTime);
}
else
{
augmentData.state = AbilityState.ready;
Debug.Log("state changed to: " + augmentData.state);
}
break;
}
}
// Now to call it:
public void Update() {
AugmentAbility(augmentData1, KeyCode.Alpha1, (augmentData) => {
augmentIndex = augmentData.index;
augmentList[augmentIndex].augmentSkill.Ability();
augmentData.state = AbilityState.active;
augmentData.activeTime = augmentList[augmentIndex].augmentSkill.activeTime;
});
AugmentAbility(augmentData2, KeyCode.Alpha2, (augmentData) => {
// Do sth else
});
AugmentAbility(augmentData3, KeyCode.Alpha3, (augmentData) => {
// Do sth entirely different
});
}
So in this class, I'm trying to use a switch statement to determine which radio button is checked in the form.
This is the part of the code that I'm focused on
private void lstTransactions_SelectedIndexChanged(object sender, EventArgs e)
{
int index = lstTransactions.SelectedIndex;
if (index != -1)
{
txtAmount.Text = entries[index, 0];
txtDate.Text = entries[index, 1];
chkCleared.Checked = bool.Parse(entries[index, 3]);
// entries[index, 2] is transaction type
//make switch comparison work correctly
// to determine which radio button should be checked
switch(entries[index, 2])
{
case TransactionTypes.Deposit.ToString():
rbDeposit.Checked = true;
break;
case TransactionTypes.Withdrawal.ToString():
rbWithdrawal.Checked = true;
break;
default:
rbServiceFee.Checked = true;
break;
}
}
}
Typing case TransactionTypes.Deposit.ToString(): and case TransactionTypes.Withdrawal.ToString(): gives me an error that says "CS0150 A constant value is expected". I tried looking up the error and I still can't figure out how to make the switch comparison work.
Here's the full Forms Code for Reference
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;
namespace Transaction3
{
public partial class CheckbookForm : Form
{
public CheckbookForm()
{
InitializeComponent();
}
enum TransactionTypes { Deposit, ServiceFee, Withdrawal }
TransactionTypes transactionType;
private string[,] entries = new string[20, 4];
decimal balance = 0m;
decimal bankBalance = 0m;
private void SetError(Control whichControl, string message)
{
errorProvider1.SetError(whichControl, message);
}
private decimal IsValid()
{
bool flag=true;
decimal amount = 0m;
DateTime date;
if (DateTime.TryParse(txtDate.Text,out date))
{
if (date>DateTime.Today)
{
flag=false;
SetError(txtDate,"Date must be on or before today");
}
}
else
{
flag=false;
SetError(txtDate,"Date must be entered");
}
if (decimal.TryParse(txtAmount.Text, out amount))
{
if (amount<=0)
{
flag=false;
SetError(txtAmount,"Amount must be more than zero");
}
}
else
{
flag = false;
SetError(txtAmount,"Amount must be a number more than zero");
}
if (flag)
{
if (transactionType == TransactionTypes.Withdrawal)
{
if (balance >= amount)
{
amount *= -1;
}
else
{
flag = false;
SetError(txtAmount, "Insufficient funds");
}
}
else if (transactionType == TransactionTypes.ServiceFee)
amount *= -1;
}
if (!flag)
amount = 0;
return amount;
}
private void ShowBalance()
{
lblBalance.Text = balance.ToString("c");
lblBankBalance.Text = bankBalance.ToString("c");
}
private void ClearForm()
{
txtAmount.Clear();
txtAmount.Focus();
txtDate.Clear();
rbWithdrawal.Checked = true;
}
private void CheckbookForm_Load(object sender, EventArgs e)
{
rbDeposit.Tag = TransactionTypes.Deposit;
rbWithdrawal.Tag = TransactionTypes.Withdrawal;
rbServiceFee.Tag = TransactionTypes.ServiceFee;
ClearForm();
ShowBalance();
}
private void btnProcess_Click(object sender, EventArgs e)
{
errorProvider1.Clear();
decimal amount = IsValid();
if (amount != 0)
{
string entry;
string process = "Not Processed";
balance += amount;
if (chkCleared.Checked)
{
bankBalance += amount;
process = "Processed";
}
ShowBalance();
int row = lstTransactions.Items.Count;
entries[row, 0] = amount.ToString();
entries[row, 1] = txtDate.Text;
entries[row, 2] = transactionType.ToString();
entries[row, 3] = chkCleared.Checked.ToString();
entry = string.Format("{0} {1}: {2} ({3})", transactionType.ToString(),
txtDate.Text, amount.ToString("c"), process);
lstTransactions.Items.Add(entry);
}
}
private void btnClear_Click(object sender, EventArgs e)
{
ClearForm();
}
private void btnReset_Click(object sender, EventArgs e)
{
errorProvider1.Clear();
DialogResult button;
button = MessageBox.Show("Clear all prior entries and set balance to $0?\nThis CANNOT be undone.",
"Reset Account", MessageBoxButtons.YesNo);
if (button == System.Windows.Forms.DialogResult.Yes) {
balance = 0;
bankBalance = 0;
ClearForm();
ShowBalance();
lstTransactions.Items.Clear();
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void rb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked)
transactionType = (TransactionTypes) rb.Tag;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
btnExit_Click(sender, e);
}
private void CheckbookForm_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult button;
button = MessageBox.Show("Close and exit? All entries will be lost.",
"Exit?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (button == System.Windows.Forms.DialogResult.Cancel)
e.Cancel = true;
}
private void lstTransactions_SelectedIndexChanged(object sender, EventArgs e)
{
int index = lstTransactions.SelectedIndex;
if (index != -1)
{
txtAmount.Text = entries[index, 0];
txtDate.Text = entries[index, 1];
chkCleared.Checked = bool.Parse(entries[index, 3]);
// entries[index, 2] is transaction type
//make switch comparison work correctly
// to determine which radio button should be checked
switch(entries[index, 2])
{
case TransactionTypes.Deposit.ToString():
rbDeposit.Checked = true;
break;
case TransactionTypes.Withdrawal.ToString():
rbWithdrawal.Checked = true;
break;
default:
rbServiceFee.Checked = true;
break;
}
}
}
}
}
You should ditch the multidimensional array and go with a typed List or Array.
Multidimensional arrays are useful when the data is of the same type, yours it a bit of everything. so we in turn would make a class.
public class Entry
{
public Entry(decimal amount, DateTime date, TransactionType transactionType, bool cleared)
{
Amount = amount;
Date = date;
TransactionType = transactionType;
Cleared = cleared;
}
public decimal Amount { get; set; }
public DateTime Date { get; set; }
public TransactionType TransactionType { get; set; }
public bool Cleared { get; set; }
}
Given
// now an array of Entry
private Entry[] entries = new Entry[20];
Usage
To update update an entry
// add / update and array slot
entries[row] = new Entry(amount, DateTime.Parse(txtDate),transactionType,chkCleared.Checked);
Your switch would look like this
switch (entries[index].TransactionType)
{
case TransactionTypes.Deposit:
rbDeposit.Checked = true;
break;
case TransactionTypes.Withdrawal:
rbWithdrawal.Checked = true;
break;
default:
rbServiceFee.Checked = true;
break;
}
Note : This is not meant to be a working example, or to make your code work, it was merely showing you how you could used a typed array to make your life easier and show a potential for the switch without having to parse your string back into an enum
Alternatively you could just use Enum.Parse
Converts the string representation of the name or numeric value of one
or more enumerated constants to an equivalent enumerated object.
var tranType = (TransactionTypes)Enum.Parse(typeof(TransactionTypes), entries[index, 2]);
switch(tranType)
The error you are facing, has nothing to do with multidimensional arrays. It is due to using a runtime value inside a case logic.
You cannot use case TransactionTypes.Withdrawal.ToString() as a case statement. The last part ToString() is a function call. Even though it will always return the same value, the compiler does not know that. It will always think that the value of case TransactionTypes.Withdrawal.ToString() is not known at compile time, and thus is a potential risk for runtime error and thus will not compile.
You might wanna think what is the harm in having a runtime value. Consider the following code -
switch (entries[index].TransactionType)
{
case TransactionTypes.Withdrawal.ToString()://only known at wexecution not before that
throw a;
break;
case TransactionTypes.Withdrawal.ToString()://only known at wexecution not before that
throw b;
break;
default:
break;
}
Both the cases have same values. But the compiler cannot determine them unless it executes the code and when it will try to do that, there will be a clash in the decision. To save the code for such failure, having dynamic value in a switch-case is prohibited and that is the reason for that exception.
In future the compilers might be more intelligent to determine proper branching based on codes, but for now we are stuck with constant values for cases. So remove the function call or use Enum.Parse to get the enum values and do your check. Something like this -
if(Enum.TryParse<TransactionTypes>(entries[index, 2], true, out TransactionTypes parsed){
switch (parsed)
{
case TransactionTypes.Deposit://constant value, no issue
rbDeposit.Checked = true;
break;
case TransactionTypes.Withdrawal://constant value, no issue
rbWithdrawal.Checked = true;
break;
default:
rbServiceFee.Checked = true;
break;
}
}
else{
throw new Exception("Unknonw enum string");
}
get more details about Enum.Parse or Enum.TryParse here https://learn.microsoft.com/en-us/dotnet/api/system.enum.tryparse?view=netframework-4.8
I'm trying to save a simple app setting ("LanguagePairId") this way:
if (rdbtnEnglishPersian.IsChecked == true) // because "IsChecked" is a nullable bool, the "== true" is necessary
{
langPairId = 1;
}
else if (rdbtnEnglishGerman.IsChecked == true)
{
langPairId = 2;
}
else if (rdbtnEnglishSpanish.IsChecked == true)
{
langPairId = 3;
}
else if (rdbtnGermanSpanish.IsChecked == true)
{
langPairId = 4;
}
else if (rdbtnGermanPersian.IsChecked == true)
{
langPairId = 5;
}
else if (rdbtnSpanishPersian.IsChecked == true)
{
langPairId = 6;
}
AppSettings.Default.LanguagePairId = langPairId;
LanguagePairId is being assigned the expected value (if rdbtnEnglishSpanish is checked, it is assigned 3, etc.)
But trying to read the app setting value on app startup:
int langPairId;
public MainWindow()
{
InitializeComponent();
RecheckTheLastSelectedRadBtn();
}
private void RecheckTheLastSelectedRadBtn()
{
langPairId = AppSettings.Default.LanguagePairId;
switch (langPairId)
{
case 1:
rdbtnEnglishPersian.IsChecked = true;
break;
. . .
...fails -- AppSettings.Default.LanguagePairId is seen as 0 on restaring the app. Why? What must I do to get the value to be saved and restored?
I don't see a call to AppSettings.Default.Save() anywhere.
Without that, your changes to the settings won't be saved.
Try adding it immediately after you set the property. E.g.:
AppSettings.Default.LanguagePairId = langPairId;
AppSettings.Default.Save();
I'm making a Windows Form Application with VS 2010. I've added a ProgressBar to my form, and I change its value. However, the ProgressBar does not advance or change. I think one of the reasons is because the process is too fast, but I made it slow and it didn't work either.
Here's the code:
void pn_TenPercentProgressEvent(object sender, PrimeNumberEventArgs e)
{
probarPrimeNumber.Visible = true;
probarPrimeNumber.Value = (int)e.Percent * 100;
this.Refresh();
}
this is the class that event occurs:
public ulong[] Generate(int count)
{
ulong[] ulngaryResult = new ulong[count];
switch (count)
{
case 0:
{
throw new Exception("The Zero is NOT Permitted.");
}
case 1:
{
ulngaryResult[0] = 2;
break;
}
case 2:
{
ulngaryResult[1] = 3;
goto case 1;
}
default:
{
int intIndex = 0;
double dblPercent = 0.1;
for (ulong i = 2; i < ulong.MaxValue; i++)
{
if (this.IsPrime(i))
{
ulngaryResult[intIndex] = i;
intIndex++;
}
if (intIndex == (int)(dblPercent * count))
{
//Raise TenPercentProgressEvent
if (TenPercentProgressEvent != null) //Optional Event
{
TenPercentProgressEvent((object)this, new PrimeNumberEventArgs(intIndex, count, dblPercent));
}
dblPercent += 0.1;
}
if (intIndex == count)
{
//Raise FinishedProgressEvent
if (FinishedProgressEvent != null) //Optional Event
{
FinishedProgressEvent((object)this, new PrimeNumberEventArgs(intIndex, count, dblPercent));
}
break;
}
}
break;
}
}
return ulngaryResult;
}
Try (int)(e.Percent * 100). As it is, casting to int before multiplying by 100 rounds to either 0 or 1 - which then translates into either 0% or 100%, all the time, but never in between.
Currently we call a web service to check if user has permission to use the chat room and we receive a 0 or a 1. I want to add to also be able to receive a 2, which will indicate it is enabled and authorized now
so I want to use three state check boxes, fully filled will mean he is authorized and also currently enabled (logged in), check will mean he is authorized but not enabled now, unchecked will mean he doesn't have permission for this chat room.
Here is some code I currently use. FYI I took over this project from our developer and I'm kind of new to this, if you can give me an example even just for authtac1 then I'll figure out how to do all others, and also do I need to add a new field ActiveTac1 like I have AuthTac1? Thanks for your help.
public partial class IMeditor : Form
{
private IMuser imu;
private IMui IMui;
private IMdata IMdata;
public IMeditor(IMui IMui, IMuser U, string Member)
{
InitializeComponent();
this.IMui= IMui;
imu = U;
if (imu.UID == 0)
{
Add.Text = "Add";
imu.MemberNick= Member;
}
else
Add.Text = "Update";
IMdata = new IMdata();
MemberHandle.Text = imu.MemberHandle;
IM.Text = imu.IM;
AuthChat.Checked = imu.AuthChat == 1;
AuthTac1.Checked = imu.AuthTac1 == 1;
AuthTac2.Checked = imu.AuthTac2 == 1;
AuthTac3.Checked = imu.AuthTac3 == 1;
AuthTac4.Checked = imu.AuthTac4 == 1;
switch (imu.Transport.ToLower()) {
case "aim": Transport.SelectedIndex = 0; break;
case "gtalk": Transport.SelectedIndex = 1; break;
case "msn": Transport.SelectedIndex = 2; break;
case "yahoo": Transport.SelectedIndex = 3; break;
}
private void Add_Click(object sender, EventArgs e)
{
IMdata.AddIM(IMui.Username, IMui.Password, imu.UID, MemberHandle.Text, Transport.Text, IM.Text,
AuthChat.Checked ? 1 : 0, 0,
AuthTac1.Checked ? 1 : 0, AuthTac2.Checked ? 1 : 0, AuthTac3.Checked ? 1 : 0,
AuthTac4.Checked ? 1 : 0);
Close();
}
last question, to make sure I didnt screw up anything else
#competemt_tech this is what I ended up using (thanks so so much for your help, and our developer who was able to assist me)
To know how to set the checkboxes when i get the data from the webservice I used
AuthChat.CheckState = GetCheckStateFromAuthCode(imu.AuthChat, imu.Enabled);
AuthTac1.CheckState = GetCheckStateFromAuthCode(imu.AuthTac1, imu.Tac1Enabled);
AuthTac2.CheckState = GetCheckStateFromAuthCode(imu.AuthTac2, imu.Tac2Enabled);
AuthTac3.CheckState = GetCheckStateFromAuthCode(imu.AuthTac3, imu.Tac3Enabled);
and then I used:
private CheckState GetCheckStateFromAuthCode(int AuthCode, int Enabled)
{
switch (AuthCode + Enabled)
{
case 0:
return CheckState.Unchecked; // Unauthorized
case 1:
return CheckState.Checked; // Authorized, not enabled
case 2:
return CheckState.Indeterminate; // Authorized and enabled
default:
return CheckState.Unchecked;
}
}
and after I make changes, to send back to the webservice I used:
imu.AuthChat, imu.Enabled = GetAuthCodeFromCheckState(AuthChat.CheckState),
imu.AuthTac1, imu.Tac1Enabled = GetAuthCodeFromCheckState(AuthTac1.CheckState),
imu.AuthTac2, imu.Tac2Enabled = GetAuthCodeFromCheckState(AuthTac2.CheckState),
imu.AuthTac3, imu.Tac3Enabled = GetAuthCodeFromCheckState(AuthTac3.CheckState),
and then I used:
private int GetAuthCodeFromCheckState(CheckState checkState)
{
switch (checkState)
{
case CheckState.Unchecked: // Unauthorized
return 0;
case CheckState.Indeterminate: // Authorized, not enabled
return 1;
case CheckState.Checked: // Authorized and enabled
return 2;
default:
return 0;
}
}
Based on your code, it appears that you are using WinForms, not WPF, correct?
If this is the case, then you will want to use the CheckState property of the checkbox and not Checked, since it supports three values:
Unchecked = 0
Checked = 1
Indeterminate = 2
Update
In order to address your requirements, you would have code similar to the following:
First, create a function that will generate the correct checkstate base on the authcode:
private CheckState GetCheckStateFromAuthCode(int AuthCode)
{
switch (AuthCode)
{
case 0:
// Unauthorized
return CheckState.Unchecked;
case 1:
// Authorized, not enabled
return CheckState.Indeterminate;
case 2:
// Authorized and enabled
return CheckState.Checked;
default:
throw new ArgumentException("Unrecognized AuthCode value " + AuthCode.ToString());
}
}
Then, use this code to set the state of your checkboxes:
AuthChat.CheckState = GetCheckStateFromAuthCode(imu.AuthChat);
AuthTac1.CheckState = GetCheckStateFromAuthCode(imu.AuthTac1);
etc.
Update 2
In order to retrieve the authcode from the checkstate:
First, create a function that will generate the correct checkstate base on the authcode:
private int GetAuthCodeFromCheckState(CheckState checkState)
{
switch (checkState)
{
case CheckState.Unchecked:
// Unauthorized
return 0;
case CheckState.Indeterminate:
// Authorized, not enabled
return 1;
case CheckState.Checked:
// Authorized and enabled
return 2;
default:
throw new ArgumentException("Unrecognized checkState value " + checkState.ToString());
}
}
Then, use this code to set the auth code from your checkboxes:
imu.AuthChat = GetAuthCodeFromCheckState(AuthChat.CheckState);
imu.AuthTac1 = GetAuthCodeFromCheckState(AuthTac1.CheckState);
etc.