Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
T

TwoFaced

@TwoFaced
About
Posts
196
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What is object reference not set to an instance of an object?
    T TwoFaced

    You've created a jagged array (an array of arrays). When you do this each element points to another array. The array's initially aren't created. I think this is why you get the error. Take this for example

        Dim data(5)() As String
        data(0) = New String() {"Data1", "Data2", "Data3"}
    
        Console.WriteLine(data(0)(0))
    
        ' The next line will throw an error because the 2nd element
        ' doesn't point to an array yet.
        Console.WriteLine(data(1)(0))
    

    What's probably happening is you are only reading x number of rows, so only the first x elements have been initialized properly. Trying to read beyond x will throw an error. You could initialize all the elements first like so:

        For i As Integer = 0 To data.Length - 1
            data(i) = New String() {}
        Next
    

    Or you can just make sure you don't read beyond the number of lines read.

    Visual Basic question database debugging

  • Two problems with a thread project
    T TwoFaced

    I believe the UserControl is firing it's mouseleave event when the mouse goes over the label or picturebox. This is normal. When the event fires you might be able to just check the mouselocation and if it's within the bounds of your control, exit the method. You could also try to get around the problem by doing all the drawing yourself instead of using a picturebox and label. **EDIT** The reason it pops up is because of the second loop in this method 'pctBoxVerkleinern'. Also I believe your going to have some threading issues because you can't start a thread once it's been aborted. In the mouseenter and leave events you need to create a new instance of the thread and then start it.

    Visual Basic question html help

  • ListView add and group items
    T TwoFaced

    Yup, here is a simple example.

    Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Add a column to the listview
        ListView1.Columns.Add("Name")
    
        ' Create two groups
        ListView1.Groups.Add("Group1", "Group1")
        ListView1.Groups.Add("Group2", "Group2")
    
        ' Add two items and assign them to the desired group
        ListView1.Items.Add("Test Group1").Group = ListView1.Groups("Group1")
        ListView1.Items.Add("Test Group2").Group = ListView1.Groups("Group2")
    
        ' Add another item differently and give it a group
        ListView1.Items.Add(New ListViewItem("Test Group1 again", ListView1.Groups("Group1")))
    
        ListView1.View = View.Details
    
        ' Basically you need to know that the groups collection is where you 
        ' add groups to the listview
    
        ' I've showed two different ways you can add an item and assign it to a group
        ' This should give you an idea how to work with groups
    End Sub
    
    Visual Basic question

  • how to create control array ? in vb .net
    T TwoFaced

    I showed you code to dymanically create textboxs, is that how these textbox's were created or were they created at design time? Controls created at design time are given a default name, however, controls created at runtime are not. When you create the textbox you need to set it's name property. This is one reason why 'Name' may not be returning anything.

    Visual Basic csharp design data-structures help

  • how to create control array ? in vb .net
    T TwoFaced

    Me.ActiveControl will give you a reference to the control that has focus. The problem I'm guessing is your code resides in a button click event. If you click the button it gets focus so Me.ActiveControl.Name will return the buttons name. What exactly are you trying to do? Can you describe the program a little?

    Visual Basic csharp design data-structures help

  • For and next loop... problem
    T TwoFaced

    That's what IntelliSense is for :) Also the MSDN library is a big help.

    Visual Basic database help question

  • For and next loop... problem
    T TwoFaced

    The listbox contains objects which could be anything. ListBoxUpgrade.SelectedItem(i) will return whatever text the ToString method returns. For most objects this is the type of object it is. Because you've bound your listview you actually have a listview full of DataRowView objects. This is why the ToString method is returning System.Data.DataRowView. If you want to get the corresponding text of the item (the text being displayed in the listbox) you can use the GetItemText method.

        For Each obj As Object In ListBox1.SelectedItems
            Console.WriteLine(ListBox1.GetItemText(obj))
        Next
    
    Visual Basic database help question

  • how to create control array ? in vb .net
    T TwoFaced

    There is no design time support for creating control arrays. Here is some code that demonstrates a few different approaches.

    Public Class Form1
    ' An array of textbox's
    Private ControlArray As New List(Of TextBox)

    Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Here I am adding TextBox's that already exist on my form to the array
        With ControlArray
            .Add(TextBox1)
            .Add(TextBox2)
            .Add(TextBox3)
        End With
    
        ' Loop through each textbox in the array
        For Each tb As TextBox In ControlArray
            MsgBox(tb.Name)
        Next
    
        ' Access a textbox by index
        MsgBox(ControlArray(1).Name)
    
        ' Here I am creating textboxes dynamically and adding them
        ' to the array
        For i As Integer = 0 To 2
            ' Create a textbox
            Dim tb As New TextBox
            ' Set it's position
            tb.Location = New Point(20, 10 + i \* 30)
            ' Set it's width
            tb.Width = 100
    
            ' Add the textbox to the array
            ControlArray.Add(tb)
    
            ' Add the textbox to the form
            Me.Controls.Add(tb)
    
            ' Add handlers for the GotFocus and LostFocus events
            AddHandler tb.GotFocus, AddressOf TextBox\_GotFocus
            AddHandler tb.LostFocus, AddressOf TextBox\_LostFocus
        Next
    
        ' Here I've looped through the forms controls and found
        ' all the textboxes and added them to the array
        ' This is a good approach if you have many controls you added at
        ' design time but don't want to manually add each one to the array.
        ' The desired event handlers can also be dynamically added this way
        For Each ctrl As Control In Me.Controls
            Dim tb As TextBox = TryCast(ctrl, TextBox)
            If tb IsNot Nothing Then
                ControlArray.Add(tb)
            End If
        Next
    End Sub
    
    ' Handles the textboxes GotFocus event
    ' I've handled the controls I created at design time by including them after the handles keyword
    Private Sub TextBox\_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox3.GotFocus
        ' tb is a reference to the textbox that raised this event
        Dim tb As TextBox = DirectCast(sender, TextBox)
        tb.BackColor = Color.Wheat
    End Sub
    
    ' Handles the textboxe
    
    Visual Basic csharp design data-structures help

  • find names in a directory
    T TwoFaced

    This is how I might go about it. Hope it gives you the right idea.

        Const directoryPath As String = "C:\\test"   ' The directory to look in
    
        Dim desiredFiles As New List(Of String)     ' List of files we're looking for
        With desiredFiles       ' Note I didn't use file extensions.  Change that if you'd like.
            .Add("File1")       ' but you'll need to tweak the code below if you do.
            .Add("File2")
        End With
    
        ' METHOD 1
    
        ' Create a DirectoryInfo object for the desired directory
        ' to look in.
        Dim info As New IO.DirectoryInfo(directoryPath)
    
        ' Get all the \*.doc files in the directory
        For Each file As IO.FileInfo In info.GetFiles("\*.doc")
            ' The contains method is case sensitive.  If you want a case-insentive
            ' search you can add the desired file names in all lower or uppercase and then use the
            ' ToLower or ToUpper methods on the file name
            If desiredFiles.Contains(IO.Path.GetFileNameWithoutExtension(file.Name)) Then
                ' The file name was found in our list
                MsgBox("Directory contained file: " & file.Name)
            End If
        Next
    
        ' METHOD 2
        For Each file As String In desiredFiles
            If IO.File.Exists(IO.Path.Combine(directoryPath, file & ".doc")) Then
                MsgBox("Directory contained file: " & file)
            End If
        Next
    
    Visual Basic data-structures help

  • Using Listbox help
    T TwoFaced

    You'd write something like this

    text1.text = ListBox1.Items.Item(2).ToString()

    The array holding the items is zero based, which means the 3rd item is really the 2nd element in the array.

    Visual Basic help tutorial question

  • Hide a property that isn't overridable...
    T TwoFaced

    You can easily fix a controls size by overriding SetBoundsCore. It looks like this.

    Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As System.Windows.Forms.BoundsSpecified)
        Const fixedWidth As Integer = 50
        Const fixedHeight As Integer = 50
    
        MyBase.SetBoundsCore(x, y, fixedWidth, fixedHeight, specified)
    End Sub
    

    I know changing the size back in the resize event will also work, but doing it that way actually allows the control's size to be changed and then it quickly changes it back. Overriding SetBoundsCore will prevent the change from ever occurring.

    Visual Basic csharp python com help

  • Breaking up strings
    T TwoFaced

    Guffa, I think that regular expression would fail to properly parse something like "ThisIsATest" because it wouldn't pick up on two capital letters next to one another. I think something like this would be required to find the word boundaries "([A-Z]|[a-z])(?=[A-Z])". Using a replace of "$1 ".

    Visual Basic question

  • write user control the same as PANEL or GROUPBOX
    T TwoFaced

    All controls can contain other controls, but I assume you want design time support like the panel has. Do do that add this line of code just before the class declaration.

    <Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(IDesigner))> _

    Visual Basic csharp

  • DateTime.Parse fails at VB2005
    T TwoFaced

    I found a way to cope with 'th', 'st', 'nd' and 'rd'. It's not that pretty but if you wrap it up into a function you've got a workable solution. It would be nice if you could just ignore characters, then you could use something like "d##MMMMyyyy" where # would be a character that's ignored. However, I couldn't find anything in the documentation that would lead me to believe that's possible. Anyway here you go.

        ' Valid date formats
        Dim validFormats As String() = {"d'st'MMMMyyyy", "d'nd'MMMMyyyy", "d'rd'MMMMyyyy", "d'th'MMMMyyyy"}
        Dim myDate As Date = Date.ParseExact("1stDecember1993", validFormats, Globalization.CultureInfo.CurrentCulture, Globalization.DateTimeStyles.None)
    

    Your original post showed no spaces for the date...it was 7thNovember1993. If that's not the case just add appropriate spaces into the formatting strings and it should work.

    Visual Basic database

  • The syntax about IDataReader? [modified]
    T TwoFaced

    dataReader("name") is the short version of dataReader.Item("name"). You can do this because the property 'Item' is the default property.

    Visual Basic database csharp question

  • Binding Two dimensional arrays to Datagrid
    T TwoFaced

    The article supplied contains a library that will create a proper datasource from a multi-dimensional array. Just download the .dll and add a reference to it. You can then use it like this:

        Dim test(2, 2) As String
        test(0, 1) = "SomeData"
        test(0, 2) = "SomeOtherData"
        DataGridView1.DataSource = New Mommo.Data.ArrayDataView(test)
    
    Visual Basic question wpf wcf tutorial

  • Passing MultiDimensional Array as a paramenters in Functions
    T TwoFaced

    You can accept a multidimensional array like this.

    Private Function GetRow(ByVal data(,) As Double, ByVal row As Integer) As Double()
    
    End Function
    

    The function also returns a 1-dimensnial array. All the function needs now is to get the values from the array and return them as 1-dimensional array.

    Visual Basic tutorial data-structures

  • string tokenization
    T TwoFaced

    Also you could use a regular expression to do the splitting. It will allow you to remove all the white space between values so you only get the actual text. Take a look at this.

        Dim value As String = "A      B     C"
    
        Dim regex As New System.Text.RegularExpressions.Regex("\\s+")
        For Each s As String In regex.Split(value)
            Console.WriteLine(s)
        Next
    
    Visual Basic help csharp com regex

  • string tokenization
    T TwoFaced

    Because your using spaces as your delimiter it was probably hard to notice but the values that will be contained in 'sites' are not spaces, they are empty strings. Take a look at this code:

        Dim value As String = "A,,B,C"
    
        For Each s As String In value.Split(","c)
            Console.WriteLine(s)
        Next
    

    You'll notice the values returned by the split function are 'A','','B','C' where '' is an empty string. It doesn't return the delimiter. In your loop you should test that the string is not empty.

    Visual Basic help csharp com regex

  • he he
    T TwoFaced

    sk8er_boy287 wrote:

    However, if you can prove that StringBuilder is better than simple string concatenation, you get an A+.

    If you need to build a string in a loop the stringbuilder is FAR more efficient then normal string concatenation. I've run into the problem before and learned the hard way. Actually I learned about it a while back using VB6, but VB6 didn't have a nice StringBuilder so I figured out another way around it. A simple example will show the difference. Do I get an A+? :)

    Public Class Form1
    Private Sub TestStringConcatenation(ByVal loops As Integer, ByVal myText As String)
    Dim s As String = ""
    For i As Integer = 0 To loops
    s &= myText
    Next
    End Sub

    Private Sub TestStringBuilder(ByVal loops As Integer, ByVal myText As String)
        Dim sb As New System.Text.StringBuilder
        For i As Integer = 0 To loops
            sb.Append(myText)
        Next
    End Sub
    
    Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Const LOOPS As Integer = 1000
        Dim myText As String = New String("A"c, 200)
        Dim sw As New Stopwatch
    
        sw.Start()
        TestStringConcatenation(LOOPS, myText)
        sw.Stop()
        Console.WriteLine("Normal string concatenation took {0} ticks", sw.ElapsedTicks)
    
        sw.Reset()
        sw.Start()
        TestStringBuilder(LOOPS, myText)
        sw.Stop()
        Console.WriteLine("String builder took {0} ticks", sw.ElapsedTicks)
    End Sub
    

    End Class

    As for the code the OP posted, what's funny about it is how much extra useless code the person used to return a string. All that was needed was a simple line

    Return "Current date and time is " + DateTime.Now.ToString()

    As someone already mentioned the original code writer probably learned that is was more efficient to use the stringbuilder if you are going to append text to a string. Unfortunatly they didn't use it correctly and didn't really grasp when it's appropriate to use it. I ran a test to see what method performed best. In this case normal string concatenation seemed to out perform stringbuilder. Here is my code I used to see the performance of each method.

    Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Const TRIALS As Integer = 1000
    Const LOOPS As Integer = 1000

    The Weird and The Wonderful com
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups