Jump to content
Xtreme .Net Talk

torg

Avatar/Signature
  • Posts

    63
  • Joined

  • Last visited

About torg

  • Birthday 04/14/1973

Personal Information

  • Occupation
    Student
  • Visual Studio .NET Version
    Visual Studio .NET Professional
  • .NET Preferred Language
    VB.NET

torg's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. torg

    Search an array

    can you go into details?
  2. I`ve got a function searching for a spesific month in an array. The month is part of a full date like this:(dd.mm.yyyy) I`ve got a text box, where I write a number representing a month, which is the input of the function which returns the position in the array for that specific month. The sorted array has been filled from "txtPerson.text" looking somthing like this: Name date address Phone i.e Adolf 14.02.1980 Duckstreet 5, ohio 555-89898 It seems to me that the function does not return the position in the array, Why not, what am I doing wrong? ' Ignore the fact that Month is a reserved word. Structure individual Dim name As String Dim dates As String Dim address As String Dim Phone As String End Structure Dim person(8) As individual . . Private Sub Button1_Click..... Dim Temp as Integer Temp = MonthSearch(cInt(txtNumber.text)) End Sub . . . Function MonthSearch(ByVal month As Integer) As Integer Dim first, middle, last As Integer first = 1 last = numPerson Do While (first <= last) middle = CInt((first + last) / 2) Select Case CInt(CDate(person(middle).dates).Month) Case Month Return middle Case Is > Month last = middle - 1 Case Is < Month first = middle + 1 Case Else End Select Loop Return 0 End Function
  3. I`ve used If IsNothing(individ(i).navn) Then individ(i).navn = "" in the form_load procedure. Still there is something wrong. It seems as if there are not performed any search at all, atleast no result are shown the search algorithm now looks like this: Function findName(ByVal name2 As String) As Integer Dim first, middle, last As Integer first = 0 last = numOfRecords Do While (first <= last) middle = CInt((first + last) / 2) Select Case UCase(Person(middle).name1) Case name2 Return middle Case Is > name2 last = middle - 1 Case Is < name2 first = middle + 1 End Select Loop Return 0 End Function
  4. Yes, that should be Case Name1. Yes, it`s supposted to be a binarysearch of the data And no, the streamreader was not supposted to be in the function. I`ve never taken into concern to move blank fields to the end or start. How do I do that? The posts in the file are already sorted alphabeticalla by name But that`s just while trying to get the code to work. I`m going to use the sort algorithm downbelow As you`ll see downbelow, It`s only in the sort algorithm where I use the variable except from in the FindName function. But it`s not modified there. Sub sort() Dim gap As Integer, doneFlag As Boolean Dim index As Integer, temp As String gap = CInt(numPosts/ 2) Do While gap >= 1 Do doneFlag = True For index = 1 To numPosts- gap If person(index).name1> person(index + gap).name1 Then temp = person(index).name1 person(index).name1= person(index + gap).name1 person(index + gap).name1 = temp doneFlag = False End If Next Loop Until doneFlag = True gap = CInt(gap / 2) Loop End Sub There may be some write faults in the code that may have occured during translation of code. Ignore them. Or assume the syntax is correct.
  5. Does any other formatting take place? I.e is the headertext set to "CPU Time" or the width to 60 ?
  6. I would appreciate an example :)
  7. I`m not sure I understand what you`re asking about. The array reads data from a file , as long as ithere are "Data" to read. If there are only 49 posts in the file, then the arrayindex 50 would be empty.As is the case in my example. I`ve only registered 6 Posts/persons in the file.
  8. 50 on both of them
  9. at this line: Select Case Person(Mid).name1.ToUpper
  10. Doesn`t help either. i`m using Option Explicit On Imports System.IO Public Class Form4 in the top of my programming code, så I don`t see that what you suggest would help very much. My problem is.: I`ve got at file "txtPersonalia.txt" where you can get certain information. this informatiin are to be placed into an array on form load where it will be sorted in an ascending order .When I type a text in a textbox, the file will be searched to find a match, and write all information that is relevant for that reslut Structure individual Dim name As String Dim dato As String Dim address As String Dim Phonnumber As String End Structure Dim Person(100) As individual when trying to run I receive the following message Additional information: Object reference not set to an instance of an object. Which drives me crazy
  11. I receive the following message when trying your proposal. overload resolution failed because no accessible 'New' accepts the number of arguments. I`ve used Dim sr As StreamReader = File.OpenText("Personalia.txt") other places in my code, and have not had any problems with that. so I doubt that`s my problem. If it is there must be another answer to it.
  12. Sorry, that was just a write fault. antPosts is numPosts..As it is in my original code. (had to do some amendments before copying the code to this board) So problem is stilll here...
  13. I`ve been sitting here for a while now, but can`t figure out what I`m doing wrong. I`m hoping that someone out here can help me to solve my problem. I receive the message. that there are noe object reference set to this instance of object. Can anybody tell meg Why? Ive got: Structure individual Dim name1 As String Dim dato As String Dim address As String Dim Phonenumber As String End Structure Dim Person(100) As individual Dim numPosts as integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sr As StreamReader = File.OpenText("Personalia.txt") Do While (sr.Peek <> -1) And (numPosts< Person.GetUpperBound(0)) numPosts += 1 Person(numPosts ).name1 = sr.ReadLine Person(numPosts ).dato = sr.ReadLine Person(numPosts ).address = sr.ReadLine Person(numPosts ).Phonenumber = sr.ReadLine Loop .... end sub Function FindName(ByVal name1) As String Dim sr As StreamReader = File.OpenText("Personalia.txt") Dim First, Mid, Last As Integer Dim foundFlag As Boolean First= 1 Last= numPosts Do While (first<= last) And (Not foundFlag) Mid= CInt((first+ last) / 2) Select Case Person(Mid).name1.ToUpper Case name foundFlag = True Case Is > name1 last= first- 1 Case Is < name1 last= first+ 1 End Select Loop If foundFlag Then ListBox1.Items.Add(Person(mid).name1) Else MessageBox.Show("nothing") End If End Function
  14. I`ve just began to explore the use of Arraylist. It seems to me that there ar only advantages by using Arraylists instead of Arrays? I would like to hear what others think about this. I also wonder if there are "situations" where ordinary arrays are preferable instead of Arraylist. Could anyone tell me how to do a binary search in my example down below? Let`s say I want to search for "!". Dim myAL As New ArrayList() myAL.Add("Hello") myAL.Add("World") myAL.Add("!") Dim i As Integer For i = 0 To 2 lstData.Items.Add(myAL.Item(i))
  15. :o Is it possible to get more embarrassed ?(rhetorical quesiton) Thank you. That worked fine.... :) :o :o :o
×
×
  • Create New...