Sunday, May 24, 2020

The Useful Generic List in VB.NET

Generics extend the power and flexibility of VB.NET in a lot of areas, but you get a bigger performance benefit and more programming options in the generic List object [List(Of T)] than with any other. To use List(Of T), you have to understand how to implement the many methods that the .NET Framework provides. Below are three examples using ForEach, FindAll, and Sort, that demonstrates how the generic List class works. The very first step is to create a generic List. You can get the data in a lot of ways, but the simplest is to just Add it. The code below shows how to classify my beer and wine collection! Starting Code There first needs to be an object that will represent a bottle from the collection. In a Windows Forms application, the Form class has to first be in a file or the Visual Studio designer wont work correctly, so put this at the end: Public Class Bottle Public Brand As String Public Name As String Public Category As String Public Size As Decimal Public Sub New( _ ByVal m_Brand As String, _ ByVal m_Name As String, _ ByVal m_Category As String, _ ByVal m_Size As Decimal) Brand m_Brand Name m_Name Category m_Category Size m_Size End Sub End Class To build the collection, Add the items. This is whats in the Form Load event: Dim Cabinet As List(Of Bottle) _ New List(Of Bottle) Cabinet.Add(New Bottle( _ Castle Creek, _ Uintah Blanc, _ Wine, 750)) Cabinet.Add(New Bottle( _ Zion Canyon Brewing Company, _ Springdale Amber Ale, _ Beer, 355)) Cabinet.Add(New Bottle( _ Spanish Valley Vineyards, _ Syrah, _ Wine, 750)) Cabinet.Add(New Bottle( _ Wasatch Beers, _ Polygamy Porter, _ Beer, 355)) Cabinet.Add(New Bottle( _ Squatters Beer, _ Provo Girl Pilsner, _ Beer, 355)) All of the above code is standard code in VB.NET 1.0. However, note that by defining your own Bottle object, you get the benefits of multiple types in the same collection (in this case, both String and Decimal) and efficient, type safe late binding. ForEach Example The fun starts when we use the methods. To begin, lets implement the familiar ForEach method. The Microsoft documentation includes this usage syntax definition: Dim instance As List Dim action As Action(Of T) instance.ForEach(action) Microsoft further defines action as delegate to a method that performs an action on the object passed to it. The elements of the current List(T) are individually passed to the Action(T) delegate. Tip: For more on delegates, read Using Delegates in Visual Basic .NET for Runtime Flexibility. The first thing you need to code is the method that will be delegated. Misunderstanding this one key point is the source of most of the confusion of VB.NET students. This function, or subroutine, is where all of the customized coding for the Of type objects is done. When performed correctly, youre essentially done. Its really simple in this first example. An entire instance of the Bottle is passed and the subroutine selects anything needed out of it. Coding the ForEach itself is simple too. Just fill in the address of the delegate using the AddressOf method. Sub displayBottle(ByVal b As Bottle) ResultList.Items.Add( _ b.Brand - _ b.Name - _ b.Category - _ b.Size) End Sub Private Sub ForEachButton_Click( ... ResultList.Items.Clear() ResultList.Items.Add(For Each Example) ResultList.Items.Add(-----------------------) Cabinet.ForEach(AddressOf displayBottle) End Sub FindAll Example FindAll is a little more complicated. The Microsoft documentation for FindAll looks like this: Dim instance As List Dim match As Predicate(Of T) Dim returnValue As List(Of T) returnValue instance.FindAll(match) This syntax includes a new element, Predicate(Of T). According to Microsoft, this will represent the method that defines a set of criteria and determines whether the specified object meets those criteria. In other words, you can create any code that will find something in the list. I coded my Predicate(Of T) to find anything in the Beer Category. Instead of calling the delegate code for each item in the list, FindAll returns an entire List(T) containing only the matches that result from your Predicate(Of T). Its up to your code to both define this second List(T) and do something with it. My code just adds the items to a ListBox. Private Sub FindAllButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindAllButton.Click ResultList.Items.Clear() ResultList.Items.Add(FindAll Example) ResultList.Items.Add(-----------------------) Dim sublist As List(Of Bottle) sublist Cabinet.FindAll(AddressOf findBeer) For Each r As Bottle In sublist ResultList.Items.Add( _ r.Brand - _ r.Name - _ r.Category - _ r.Size) Next End Sub Function findBeer(ByVal b As Bottle) _ As Boolean If (b.Category Beer) Then Return True Else Return False End If End Function Sort Example The final method this article examines is Sort. Again, Microsoft uses some terminology you might not be familiar with. There are actually four different overloads of the Sort method: Sort()Sort(IComparer(T))Sort(Comparison(T))Sort(Int32, Int32, IComparer(T)) This lets you use sort methods defined in the .NET Framework for the list, code your own, use a system defined comparison for the type, or sort part of the collection using a starting position and count parameter. In this example, since I use the following syntax to actually perform the sort, Im using the third overload. x.Name.x.Name.CompareTo(y.Name)(y.Name) Ive coded another delegate to my own comparer. Since I want to sort by my Name, I pull just that value out of each instance of the Bottle object that is passed and use the Sort(Comparison(Of (T))). The Sort method actually rearranges the original List(T). Thats what is processed after the method is executed. Private Sub SortButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SortButton.Click ResultList.Items.Clear() ResultList.Items.Add(Sort Example) ResultList.Items.Add(-----------------------) Cabinet.Sort(AddressOf sortCabinet) For Each r As Bottle In Cabinet ResultList.Items.Add( _ r.Name - _ r.Brand - _ r.Category - _ r.Size) Next End Sub Private Shared Function sortCabinet( _ ByVal x As Bottle, ByVal y As Bottle) As Integer Return x.Name.CompareTo(y.Name) End Function These methods were selected to demonstrate the major ways that the Framework methods in List(T) are actually coded. Theres a whole raft of other methods, however. Thats what makes List(T) so useful!

Wednesday, May 13, 2020

Mohs Scale of Hardness - Identify Rocks Minerals

There are many systems used to measure hardness, which is defined several different ways. Gemstones and other minerals are ranked according to their Mohs hardness. Mohs hardness refers to a materials ability to resist abrasion or scratching. Note that a hard gem or mineral is not automatically tough or durable. About the Mohs Scale of Mineral Hardness The Mohs (Mohs) scale of hardness is the most common method used to rank gemstones and minerals according to hardness. Devised by German mineralogist Friedrich Moh in 1812, this scale grades minerals on a scale from 1 (very soft) to 10 (very hard). Because the Mohs scale is a relative scale, the difference between the hardness of a diamond and that of a ruby is much greater than the difference in hardness between calcite and gypsum. As an example, diamond (10) is about 4-5 times harder than corundum (9), which is about 2 times harder than topaz (8). Individual samples of a mineral may have slightly different Mohs ratings, but they will be near the same value. Half-numbers are used for in-between hardness ratings. How to Use the Mohs Scale A mineral with a given hardness rating will scratch other minerals of the same hardness and all samples with lower hardness ratings. As an example, if you can scratch a sample with a fingernail, you know its hardness is less than 2.5. If you can scratch a sample with a steel file, but not with a fingernail, you know its hardness is between 2.5 and 7.5.   Gems are examples of minerals. Gold, silver, and platinum are all relatively soft, with Mohs ratings between 2.5-4. Since gems can scratch each other and their settings, each piece of gemstone jewelry should be wrapped separately in silk or paper. Also, be wary of commercial cleaners, as they may contain abrasives that could damage jewelry. There are a few common household items on the basic Mohs scale to give you an idea of how hard gems and minerals really are and for use in testing hardness yourself. Mohs Scale of Hardness Hardness Example 10 diamond 9 corundum (ruby, sapphire) 8 beryl (emerald, aquamarine) 7.5 garnet 6.5-7.5 steel file 7.0 quartz (amethyst, citrine, agate) 6 feldspar (spectrolite) 5.5-6.5 most glass 5 apatite 4 fluorite 3 calcite, a penny 2.5 fingernail 2 gypsum 1 talc

Wednesday, May 6, 2020

Chalice Chapter 7 Free Essays

â€Å"I remember seeing you once when you were a boy,† she replied, not adding that she was trying to find that boy in his face now, and failing. â€Å"You trotted past my mother and me, and nodded and smiled at us. It could have been Ponty’s dam you were riding; I always noticed horses when I was a child, and Ponty looks much the same as that pony did. We will write a custom essay sample on Chalice Chapter 7 or any similar topic only for you Order Now Your brother had cantered on ahead.† An expression crossed his face so fleetingly that had she not been staring at him she would have missed it: it was the expression of the little brother whose older brother had just cantered on ahead of him – again. For that tiny, fleeting moment not only did he look fully human, but she saw the boy he had once been, and knew it was the same boy she had seen that day with her mother. â€Å"Yes, he would have cantered on ahead. He was an excellent rider from the first time he sat alone on a pony; but any horse he rode immediately wanted to gallop. He had a similar effect on everyone. Except perhaps me. He overwhelmed his Chalice.† It was not a question. She could think of nothing better to tell him than what she guessed was the truth. As Chalice, her guess came from sources no one else had, although her conclusions were no different from what everyone knew, whether they spoke it aloud or not – which they did not. She stood to all the important meetings of the House and the Circle. Neither they nor their new Master spoke in the terms he and she spoke in now. â€Å"He – chose – her to be flexible. To be responsive. The old Chalice was old before he became Master, and your father was a man who – who deeply believed in tradition.† â€Å"Narrow-minded and intolerant,† he said. â€Å"The trouble did not begin with my brother.† â€Å"I guess,† she said slowly, â€Å"that the land did feel some – imprisonment, under your father. And your brother wished to open the prison door. He knew his – his own mind soon enough that he was able to – to will the land to choose a – a supple young girl when the Chalice wished to take an apprentice. A girl who would grow into a Chalice who would help him unlock the door.† â€Å"My brother wished to run wild with no hindrance from anyone or anything.† â€Å"He helped create a Chalice who would accept his lead.† â€Å"Who would provide no obstacle to his self-indulgences.† She was silent. She would have liked to disagree, to honour the memories of the Master and the Chalice they had received their sovereignties from, but†¦Master and Chalice were always grievously hard burdens to bear. What she and her Master had been given wasn’t even the onus of building bricks without straw; the bricks had existed and been shattered. You can’t make bricks out of broken bricks. â€Å"By wine and fire,† he said slowly. â€Å"Therefore the land would have a Chalice neither of water nor of wine. And it drew me back from a place farther into Fire than anyone has returned from.† â€Å"I am not strong enough,† she said. She had never said this aloud to anyone before – anyone but her bees. â€Å"I know too little, and I do not learn fast enough. And there are not enough hours in the day.† And the land has been bent away from true too far and for too long. â€Å"I do not believe that,† he said. â€Å"At least – it would not be if you had a Master you could rely on, who could sustain you as a Master should.† â€Å"I do not believe that,† she said firmly. â€Å"I – â€Å" â€Å"No,† he said. â€Å"Let us not have another exchange of compliments. You have chosen to support me, and I tell you that I support you. I do hear our land about some things, and I feel it respond to you – it responds as a frightened horse does to the rein in a kind hand, when the brute that hurt it has gone. It is skittish and uneasy yet, but it listens to you. It is listening hopefully. There is good heart in our land; it will return to us if it can. â€Å"So I suggest there be a pact between us – that we accept that we are Master and Chalice here – and that we are each other’s Master and Chalice. Will you assent to this?† While they were talking the bees had, as usual, come to see who Mirasol’s visitor was. But a more than usual number of them had settled on him, and had not flown away again. This was not their usual behaviour, but she was too disturbed and confused by the conversation to have paid proper attention; nor had she noticed that their humming note had changed. â€Å"Oh – I did not think,† she said. â€Å"The bees – they probably do not like the smell of fire on you.† He made a sudden movement – exactly the sort of sudden movement you should not make when surrounded by half-agitated bees. His hand had gone to his forearm, bare above the wrist, and she realised one had stung him – stung the Master. Several thoughts flew frantically into her mind simultaneously: this was why a Chalice was never of honey; but no Master had ever smelt of fire as this one did; what law was there about a Chalice who caused injury to her Master? â€Å"Don’t – don’t – â€Å" But he hadn’t tried to crush the bee that stung him. He was holding her, very gently, against his forearm, with the tip of one finger. â€Å"There, little one, that’s not necessary. Don’t wriggle so, you’ll do yourself fatal harm. Your sting is barbed, you know, you have to tease it out slowly†¦.† He raised his finger, and one rather tired and dazed bee flew away. None of the others had stung him, and after a few seconds they all too began to fly away, in little groups of twos and threes; and their hum had steadied and deepened again to its usual note. â€Å"You know something of bees,† she said. He looked at her, and something more like a human smile than the last time she had seen the corners of his mouth curl upwards changed his face. It seemed to quiet the flicker, as if the hum of the bees had a calming effect on this too. â€Å"A bee sting is very like fire, is it not?† She smiled too, hesitantly. â€Å"I suppose it is. Are you – â€Å" â€Å"Hurt? Harmed?† he said. â€Å"No. It is very difficult to burn a priest of Fire, although it can be done.† She said, â€Å"I am glad that when you were sent away you went to Fire.† Again she had spoken unthinkingly, in the carelessness of relief, but he replied readily: â€Å"A bee could not sting a third-level priest of Earth any more than she could sting a thirty-year-old oak. A bee could not sting a third-level priest of Air any more than she could sting a sunbeam.† Think before you speak, she said to herself fiercely, but aloud she said immediately, â€Å"A thirty-year-old oak cannot be transplanted and live; and what happens to the light when a cloud passes in front of the sun? I am still glad, if you had to be sent away, you went to Fire. You walk on the earth and you cast a shadow; you speak in ordinary words and – and you can be stung by a bee. You are more human than you fear.† She could see him considering how to refute her words; but the silence stretched to a minute and at last he said only, â€Å"Thank you.† â€Å"Honey – † she began again. â€Å"Yes. You were going to give me some honey.† That was not what she had been about to say, and she was bewildered for a moment. Then she recalled herself, and gestured at the tray. â€Å"I didn’t know how you would like it.† â€Å"What would you recommend?† She opened her mouth, closed it again. Opened it again, said resolutely, â€Å"Straight out of the jar.† She handed him a spoon, and the jar. â€Å"There are two spoons.† â€Å"I will have some too, if you permit.† And he laughed. It was a creaky, crackly noise, and if she had not been already much accustomed to the strangeness of him, she might not have realised that was what she was hearing; it sounded rather like the noises a fire makes burning sappy wood. But she did realise, and she smiled. â€Å"You are Master,† she said. â€Å"And you are Chalice, and the first, so far as we know, Chalice of honey, and it is your honey. I am honoured to taste it, and will it not†¦will it not make the bond necessary between us stronger to eat a little of your honey together?† Involuntarily she glanced at the back of her right hand, where, sometimes, when the light was just right or just wrong, there was a faint scar visible. â€Å"It is not fitting nor desirable that the bond began with hurt,† she said. â€Å"But it did begin then, when your hand slipped on the cup of welcome.† â€Å"It is a strange Mastership and a strange Chalicehood,† he replied. â€Å"The last Master and Chalice died ill, and without Heir or apprentice. We are making new ways because we must. We have had one burning between us. Let us have the sweetness now.† Two, she thought. Two burns and two sweets. For it was a strange sweetness when you healed my hand; and one of my bees burnt you. Do you fear to overwhelm me? You shall not. And the land chose me without your will – while you still lay in Fire. Yes. Perhaps what we do is possible. Possibly I am strong enough. She realised she was smiling, and looked at him again, and when he smiled back, this time, it was unmistakably a smile, not merely the remains of an old human reflex not quite abolished by Fire. â€Å"Does honey always make one smile?† he asked, as if it were a serious question. â€Å"Yes,† she said firmly. â€Å"Yes, it does. With your permission, Master, I will give you some to take back to the House with you. Do not let Ponty know you carry it!† The night the Onora Grove burned she had been sleeping fitfully, for there was a ferocious storm tearing at the landscape, and the earthlines were uneasy. When the lightning struck not far from her cottage, she was out of bed and dragging on her clothes before she had thought of anything she might do. Even after it had occurred to her that she needed to have thought of something to do – and could still think of nothing – she went anyway, snatching up the smallest and plainest of the Chalice cups off the shelf as she passed, one that had no specific meaning or duty, and stuffing it down one pocket in her cloak; a small jar of honey went into the pocket on the other side. When she opened her door and stepped out the rain felt strangely warm against her face, but the wind buffeted her like a blow from a fist and she stumbled, holding on to her door-handle for balance. She scuttled down the path from her door, leaning against the blustering gusts. The wind was behind her as she turned onto the main path, which was wide and smooth enough for wagons, so she ran, clutching her skirt and the ends of her cloak against the force of the gale. The rain drove against her, through the cloak, through her clothing, to her skin. The sky was turning red as she sprinted toward the grove, and through the roar of the wind she began to hear the hissing of the rain-lashed fire. The wind slewed around and the fog billowed out to meet her; her lungs hurt from smoke as well as running. She almost hurtled into the Master; in his black cloak he looked like more smoke and fog. She had not come far, but her legs were trembling with effort, and with fear. The Master was standing, apparently merely watching the fire; but he turned to her at once and said, â€Å"Good, you’re here,† as if he had been waiting for her – expecting her. â€Å"Can you bring me water from the stream?† It should have been hard to hear him through the sound of wind, rain and fire, but it was not; and his voice sounded calm and strong. Bewilderedly she turned around, realised where she was, and went to the stream. It flickered a macabre, almost phosphorescent red; it did not look like water. Nor could she hear its usual cheerful murmur as it tumbled in its bed. She dipped a cupful up and returned to the Master. â€Å"You have brought honey too?† How to cite Chalice Chapter 7, Essay examples

Tuesday, May 5, 2020

Auschwitz

Auschwitz- Birkenau Death Camp Essay Auschwitz-birkenau was by the provincial Polish town of Oshwiecim, in Galacia. It was where the largest numbers of European Jews were killed. They called it The Gate to Hell. In September 1941 the SS men (Hitlers Men) experimented with gassing and killed over 850 people. Murdering a large number of prisoners became a daily routine. By 1942 there had been three million people killed through gassing, starvation, disease, shooting, and burning. Almost every one of the prisoners was a Jew. At Auschwitz children were killed as soon as they got there. Children born in the camp were also killed right away. There were Camp Doctors that would torture and cause horrible pain on the Jewish children. They were put into pressure chambers, tested with drugs, castrated, and frozen to death. Block 10 was a room in Auschwitz that was used for medical experimentation. German doctors had to sign up to use this room and they would take some of the prisoners and torture them until they died. Dr. Clauberg liked to use sterilization by injection. He would take married women between the ages of twenty and forty that have already had children and inject a substance into their cervix so that the fallopian tubes would fill up. The women would scream with pain, feeling like their stomachs were going to burst. Horst Schumann used block 10 for castration or X-rays. He would use healthy young men and women in their early teens or twenties. He would place plates on different areas of the body and then turn on the machine. The patients got burns that would become infected and took a long time to heal. Many would have fever, severe pain and vomiting.