For int i = value [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to create some code that search for a value .
As of now the code looks like :
private void button4_Click(object sender, EventArgs e)
{
uint randBuff = DLL.Extension.ReadUInt32(0x0154d6e4);
for (int i = 0; i < 144705; i++)
{
randBuff = (randBuff + 4);
listBox1.Items.Add(randBuff.ToString("x8"));
}
}
The value I search is 144705 . The idea is to stop searching for the value when randBuff =144705 . Can this be done with a loop or is there any other way to do it ?

If I understand your question right, then this is more appropriate of a loop:
while (randBuff < 144705)
{
listBox1.Items.Add(randBuff.ToString("x8"));
randBuff += 4;
}
Basically, as long randBuff is less than the target value of 144705, add the value to the list box and increase the value by 4.

Related

Operator '-' cannot be applied to operands of type 'string' and 'float' [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Im new at c# and i have error CS0019 I dont know how to fix it
i wanna make math program with substract and i wanna make my program logic:
if you pressed button textbox number will substract and show result in text box.
private void button1_Click(object sender, EventArgs e)
{
float num = 1
textBox1.Text - num ;
}
You need to convert the contents of textBox1. Try this:
private void button1_Click(object sender, EventArgs e)
{
double num1 = 1;
double num2 = Convert.ToDouble(txtBox1.Text);
double result = num2 - num1;
txtBox1.Text = result.ToString(); //Or whatever other text box you want to put this in
}

How do increment an integer that is part of a string at each iteration of loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i have a string like this S02E01 and now i want to run it through a loop like 20 times but at each iteration i want to increment the number after 'E' so that we have for example S02E01,S02E02,S02E03 ..S0210,...S02E20. Please help me.
Its really simple by using some string functions: Substring, PadLeft or ToString
string mystring = "S02E00";
var template = mystring.Substring(0, mystring.Length - 2);//template = "S02E"
for(int i = 0;i <= 20; i++)
{
var result = template + i.ToString("00");
Console.WriteLine(result);
}
you could use PadLeft too => var result = template + i.ToString().PadLeft(2, '0');

I cant increment value by 2 or more than 2 [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 5 years ago.
Improve this question
How do i increment a value by 2 instead of 1? when i run my code it will go from 1-10 by adding 1 but i want it to go 1-10 by adding 2
for (int x=0;x<10;x++)
{
Console.WriteLine(x);
}
You can do instead -
for (int x = 0; x < 10;) {
Console.WriteLine(x);
x = x + 2;
}
If I understand you correctly, this should be the solution for you.
for (int x = 0; x < 10; x += 2)
{
Console.WriteLine(x);
}

WPF how to get Selected Indices Of ListBOx [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
for (int x = added_signals_listbox.SelectedItems.Count - 1; x >= 0; x--)
{
SignalViewModel SelectedItem = added_signals_listbox.SelectedItems[x] as SignalViewModel;
int SelectedItemIndex = added_signals_listbox.Items.IndexOf(SelectedItem);
//ListBoxItem container = added_signals_listbox.SelectedItems.Item.ContainerFromItem(SelectedItem) as ListBoxItem;
//int SelectedItemIndex = added_signals_listbox.ItemContainerGenerator.IndexFromContainer(container);
_GraphViewerViewModel.AddedSignals.RemoveAt(SelectedItemIndex);
}
The commented code doesn't run, and I don't remember what I was trying to ask yesterday. Sorry about the poor question. I think I must have copy and pasted the wrong code. Please close the question.
Listbox for instance
<ListBox Name="listbox" SelectionChanged="changed" SelectionMode="Multiple">
<ListBox.Items>
<ListBoxItem>one</ListBoxItem>
<ListBoxItem>two</ListBoxItem>
</ListBox.Items>
</ListBox>
private void changed(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
for (int index = 0; index < listbox.SelectedItems.Count; index++)
listbox.Items.Remove(listbox.SelectedItems[index]);
}
When you select any item it will be deleted right away, is that what you wanted to acquire?

how to achieve for loop IronPython [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How to achieve this C# for-loop in IronPython, I can't seem to find a way to make i - 10 in IronPython
int amount = 32;
int scrolls = 0;
int mets = 0;
if (amount >= 10) {
for (int i = amount; i >= 10; i -= 10) {
scrolls++;
if (i - 10 < 10)
mets = i - 10;
}
}
Your loop exit condition is i >= 10. Your loop entry condition is amount >= 10. i gets set to your amount on loop entry, which is already >= 10. Your loop will never execute.

Categories

Resources