pradeep1210's Profile User Rating: -----

Reputation: 9 Worker
Group:
Active Members
Active Posts:
56 (0.08 per day)
Joined:
08-May 12
Profile Views:
2,368
Last Active:
User is offline Dec 23 2013 05:29 AM
Currently:
Offline

Previous Fields

Country:
IN
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   pradeep1210 has not set their status

Posts I've Made

  1. In Topic: Challenge: Mission Operator Overlord.

    Posted 5 Jun 2012

    Please accept something from me too :)

    The class:
    Public Class Thing
        Public Enum ThingProperties
            [Class]
            Color
            Size
            Shape
            'TODO: Define your property types here
        End Enum
    
        Public Property Properties As New Dictionary(Of ThingProperties, String)
        Public Property Name As String
    
        Public Sub New(ByVal name As String)
            Me.Name = name
        End Sub
    
        Public Overloads Shared Operator Like(ByVal a As Thing, ByVal b As Thing) As Boolean
            'TODO: Incease or decrease this depending on what precision of match you want to have
            Return MatchPercent(a,B)/> >= 50
        End Operator
    
        Public Overloads Shared Operator =(ByVal a As Thing, ByVal b As Thing) As Boolean
            Return MatchPercent(a,B)/> = 100
        End Operator
    
        Public Overloads Shared Operator <>(ByVal a As Thing, ByVal b As Thing) As Boolean
            Return MatchPercent(a,B)/> <> 100
        End Operator
    
        Public Overrides Function ToString() As String
            Return Me.Name
        End Function
    
        Private Shared Function MatchPercent(ByVal a As Thing, ByVal b As Thing) As Integer
            Dim matches, found, notFound As Integer
    
            If a Is b Then Return 100
    
            For Each key In a.Properties.Keys
                If b.Properties.ContainsKey(key) Then
                    If a.Properties(key).ToLower = b.Properties(key).ToLower Then matches += 1
                    found += 1
                Else
                    notFound += 1
                End If
            Next
            If found = 0 OrElse found < notFound Then
                Return 0
            Else
                Return CInt(matches * 100 / found)
            End If
        End Function
    End Class
    
    


    Sample Usage:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim apple As New Thing("Apple")
        Dim mango As New Thing("Mango")
        Dim orange As New Thing("Orange")
    
        apple.Properties.Add(ThingProperties.Class, "Apple")
        mango.Properties.Add(ThingProperties.Class, "Mango")
        orange.Properties.Add(ThingProperties.Class, "Orange")
    
        apple.Properties.Add(ThingProperties.Color, "Red")
        mango.Properties.Add(ThingProperties.Color, "Yellow")
        orange.Properties.Add(ThingProperties.Color, "Orange")
    
        apple.Properties.Add(ThingProperties.Size, "10")
        mango.Properties.Add(ThingProperties.Size, "10")
        orange.Properties.Add(ThingProperties.Size, "10")
    
        apple.Properties.Add(ThingProperties.Shape, "Round")
        mango.Properties.Add(ThingProperties.Shape, "Oval")
        orange.Properties.Add(ThingProperties.Shape, "Round")
    
        Dim msg As New StringBuilder
        msg.AppendFormat("{0} is {2} {1}" & vbCrLf, apple, mango, If(apple Like mango, "like", "not like"))
        msg.AppendFormat("{0} is {2} {1}" & vbCrLf, apple, orange, If(apple Like orange, "like", "not like"))
        msg.AppendFormat("{0} is {2} {1}" & vbCrLf, mango, orange, If(mango Like orange, "like", "not like"))
    
        MessageBox.Show(msg.ToString)
    End Sub
    
  2. In Topic: 2 lines of code into 1

    Posted 19 May 2012

    You do like this:
    If getDateAsInt.convertDateToInteger(anyDateText) = 0 Then Exit Sub
    
    
    
    
  3. In Topic: How to separate each column in a textfile?

    Posted 17 May 2012

    View Postvnewbie, on 17 May 2012 - 06:54 PM, said:

    Thanks Pradeep,

    Just a quick question what would I need to do to just add the header to a file and not worry about the alignment?


    Most part of that code was being used to format the data. Since now u no longer need to format the records, you can insert your header row simply like this:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '' your header - format it whatever way u want it to look like.
        Dim header As String = "My Sexy Header Line Goes Here"
    
        '' add header to file
        AddHeaderToFile("C:\Temp\test.txt", "C:\Temp\test-1.txt", header)
        MessageBox.Show("Done!")
    End Sub
    
    Private Sub AddHeaderToFile(ByVal inputFileName As String, ByVal outputFileName As String, ByVal header As String)
        Dim fileData As String = IO.File.ReadAllText(inputFileName)
        Using sw As New IO.StreamWriter(outputFileName)
            sw.WriteLine(header)          '' write header
            sw.Write(fileData)            '' write data rows
            sw.Close()
        End Using
    End Sub
    
    
  4. In Topic: How upload file to a website.

    Posted 17 May 2012

    What code do you have so far?
  5. In Topic: How to separate each column in a textfile?

    Posted 17 May 2012

    Try this:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '' your header - separate the columns with comma.
        Dim header As String = "My,Sexy,Header Line,Goes,Here"
    
        '' the numbers are the maximum width of the fields (starting first column to last one)
        FixFileData("C:\Temp\test.txt", "C:\Temp\test-1.txt", header, 10, 10, 15, 20, 10, 10, 10, 10, 15, 10)
        MessageBox.Show("Done!")
    End Sub
    
    Private Sub FixFileData(ByVal inputFileName As String, ByVal outputFileName As String, ByVal header As String, ByVal ParamArray fieldWidths() As Integer)
        Dim fileData() As String = IO.File.ReadAllLines(inputFileName)
        For row = 0 To fileData.Length - 1
            Dim fields = Split(fileData(row), " ")
            For i = 0 To fields.Length - 1
                fields(i) = fields(i).PadRight(fieldWidths(i))
            Next
            fileData(row) = Join(fields, vbTab)
        Next
    
        Using sw As New IO.StreamWriter(outputFileName)
            '' write header
            Dim fields = Split(header, ",")
            For i = 0 To fields.Length - 1
                fields(i) = fields(i).PadRight(fieldWidths(i))
            Next
            header = Join(fields, vbTab)
            sw.WriteLine(header)
    
            '' write data rows
            For Each row In fileData
                sw.WriteLine(row)
            Next
            sw.Close()
        End Using
    End Sub
    
    

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
New Delhi
Full Name:
Pradeep Kumar
Programming Languages:
Visual Basic 6
Visual Basic.NET
MS-Office VBA
ASP.NET
SQL Server

Contact Information

E-mail:
Private
Website URL:
Website URL  http://pradeep1210.wordpress.com

Friends

Comments

pradeep1210 has no profile comments yet. Why not say hello?