VB.Net Events Practice Help - vb.net

I was given an assignment to "write a program to print only even numbers between 6 and 16 using events", but I don't even know where to begin. The main thing I am having difficulty with understanding in this assignment is how I am supposed to specify that it only print even numbers in the given range of numbers.
Am I going to have to do a Mod2 code for each individual number and have it exclude any with the result of 1? Or is there another piece of code specifically designed for such an occassion? Perhaps there is some type of equation I can have the program read in terms of a variable, which holds the values of 6, 8, 10, 12, 14, and 16? I am just genuinely confused on how this is supposed to be programmed. Any assistance would be greatly appreciated.

No offense, but I'm not at all convinced that you are accurately relaying you assignment, but...
Firstly, using MOD is a good starting point, particularly as you are supposedly tying this in with events...
To use events as part of your solution, I would suggest creating a textbox withevents and a handler for textchanged, then in a loop set the txtbox.Text property to the string representation of the loop index (say going from 1 to 20), then inside the textchanded event turn the propery back into an integer, check to see if it's within the proper range and even(using, as you suggested, MOD).

The following will help you solving a part of the problem:
Dim number as Integer = 6
While number <= 16
// PRINT Goes here ..
number = number + 2
End While

These Microsoft links are good learning resources:
Learning Visual Basic from the Ground Up
Getting Started with Visual Basic
Video How to: Creating Your First Visual Basic Program
Events in Visual Basic
Closer Look: Understanding Properties, Methods, and Events
Events and Event Handlers

Related

How to create a program to convert unit measurements

Using Microsoft access, visual basic.
I'm having a big problem doing this task.
What I have done: Created a table on access where I have put measurements in (from meters):
mile = 10000meters, nautic mile = 1862meters, English mile=1652, kilometers = 1000 meters and all the way down to Millimeters.
What I have created for input:
1 box takes an Integer to be converted and a 1 box specified with an initial unit.
What I have created for Output:
1 box shows the Integer of result with 1 box specified the chosen unit of the output.
Can anyone please, please help me with the codes?
Honestly I'd never really noticed the CONVERT function until today but here's a quick demo of how I'd slap together a "conversion tool" in Excel.
If you want to do the same thing in Access, the premise is the same, but it will be a bit more work since you'll have to design the form from scratch instead of using a worksheet, which is kind of meant for this kind of job.
Using Excel functions in Access
Before you are able to use Excel's CONVERT function in Access, you'll need to reference the Microsoft Excel Object Library.
In Access, open any VBA Module.
GoTools > References
Check the box next to Microsoft Excel 16.0 Object Library. (The version number will vary if you have an older version of Office.)
Then you can call most Excel functions from Access VBA or queries with WorksheetFunction (the same way you would use them in Excel VBA).
For example:
MsgBox WorksheetFunction.Convert(3.7, "m", "ft")
...displays a message box with the number of feet in 3.7 metres.
The calculations will be the easy part; a couple lines of VBA in the On Change or On Exit events will trigger the calculation.
The most time-consuming part will likely be perfecting the placement and formatting of the controls on the form, which is by no means difficult (and there are several tutorials online that can provide the basics if necessary.)
Lastly, keep in mind that there are no doubt a plethora of existing conversion tools available for free download with a little Googling... (I'm confident that you're not the first person who wanted to use MS Office to convert measurements.) 😉
More Information:
Microsoft Docs : WorksheetFunction.Convert Method
Microsoft Docs : List of Worksheet Functions Available to Visual Basic
Office Support : Create a form in Access
QuackIt: Microsoft Access Tutorial
Blueclaw : Access Event Procedures
You can download the demo xlsx used above from JumpShare here.
For both comboboxes, bind them to column 2, faktorTilMeter, and set the ColumnWidths to, say: 2,542cm;0cm.
Then, assign this expression as ControlSource for your output textbox:
=TextboxInput/ComboboxFrom*ComboboxTo

In VB.net is there an option to force generation of the counter variable in the "Next" statement?

Visual Basic .net automatically inserts a "Next" statement when you enter a "For" statement; e.g., if I type:
For i as integer = 1 to 10
a Next will automatically be inserted, so that the code looks like:
For i as integer = 1 to 10
Next
It is optional to put the counter variable ("i" in the above) in the Next statement, so that it would read:
Next i
I'd really like to make this the default, as it really helps when one has nested For statements. I can't find anything in the Visual Studio settings to do this; maybe it's partly buried somewhere in Intellisense. I thought perhaps someone out there has already figured this out.
You will want to modify the .snippet file associated with the pattern. For the one you are looking for it is, by default:
VisualStudioInstallDirectory\VB\Snippets\1033\common code patterns\conditionals and loops\ForEachNext.snippet
You can also track down the exact location by looking in
Tools > Code Snippets Manager..., select Visual Basic for the language and browse to Code Patterns - If, For Each, Try Catch, Property, etc - the file location will be listed there.

VB.net Loop adding to combobox

Spent about an hour now, with multiple rages at my monitor. I have a variable which stores the amount of elements within an array.
I want to add the numbers '1' up to this variable number to a combobox. So that when i use the combobox, it gives the options of 1,2,3 etc up to the variable number. If anyone could help, that would a fantastic!!
Also, I tried a few different loops but caused visual studio to give an unable to access debug error when i tried to run the program. I am new to this so apologies if this seems basic.
The code I have below stores the count.
accno = custdetails.Count
You don't need to write the loop. This is a one-liner:
MyCombobox.Items.AddRange(Enumerable.Range(1, accno).ToArray())
I prefer that because it starts you thinking in terms of matching your presentation to a data source, which will help you a lot as you learn further.
But if you really want to:
For i As Integer = 1 to accno
MyCombobox.Items.Add(i)
Next

Editing contents of a labview array

I'm trying to increment specific elements by 1, in order to log results as they come in. I'm trying to read an element, add 1 to it, and then write it back to the same memory address. Why isn't this simple?
In code it would be something as simple as;
array1[element1] = (array1[element1]+1)
or
array1[element1]++
Arrays seem to be either read (indicators) or write (controls)? This is really frustrating, and there's very little help online.
You can use an "Array index/replace" element inside a "In place element structure":
You should use ReplaceArraySubset in the Array palette. For simple replacements, it's much faster than the In Place Element Structure
As an infrequent, novice Labview user I have the same problem ... until I found the code that I used 10 years ago. Surely the answer to sgccarey is:-
Right click on the array control or indicator and 'create local variable'
This variable will appear on the block diagram and can be set as 'Change to Write' or 'Change to Read' as necessary to use as the input and / or output array to a simple 'replace array subset'.
This way the array data only appears once on the Front Panel and is updated as required.
I have no idea if using Local Variables affects runtime efficiency but it works for me. Hope this helps.

Calculating multi-step math in a text box. - Visual Basic

I would like an application that I am creating in Visual Studio 2010 to be able to calculate a multi-step math problem that has been entered by the user into one whole text box.
ex. 3 * 55 / 7 ^ 2
The user would click a button, and the program would calculate the answer to the problem that they input. I was thinking something along the lines of:
Dim sngAnswer As Integer
sngAnswer = Val(Me.txtInput.Text)
But that doesn't work. Any ideas?
There is nothing included in the framework which will do this type of expression evaluation automatically.
You will likely want to use an expression parsing library to handle the math expression. NCalc and FLEE are both good options for this.