Jump to content
Xtreme .Net Talk

PlausiblyDamp

Administrators
  • Posts

    7016
  • Joined

  • Last visited

Everything posted by PlausiblyDamp

  1. If you use the Validating Event rather than the ValueChanged event it should prevent the problem with the event triggering itself repeatedly. Also you might consider an ErrorProvider rather than a MessageBox as a less intrusive way of notifying the user.
  2. As a quick one - the objects returned in my above post are sorted from closest to furthest away - if you loop over them (e.g. for each) you should be getting further away each time. From the addresses is it only the first part needed i.e. the number followed by S / E or N? Could the point of reference change from the hard coded 7700 and how are E address compared to this point? Would it be possible to simply map the street nummbers to a simple 2d grid and use that to calculate distances?
  3. You might find it easier to simply draw points onto a picturebox that contains the map itself.
  4. Just to make things even more complex the following two examples use the joys of lambda expressions to convert the strings to integers on the fly... Dim myArr() As String = {"6200", "6600", "7900", "8600", "9900"} Dim myInt As Integer = 7700 Dim res = From nums In myArr.Select(Function(s) Convert.ToInt32(s)) _ Order By nums - myInt _ Select New With {.Original = nums, .Difference = nums - myInt} 'just print out to debug as an example For Each x In res Debug.WriteLine(String.Format("Number {0}, distance {1}", x.Original, x.Difference)) Next and Dim myArr() As String = {"6200", "6600", "7900", "7500", "8600", "9900"} Dim myInt As Integer = 7700 Dim res = From nums In myArr.Select(Function(s) Convert.ToInt32(s)) _ Let diff = Math.Abs(nums - myInt) _ Order By diff _ Group nums By diff _ Into DistanceGroup = Group _ Select New With {.Difference = diff, .NumberOfMatches = DistanceGroup.Count, DistanceGroup} 'just print out to debug as an example For Each x In res Debug.WriteLine(String.Format("Distance {0}, Number Of Matches {1}", x.Difference, x.NumberOfMatches)) For Each number In x.DistanceGroup Debug.WriteLine(String.Format("Original number {0}", number)) Next Next
  5. Excellent a chance to show off with Linq!! The following snippet will return a collection of numbers sorted by how far from the starting number - just check the output window when running under a debug build to see the output. Dim myArr() As String = {"6200", "6600", "7900", "8600", "9900"} Dim myInt As Integer = 7700 Dim res = From nums In myArr _ Order By Math.Abs(Convert.ToInt32(nums) - myInt) _ Select New With {.Original = nums, .Difference = Math.Abs(Convert.ToInt32(nums) - myInt)} 'just print out to debug as an example For Each x In res Debug.WriteLine(String.Format("Number {0}, distance {1}", x.Original, x.Difference)) Next although it would be easier still if the original array contained integers rather than strings. If you need to handle multiple numbers being the same distance then something like Dim myArr() As String = {"6200", "6600", "7900", "7500", "8600", "9900"} Dim myInt As Integer = 7700 Dim res = From nums In myArr _ Let diff = Math.Abs(Convert.ToInt32(nums) - myInt) _ Order By diff _ Group nums By diff _ Into DistanceGroup = Group _ Select New With {.Difference = diff, .NumberOfMatches = DistanceGroup.Count, DistanceGroup} 'just print out to debug as an example For Each x In res Debug.WriteLine(String.Format("Distance {0}, Number Of Matches {1}", x.Difference, x.NumberOfMatches)) For Each number In x.DistanceGroup Debug.WriteLine(String.Format("Original number {0}", number)) Next Next which returns a collection of objects giving the distance (closest to furthest, number of matches and then a list of the actual numbers) - the dubug stuff at the end should show you what can be done to get at this. Again if the original array was converted to integers things would be a little easier.
  6. What version of .Net are you using?
  7. IIRC there is a link to a free pdf version of the book they did about #develop somewhere on their site - it really helps to explain how these things work.
  8. Could this information be stored elsewhere and loaded as part of the plugin load process? #Develop has a system that although complex could be simplified for your needs. Each plugin has an accompanying config file (xml in their case) which contains information regarding file extension etc.
  9. http://msdn.microsoft.com/en-us/library/ms173156.aspx is probably worth a read as it goes into some detail. In a nutshell however an interface is a way of achieving polymorphism as it defines a standard set of methods that classes can implement, other code however can just target the interface and not care about the exact type of object it is dealing with.
  10. So if I use the colour Red (&HFFFF0000) what would you expect the file to contain (0000803F or the full 0000803F0000000000000000)
  11. What is the file used by? Does it have any documentation that explains it's file format?
  12. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If dlgColor.ShowDialog() = DialogResult.OK Then PictureBox1.BackColor = dlgColor.Color() Dim fs1 As New FileStream(Application.StartupPath & "/test1.bin", FileMode.OpenOrCreate, FileAccess.Write) Dim bwriter1 As New BinaryWriter(fs1) Dim i As Integer = dlgColor.Color.ToArgb bwriter1.Write(i) bwriter1.Close() fs1.Close() End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim fs1 As New FileStream(Application.StartupPath & "/test1.bin", FileMode.Open, FileAccess.Read) Dim breader1 As New BinaryReader(fs1) Dim i As Integer = breader1.ReadInt32() breader1.Close() fs1.Close() Dim c As Color = Color.FromArgb(i) PictureBox1.BackColor = c End Sub worked fine for me.
  13. http://www.xtremedotnettalk.com/showthread.php?t=94476 might be worth a quick skim as it has an example of a class used to wrap a file path as suggested by DPrometheus earlier.
  14. Out of interest why do you need to do this?
  15. What is the code for the hex2bin method? Could you not just write it out as an integer and read it back as one? Could you not just use something like If dlgColor.ShowDialog() = DialogResult.OK Then PictureBox1.BackColor = dlgColor.Color() Dim fs1 As New FileStream(Application.StartupPath & "/files/test1.bin", FileMode.OpenOrCreate, FileAccess.Write) Dim bwriter1 As New BinaryWriter(fs1) Dim i As Integer = dlgColor.Color.ToArgb bwriter1.Write(i) bwriter1.Close() fs1.Close() and once you have read the integer back just use Dim c as Color = Color.FromArgb() to get it back.
  16. Unless you are doing things with threads then execution is purely synchronous - a method call (sub or function) completes before it returns and execution can continue. DoEvents simply lets your application process it's windows messages and shouldn't alter this in any way (apart from the odd exception like your application exiting etc.) I honestly have no idea if this is true in vb6 or not but it sounds highly unlikely (then again vb6 was odd in places;))
  17. Could you not just loop over the array and subtract the value from myInt and then calculate the absolute value (i.e. ignore the sign), then store this value / original value in a dictionary - the lowest value is the closest etc.
  18. What exactly is the problem? Is the colour changing between a load and save?
  19. Have you checked the contents of the arrays when the code executes? I can't see why it wouldn't clear the rtb - however if the array is being appended to then that could be the source of the problem.
  20. http://tinyurl.com/bs5q7b
  21. That has got to be one of the worst examples of XML I have seen for a while - they really haven't made you job easy by pretty much using html not xml for the feed. To be honest you might find it easier to just load the feed into a string and manually parse the contents rather than using the xml classes.
  22. Have you tried passing the int parameters as ref? [DllImport(@"c:\Program Files\OpenBUGS\brugs.dll", CharSet = CharSet.Ansi, EntryPoint = "CmdInterpreter")] public static extern void CmdInterpreter(ref string command, ref int len, ref int res); //How do I rewrite this without unsafe? That way you might be able to do away with unsafe code and just declare you variables as normal int variables.
  23. Could you just clarify what are you trying to do? Do you simply want to take afile's length and then shove this value into an existing file or use this length to locate an offset in the file? Given the sample uses the .gz extension are you trying to manipulate gzip files in some way?
  24. What version of .Net? If you are using version 2 or later the textbox supports auto completion directly, there are 3 or 4 properties AutocompleteMode, AutocompleteSource or similar - these should get you started.
  25. Something like http://www.codeproject.com/KB/GDI-plus/queuelinearfloodfill.aspx might be worth a read.
×
×
  • Create New...