Support Forums
Source Codes For Beginners Pt.1 - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: Source Codes For Beginners Pt.1 (/showthread.php?tid=4946)

Pages: 1 2


Source Codes For Beginners Pt.1 - SouR'D - 02-21-2010

These are just some sources i had found on my computer. (credit to their owners)


Start Process

Code:
Process.Start("www.TechnicForums.com")


External Ip

Code:
Public Class iMe

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Husam As New System.Net.WebClient
        Dim ip As String
        ip = System.Text.Encoding.ASCII.GetString(( _
        Husam.DownloadData("Http://whatismyip.com/automation/n09230945.asp")))
        TextBox1.Text = ip

    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Me.Close()
    End Sub
End Class


Fade in (Form Effect)

Code:
Delegate Sub FadeIn_Delegate(ByRef [Form] As Form, ByRef [TimeMs] As Double, ByRef [ToOpacity] As Double)

    Public Sub FadeIn(ByRef whd As Form, ByRef ms As Double, ByRef ToOpacity As Double)
        Dim etime As DateTime
        If whd.InvokeRequired Then
            Dim d As New FadeIn_Delegate(AddressOf FadeIn)
            whd.Invoke(d, New Object() {whd, ms, ToOpacity})
        Else
            Try
                While whd.Opacity < ToOpacity
                    whd.Opacity += 0.01
                    If whd.Opacity = ToOpacity Then Exit While
                    etime = Now.AddMilliseconds(ms)
                    While Now < etime
                        System.Windows.Forms.Application.DoEvents()
                    End While
                End While
            Catch ex As Exception
                Exit Try
            End Try
        End If
    End Sub


Type Writer (Text Effect)

Code:
Public Class Form1
    Dim i As Integer = 0
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 300 'Typing Speed.
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim strtext As String = TextBox1.Text
        Dim textarray() As Char = strtext.ToCharArray()

        If i = Len(strtext) Then
            Timer1.Stop()
            Me.Close()
        Else
            RichTextBox1.AppendText(textarray(i))
            i = i + 1
        End If

    End Sub

End Class



Progress Bar

Code:
ProgressBar1.Increment(textbox1.text)
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Stop()
MsgBox("Progress Bar Loaded 100%")
ProgressBar1.Increment(-100)
Timer1.Interval = (TextBox2.Text)
End If

Rc4 Text Encryption

Code:
Public Shared Function rc4(ByVal message As String, ByVal password As String) As String

        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim cipher As New StringBuilder
        Dim returnCipher As String = String.Empty

        Dim sbox As Integer() = New Integer(256) {}
        Dim key As Integer() = New Integer(256) {}

        Dim intLength As Integer = password.Length

        Dim a As Integer = 0
        While a <= 255

            Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))

            key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
            sbox(a) = a
            System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
        End While

        Dim x As Integer = 0

        Dim b As Integer = 0
        While b <= 255
            x = (x + sbox(b) + key(b)) Mod 256
            Dim tempSwap As Integer = sbox(b)
            sbox(b) = sbox(x)
            sbox(x) = tempSwap
            System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
        End While

        a = 1

        While a <= message.Length

            Dim itmp As Integer = 0

            i = (i + 1) Mod 256
            j = (j + sbox(i)) Mod 256
            itmp = sbox(i)
            sbox(i) = sbox(j)
            sbox(j) = itmp

            Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)

            Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)

            itmp = Asc(ctmp)

            Dim cipherby As Integer = itmp Xor k

            cipher.Append(Chr(cipherby))
            System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
        End While

        returnCipher = cipher.ToString
        cipher.Length = 0

        Return returnCipher

    End Function

I would Like +Rep for sharing this but i am not allowed to ask..Hehe


RE: Source Codes For Beginners Pt.1 - Danny - 02-23-2010

Very nice job here Smile +REP Big Grin

Edit: Oops! I need 100 posts to give reps Sad


RE: Source Codes For Beginners Pt.1 - Ezzat - 03-01-2010

thx for sharing that.....


RE: Source Codes For Beginners Pt.1 - Mattâ„¢ - 03-01-2010

Thanks I liked the encryption one. Big Grin


RE: Source Codes For Beginners Pt.1 - Sam - 11-13-2010

Why did you ask then?


RE: Source Codes For Beginners Pt.1 - KoBE - 11-13-2010

SouRD Wrote:I would Like +Rep for sharing this but i am not allowed to ask..

You want +Rep for sharing someone else's work? Nono Its a good post, and you did good by not taking credit. But, you can do a quick google search and come up with this.

Again, good post. But +Rep will come.. when it's deserved.


RE: Source Codes For Beginners Pt.1 - SYNTAX ERR0R - 11-13-2010

Hey thanks for these bro. Just what I have been looking for Smile. Some simple code to get me started.


RE: Source Codes For Beginners Pt.1 - SlimDeath - 11-15-2010

It's very useful for beginners but the "Fade in (Form Effect)" it's very cool, you should definitely use it if you want it to make it more attractive.


RE: Source Codes For Beginners Pt.1 - JesusOfSuburbia - 11-15-2010

It's very usefull...I'm also trying to make this work Big Grin thank's man!


RE: Source Codes For Beginners Pt.1 - Navineous - 11-15-2010

Quite useful indeed, thanks for posting this.