I want to compare an exam grade to the content of a listbox .
e.g
textbox.text = "ABCDABCDAB"
and the listbox contains (Jean,ABCDABCDAB, John,ABCCBBCCAB, Kirou,BBCDABCDAB).
How do I write the program to read the textbox content and compare it to the listbox content. Hope I am clear enough. Can anybody help please? in Visual Basic 2010
Don't know how to write it in VB but I'm sure you'll be clever enough to translate it from C#
if( listBox1.Items.Contains(textbox.Text) )
// hurray!
else
// :( no such item
In VB.NET you have to write it like this:
If ListBox1.Items.Contains(TextBox1.Text) = True Then Msgbox("Item exists")
I hope this is going to help you
You can try this :
if (ListBox1.Items.Contains(TextBox1.Text))
{
MsgBox.Show("Yay! Item exists.");
}
else
{
MsgBox.Show("Oops! No such item exists.");
}
Related
i want to make a variable can be used in .caption, so i can get the value and used it to make something.
last experiment, i use it in foxpro and it can work pretty well.
like this.
foxpro code mix variable with system
tmbl = "command"+alltrim(str(i)) set order to no_room seek
(thisform.pageframe1.page1.&tmbl..caption
see the &tmbl.?? im using it as a connector to .caption
now im trying to do it in VB.NET. it can not work. i don't know what kind connector must be use in VB.NET. so can somebody please tell what must to use in VB.NET?
You can simply use controls collection to find the control you want (and even in VFP it is the way to go, instead of abusing the & operator). Say you want to do this for a label, in C# it looks like:
var label = this.Controls.OfType<Label>()
.SingleOrDefault(c => c.Name == "command" + i);
if (label != null)
{
label.Text = "Whatever";
}
Telerik code converter converts this to VB.Net as:
Dim label = Me.Controls.OfType(Of Label)().SingleOrDefault(Function(c) c.Name = "command" + i)
If label IsNot Nothing Then
label.Text = "Whatever"
End If
I'm trying to make a program where there are multiple forms. Now what I would like to accomplish is that, whenever I open another form, the current form will close but I would like to do that without the forms having to vanish with an effect. Is there a way in the properties to do that? I tried changing the DoublBuffered into TRUE but it has no effect (I mean, the effect was still there). Can somebody point me to the right direction please? Thanks in advance. :D
By the way, I'm using:
Form2.Show()
Me.Close()
I haven't tried it out, but you can use the following. Assuming you have 2 Forms(1,2)
private void Form1_Load(Object sender, EventLog e)
{
if((bool)Form1.ActiveForm)
{
Form1.Visible = true;
Form2.Visible = false;
// Rest of your code to display
}
if((bool)Form2.ActiveForm)
{
Form1.Visible = false;
Form2.Visible = true;
// Rest of your code to display
}
}
Use this,
Form1.Opacity = 0
Here are places to add it. First set Form 2 opacity as 0 in visual studio. and then go to the form load and after loading all the things you need put in,
Form2.Opacity = 100
Then before form 1 closing put in,
Me.Opacity = 0
You just need to know where to set to 0 and where to 100. It will work good. But I am not sure why you don't want that effect.
So I've coded a VSTO addin using vb.net to add a header to a document in Word however from historical methods we have lots of templates with field codes. My addin does not account for these and simply strips the header to add xxxxx value you choose from the pop up.
I need my code to be smart enough to 'spot' the field code and append or if it does not exist e.g. a blank document then continue running as expected. I can append this field code using the below code:
wordDocument.Variables("fieldname").Value = "xxxx"
wordDocument.Fields.Update
However my tool then adds the header as normal and strips most the content from the template. So effectively my question is how would I code a check for this before proceeding. So in plain English I would need my addin to go from this:
Load pop up
Set xxxx value in header
Close
To this:
Load pop up
Check Document for existing "fieldname"
If "fieldname" exists then
wordDocument.Variables("fieldname").Value = "xxxx" (from pop up selection)
wordDocument.Fields.Update
However if "fieldname" doesn't exist then continue as normal....
Sorry if this is a little complex and/or long winded.
Thanks in advance.
Here is my code in C#, hope this might help you to code in VB.Net
foreach (Section sec in doc.Sections)
{
doc.ActiveWindow.View.set_SeekView(WdSeekView.wdSeekCurrentPageHeader);
foreach (HeaderFooter headerFooter in sec.GetHeadersFooters())
{
doc.ActiveWindow.View.set_SeekView(headerFooter.IsHeader ? WdSeekView.wdSeekCurrentPageHeader : WdSeekView.wdSeekCurrentPageFooter);
if (headerFooter.Range.Fields.Count > 0)
{
//Append to existing fields
UpdateFields(headerFooter.Range.Fields);
}
else
{
//Add field code
AddFieldCode(headerFooter.Range);
}
}
doc.ActiveWindow.View.set_SeekView(WdSeekView.wdSeekMainDocument);
}
Extension method to iterate through the header types
public static IEnumerable<HeaderFooter> GetHeadersFooters(this Section section)
{
List<HeaderFooter> headerFooterlist = new List<HeaderFooter>
{
section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary],
section.Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage],
section.Headers[WdHeaderFooterIndex.wdHeaderFooterEvenPages],
section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary],
section.Footers[WdHeaderFooterIndex.wdHeaderFooterFirstPage],
section.Footers[WdHeaderFooterIndex.wdHeaderFooterEvenPages]
};
return headerFooterlist;
}
As the title states, I need to use NCalc in Visual Studio 2010. I am writing a program that will calculate a multi-step math problem in VB, but I'm not quite sure how I'd use NCalc. The user inputs a math problem into a text box, then clicks a button which will tell the program to calculate the answer. I've already added NCalc as a reference, and imported it into the project, I'm just not sure what to do next.
You'd need to add, at the top of your file:
using NCalc.Domain;
You could then write something in a button press like:
Expression exp = new Expression(textBox1.Text); // Get the text box text
try
{
object result = exp.Evaluate();
textBox2.Text = result.ToString(); // Place the "answer"
}
catch(EvaluationException e)
{
// This happens if the user enters a "bad" expression
textBox2.Text = "Unable to compute: " + e.Message;
}
For details, see the examples on NCalc's homepage.
I'm trying to use two devExpress checkedComboBoxes (boxes) to maintain a list and its antilist (i.e, same items in both comboboxes, and they must be checked in only one of the lists).
I'm using C++/CLI, so for each box I handle
EditValueChanged += gcnew System::EventHandler(this, &SelectionControl::exclBox_EditValueChanged);
which calls through to
void
box_ToggleAntibox(
DevExpress::XtraEditors::CheckedComboBoxEdit^ box,
DevExpress::XtraEditors::CheckedComboBoxEdit^ antibox )
{
using namespace DevExpress::XtraEditors::Controls ;
cli::array<String ^> ^ sAnti = gcnew cli::array<String ^>(2*box->Properties->Items->Count) ;
int ii = 0;
String ^ delim = ", ";
for each (CheckedListBoxItem^ i in box->Properties->GetItems()) {
if (i->CheckState==Windows::Forms::CheckState::Unchecked)
{
sAnti[ii] = i->Value->ToString();
++ii;
sAnti[ii] = delim;
++ii;
}
}
String ^ result = String::Concat(sAnti);
antibox->EditValue = result;
}
As the devExpress documentation seems to say to set the edit value, rather than simply iterating through the box list and setting the anti-list to !Checked.
However, it doesn't seem to be working (the correct items are added to the text window, but nothing is checked). Moreover, if I look at my box after the event has finished, I find that the string value in the text window is correct (reflects what I'd selected), but if I open it up, then all items are selected.
Does anyone have any suggestions I might try?
Is it better to set each item's CheckState::Checked instead?
Thanks!
I spent some time talking to DevExpress support. The short answer is that this should work - but doesn't for us. Your mileage may vary, but our solution was to put the two comboboxes on to separate controls on the form.