Page 4 of 4 FirstFirst ... 234
Results 46 to 60 of 60
  1. #46
    MethNipple's Avatar
    Join Date
    Oct 2014
    Gender
    male
    Posts
    11
    Reputation
    10
    Thanks
    0
    Thanks for this, as someone who's fairly new to programming I'm trying to get into good habits now (commenting, consistent naming schemes etc...).

  2. #47
    Lucyfer's Avatar
    Join Date
    Dec 2012
    Gender
    female
    Location
    House Of Smoke 卍
    Posts
    1,295
    Reputation
    80
    Thanks
    1,957
    My Mood
    Devilish
    nice tutorial !

    My New Skype: mpgh.lucyfer
    Email: mpghlucyfer@gmail.com
    Hangouts (Google Talk): mpghlucyfer@gmail.com



    Do not Hesitate if you have Questions :-)
    Want fast Reply? Skype ME


    ALWAYS PRESS & TO GIVE US MOTIVATION TO CONTINUE POSTING AND GIVEAWAY COOL STUFF .


    Joined-December 2012
    Member Level 2-March 2016
    Blackshot Minion Section-March 2016

  3. #48
    apollofire007's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Posts
    157
    Reputation
    18
    Thanks
    163
    My Mood
    Chatty
    Thats quite informative and easy to understand. Very good efforts. Thanks a lot

  4. #49
    lacktos's Avatar
    Join Date
    Dec 2015
    Gender
    male
    Location
    Somewhere in NY
    Posts
    38
    Reputation
    10
    Thanks
    2
    Thanks for the important knowledge good share bro.

  5. #50
    Brisado's Avatar
    Join Date
    Feb 2018
    Gender
    male
    Posts
    18
    Reputation
    10
    Thanks
    2
    thank you, very good tutorial

  6. #51
    v_jones_yt's Avatar
    Join Date
    Jan 2018
    Gender
    male
    Location
    somewhere in the universe
    Posts
    18
    Reputation
    10
    Thanks
    1
    My Mood
    Inspired
    good job thanks man

  7. #52
    thoughtful's Avatar
    Join Date
    Nov 2017
    Gender
    male
    Location
    Canada
    Posts
    471
    Reputation
    30
    Thanks
    118
    My Mood
    Relaxed
    Quote Originally Posted by Blubb1337 View Post
    Improve your coding

    This is a small 'guide' on how to improve your coding and make it more clear. You can keep the overview, following these tips.

    If I forgot anything, please remind me /Sticky plox.

    Rename your controls

    This is important to actually keep your code clean.

    Do not keep the default control names like Button1/Textbox1.

    Rename them.

    Textbox1 = txtResult
    Button1 = cmdCalculate

    You can now easily recognize your events in your code, instead of having to search them.

    Comment your code

    This is obvious. You may forget stuff later on, therefore you can just add comments into your code.

    [php]'comment[/php]

    Use your datatypes correctly

    Code:
    Dim int as integer = "5"
    Dim str as string = "Sample Text" 
    
    txtResult.text = int
    Integer <> String. Therefore the correct way is:

    [php]Dim int as integer = 5[/php]

    Shorten your code

    Instead of writing:

    Code:
    txtResult.text = txtResult.text + int
    You better use:

    [php]txtResult.text += int[/php]

    Furthermore:

    [php]= 'obvious
    <> 'not the same, Noob <> Pro
    i <=5 'i is smaller than 5 or 5
    i >=5 'i is bigger than 5 or 5
    i < 5 'i is smaller than 5
    i > 5 'i is bigger than 5
    + 'add
    - 'substract
    * 'multiply
    / 'division
    [/php]

    Using

    Code:
    Dim str as IO.Streamreader = New Streamreader("C:\test.txt")
    
    txtResult.text = str.readtoend
    
    str.dispose
    [php]Using str as new Io.Streamreader("C:\test.txt")

    txtResult.text = str.readtoend

    End Using[/php]

    Case instead of If

    Code:
    If txtResult.text = "a" Then
    Msgbox("Newb")
    End if
    
    If txtResult.Text = "b" Then
    Msgbox("Newbie")
    End if
    
    If txtResult.text = "c" Then
    Msgbox("Noob")
    End if
    [php]Select Case txtresult.Text

    Case "a"
    Msgbox("Newb")

    Case "b"
    Msgbox("Newbie")

    Case "c"
    Msgbox("Noob")

    End Select[/php]

    If-Structures

    If condition Then
    [statements]
    ElseIf condition Then
    [statements]
    Else
    [statements]
    End If

    [php]If textbox1.text = "meh"
    'do something
    elseif Textbox1.text = "duh"
    'do something else
    else 'if it's neither meh nor duh
    'something
    end if[/php]

    Using Case...

    [php]Select Case Textbox1.Text
    Case "meh"
    'do something
    Case "Duh"
    'do something else
    Case Else
    'something
    end select[/php]

    [php]If Textbox1.text <> "" then 'if it's not empty
    end if[/php]

    If not...

    [php]If not textbox1.text = "" then
    end if[/php]

    Booleans

    [php]Dim b as boolean 'by default the boolean is FALSE[/php]

    Code:
    If b = true then
    'do something
    end if
    
    If b = false Then
    'do something
    end if
    [php]if b then 'true
    'do something
    else 'false
    'do something
    end if[/php]

    Try-Catch

    To avoid your program from closing when an error appears, you can use Try-Catch Blocks.

    [php]Try
    Timer.Value = txtResult.Text 'user may enter a letter instead of a number
    Catch ex as exception
    Msgbox(ex.Tostring) 'optional
    End try[/php]

    However, do not use them if they are not necessary.

    Code:
    Try
    Timer.Value = nudValue.Value 'NumericUpDown
    Catch ex as exception
    end try
    Regions

    You can use Regions to make your code more clear.

    [php]#Region "Settings"

    Private Sub spStartup_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles spStartup.CheckedChanged
    if spstartup then
    my.settings.spStartup = true 'run singleplayer on startup
    my.settings.save
    end if
    End sub

    Private Sub mpStartup_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mpStartup.CheckedChanged
    if spstartup then
    my.settings.mpStartup = true 'run multiplayer on startup
    my.settings.save
    end if
    End sub

    #End region[/php]

    Declare your own Subs/Function

    You may have a lot of repetitive code. Therefore, you can shorten your code a lot by building functions or subs.

    Code:
      'grenades
            If My.Settings.nade = true Then
    
                    string1 = readdll2("cshell.dll")
                    string2 = "&H" + Hex(string1 + &H108DFC8)
                    Call ITZAMOBSVG(string2, 1337, 4)
               
            End If
    
            'flashs
            If My.Settings.flash = true Then
    
                    string1 = readdll2("cshell.dll")
                    string2 = "&H" + Hex(string1 + &H108DFD4)
                    Call ITZAMOBSVG(string2, 1337, 4)
              
            End If
    
            'grenade launcher
            If My.Settings.gl = true Then
    
                    string1 = readdll2("cshell.dll")
                    string2 = "&H" + Hex(string1 + &H108DF64)
                    Call ITZAMOBSVG(string2, 1337, 4)
               
            End If
    [php]Private sub h4x(ByVal address as string, byval value as long, byval bytes as integer)
    string1 = readdll2("cshell.dll")
    string2 = "&H" + Hex(string1 + address)
    Call ITZAMOBSVG(string2, value, bytes)
    End sub[/php]

    [php]If My.Settings.nade Then
    h4x(&H108DFC8, 1337, 4)
    End If

    'flashs
    If My.Settings.flash Then
    h4x(&H108DFD4, 1337, 4)
    End If

    'grenade launcher
    If My.Settings.gl Then
    h4x(&H108DF64, 1337, 4)
    End If[/php]

    What is the difference between a function and a sub?

    A function always returns something.

    [php]Private Sub calculate(byval number1 as integer, byval number2 as integer)
    textbox1.text = number1 + number2
    end sub[/php]

    [php]calculate(5,3)[/php]

    [php]private function calculate(byval number1 as integer, byval number2 as integer)
    return number1 + number2
    end function
    [/php]

    [php]textbox1.text = calculate(5,3)[/php]

    With

    Code:
    lblStatus.text = "Something"
    lblstatus.BackColor = Color.Yellow 
    lblstatus.Location = New Point(50, 100)
    lblstatus.visible = true
    [php]With lblstatus
    .text = "Something"
    .backcolor = color.yellow
    .location = new point(50, 100)
    .visibile = true
    end with[/php]


    Structure

    Code:
    Dim firstPos as point
    Dim firstDir as string 
    Dim firstFrame as integer
    
    Dim secondPos as point 
    Dim secondDir as string 
    Dim secondFrame as integer
    
    Dim thirdPos as point
    Dim thirdDir as string
    Dim thirdFrame as integer
    [php]Structure meh
    Dim Pos As Point
    Dim Dir As String
    Dim Frame As Integer
    end structure

    dim first as meh
    dim second as meh
    dim third as meh[/php]

    [php]first.dir = "up"[/php]


    I will try to update this topic with more improvements.

    I do hope you will now code "cleaner". This will improve your coding.
    [/QUOTE]

    Honestly if you don't know how to comment your code and indent, you're a bad coder.

  8. #53
    simplehack98's Avatar
    Join Date
    Aug 2015
    Gender
    male
    Posts
    37
    Reputation
    10
    Thanks
    4
    My Mood
    Fine
    Nice tutorial my friend

  9. #54
    shipo95's Avatar
    Join Date
    Nov 2016
    Gender
    male
    Posts
    14
    Reputation
    10
    Thanks
    0

    Talking Thanks

    thanks man

  10. #55
    wagamama's Avatar
    Join Date
    Nov 2018
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    0
    Great tutorial. Mainly a Python guy, but I do stumble across PHP projects from time to time, and this will definitely come in useful.

  11. #56
    PyramidStore's Avatar
    Join Date
    Feb 2019
    Gender
    male
    Posts
    114
    Reputation
    10
    Thanks
    2
    Very nice.. yes commenting and shorten code is quit helpful

  12. #57
    bannekz's Avatar
    Join Date
    Apr 2017
    Gender
    male
    Posts
    17
    Reputation
    10
    Thanks
    0
    Good job for this!

  13. #58
    gasparzinhod's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Posts
    14
    Reputation
    10
    Thanks
    0

    Great

    Great job friend, thank you!

  14. #59
    jack9090's Avatar
    Join Date
    Mar 2019
    Gender
    male
    Posts
    12
    Reputation
    10
    Thanks
    0
    Cheers mate!

  15. #60
    worldwidesafe's Avatar
    Join Date
    Jun 2020
    Gender
    male
    Location
    SAFE
    Posts
    35
    Reputation
    10
    Thanks
    711
    thanks bruh

Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. Improve your reaction
    By Ferris Bueller in forum CrossFire Tutorials
    Replies: 13
    Last Post: 06-07-2011, 09:16 AM
  2. [Tutorial] HOW TO IMPROVE YOUR COMPUTERS FPS AND IN GENRAL!
    By Death217 in forum CrossFire Tutorials
    Replies: 8
    Last Post: 03-27-2011, 05:19 PM
  3. [Request] Mechanical share your code
    By deadman027 in forum CrossFire PH Discussions
    Replies: 13
    Last Post: 10-11-2010, 06:13 AM
  4. How Can I Improve This Code ?
    By kelechi96 in forum Combat Arms EU Hack Coding/Source Code
    Replies: 8
    Last Post: 08-02-2010, 10:51 AM
  5. Do you take drugs to improve your gameplay?
    By CAPTAIN OBVIOUS in forum General
    Replies: 23
    Last Post: 04-11-2008, 09:48 PM