Populate an Array in VB - vb.net

I am writing a program for class that needs to ask the user for 3 different test scores from 3 different people and store that in an array. I am having issues with populating the array from the user input.
It should ask the user to enter in 3 scores for person 1, person 2, and person 3. Then Store it in a "three-element array of structure variables; each element will contain the test scores for one student"(to quote exactly what the book said).
Everything else I can do so any suggestions on how to tackle this would help me greatly.

There are many tutorials on Array
http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx
http://www.tutorialspoint.com/vb.net/vb.net_arrays.htm
Creating an Array
Dim scores(2) As Double 'this creates an array with 3 elements
Populating it
scores.SetValue(99.5, 0) 'SetValue(the score fetched from input box, index number)
...and so on
Good luck.

Related

Freemarker: Removing Items from One Sequence from Another Sequence

This may be something really simple, but I couldn't figure it out and been trying to find an example online to no avail. I'm basically trying to remove items found in one sequence from another sequence.
Example #1
Items added to the cart is in one sequence; items removed from cart is in another sequence:
<#assign Added_Items_to_Cart = "AAAA,BBBB,CCCC,DDDD,EEEE,FFFF">
<#assign Deleted_Items_from_Cart = "BBBB,DDDD">
The result I'm looking for is: AAAA,CCCC,EEEE,FFFF
Example #2
What if the all items added to and deleted from cart are in the same sequence?
<#assign Cart_Activity = "AAAA,BBBB,BBBB,CCCC,DDDD,EEEE,DDDD,FFFF,Add,Add,Delete,Add,Add,Add,Delete,Add">
The result I'm looking for is the same: AAAA,CCCC,EEEE,FFFF
First things first: You ask about sequence but the data you are dealing with are strings.
I know you are using the string to work as a sequence (and it works), but sequences are sequences and strings are strings, and they have diferente ways of dealing with. I just felt this was important to clarify if someone who is starting to learn how to program get to this answer.
Some assumptions since you're providing strings with data separated by comma:
You want a string with data separated by comma as a result.
You know how to properly create strings with data separated by comma.
You dont have commas in your items names.
Observations:
I'll give you the logic but not the code donne, as this can be a great chance for you to learn/practice freemarker (stackoverflow spirit, you know...)
You question is not about something specific of freemaker (it just happens to be the language you want to work with). Think about adding the logic tag to you question. :-)
Now to the answer on how to do what you want on a "string that is working as a sequence":
Example #1
Change your string to a real sequence :-)
1 - Use a built-in to split your string on commas. Do it for both Added_Items_to_Cart and Deleted_Items_from_Cart. Now you have two real sequences to work with.
2 - Create a new string tha twill be your result .
3 - Iterate over the sequence of added itens.
4 - For each item of the added list, you will check if the deleted list also contains this item.
4.1 - If the deleted list contains the item you do nothing.
4.2 - If the deleted list do not contains the item, you add that item to your string result
At the end of this nested iteration (thats another hint) you should get the result you're looking for.
Example #2
There are many ways of doing it and i'll just share the one that pops out of my mind right now.
I think it's noteworthy that in this approach you will always have an even sized list, as you always insert 2 infos each time: item and action.
So always the first half will be the 'item list' and the second half will be the 'action list'.
1 - Change that string to a sequence (yes, like on the other example).
2 - Get half of its size (in your example size = 16 so half of it is 8)
3 - Iterate over a range from 0 to half-1 (in your example 0 to 7)
4 - At each iteration you'll have a number. Lets call it num (yes I'm very creative):
4.1 - If at the position num + half you have the word "Add" you add the item of position num in your result string
4.2 - If at the position num + half you have the word "Delete" you remove the item of position num from your result string
And for the grand finale, some really usefull links that will help you in your freemarker life forever!!!
All built-ins from freemarker:
https://freemarker.apache.org/docs/ref_builtins.html
All directives from freemarker:
https://freemarker.apache.org/docs/ref_directive_alphaidx.html
Freemarekr cheatsheet :
https://freemarker.apache.org/docs/dgui_template_exp.html#exp_cheatsheet

Trying to understand and translate a small bit of VB code

I'm in the middle of transferring some VB code to another language, but I don't understand what's supposed to be happening here.
Dim foo(7,0) as Date
Then later in the code I get something like foo(5,3) and I believe the output to be a Date object. There is no function written to describe foo so I'm assuming it's a multi-dimensional array. But cast as a Date? I'm confused, please help.
I don't know what's going on their either, because this:
Dim foo(7,0) as Date
declares a two dimensional array that is effectively a one dimensional array because the second dimension has an upper bound of 0...
... and then you claim that the second dimension is later indexed with 3, which is outside the bounds. foo(5, 0) would be fine, but the sixth row (if you want to think of the 5 that way) has 1 column, so retrieving the fourth is an IndexOutOfRangeException. Presumably this has been ReDim'd at some point between then and now
To have the debugger help you out, run the code, stop on it and point to foo or look in the LOCALS window:
Bounded in red is the variable analyzer as a tooltip and in the locals. It shows Date to be a 2D array. It also helpfully lists all the contents. Bounded in blue is the error you get if you try and access index 3 of an array that stops at index 0
Make that 2D array actually have an appreciable width:
And you can see it's just a block of Date

Xcode - Objective C- How to make a dictionary of persons?

I can't get my head around my objective C code. I want to make a dictionary with persons that I save in the app. The dictionary is in first empty and then we need to add it from the textfields I created (see image)textfieldWelkom
For every person that is added, we have to show it in a list (see image) lijstTabblad in the tableviewcontroller. (The list has to be the whole name of the person)
I don't get the idea of how to making a dictionary with multiple persons with every person his own ELEMENTS. And how that I can get the elements again out of de dictionary for making the list etc..
(not like the 1 example but multiple values with that person)
I would be sow thankfull if you could help me!
Greetings,
Kevin
You needs to first create single person dictionary dictionary keys
are like name sirname age and put values for respected keys
add this dictionary in one array or another dictionary(array/dictionary must be mutable array)

Objective C - Attribute values into Variables

I'm new to objective-C, having a programming background mainly in C++, and believe this to be an easy question although I can't find the answer to what I'm looking for. I'm using Xcode 6 as of now.
I have an entity "Song" in which I have various attributes, "Description", "Tempo", etc. My tempo attribute, for example, is limited to integers, and I want to be able to manipulate any/all of those tempo values for each Song at a given time. Upon a dedicated button click, I want to either edit the values or put all of the values in an array (array[0] = Song 1 Tempo, array[1] = Song 2 Tempo, etc), so mainly I need to get those individual values into variables, or so I think.
I feel as though my limited knowledge of attributes and entities is preventing me from being able to connect the bridge between them and variables, the latter of which I'm used to working with in C++, of course. Any suggestions or tips would be much appreciated, thanks in advance!
Pat
Your attribute will return collection type object like dictionary or array. So you can iterate your attributes values and just add in NSMutableArray.

Associative arrays for grandmothers using awk

I have a really hard time wrapping my head around arrays and associative arrays in awk.
Say you want to compare two different columns in two different files using associative arrays, how would you do? Let's say column 1 in file 1 with column 2 in file two, then print the the matching, corresponding values of file 1 in a new column in file 2. Please explain each step really simply, as if talking to your grandmother, I mean, super-thoroughly and super-simple.
Cheers
Simple explanation of associative arrays (aka maps), not specifically for awk:
Unlike a normal array, where each element has a numeric index, an associative array uses a "key" instead of an index. You can think of it as being like a simple flat-file database, where each record has a key and a value. So if you have, e.g. some salary data:
Fred 10000
John 12000
Sara 11000
you could store it in an associative array, a, like this:
a["Fred"] = 10000
a["John"] = 12000
a["Sara"] = 11000
and then when you wanted to retrieve a salary for a person you would just look it up using their name as the key, e.g.
salary = a[person]
You can of course modify the values too, so if you wanted to give Fred a 10% pay rise you could do it like this:
a["Fred"] = a["Fred"] * 1.1
And if you wanted to set Sara's salary to be the same as John's you could write:
a["Sara"] = a["John"]
So an associative array is just an array that maps keys to values. Note that the keys do not need to be strings, and the values do not need to be numeric, but the basic concept is the same regardless of the data types. Note also that one obvious constraint is that keys need to be unique.
Grandma - let's say you want to make jam out of strawberries, raspberries, and blueberries, one jar of each.
You have a shelf on your wall with room/openings for 3 jars on it. That shelf is an associative array: shelf[]
Stick a label named "strawberry" beneath any one of the 3 openings. That is the index of an associative array: shelf["strawberry"]
Now place a jar of strawberry jam in the opening above that label. That is the contents of the associative array indexed by the word "strawberry": shelf["strawberry"] = "the jar of strawberry jam"
Repeat for raspberry and blueberry.
When you feel like making yourself a delicious sandwich, go to your shelf (array), look for the label (index) named "strawberry" and pick up the jar sitting above it (contents/value), open and apply liberally to bread (preferably Mothers Pride end slices).
Now - if a wolf comes to the door, do not open it in case he steals your sandwich or worse!