PDA

View Full Version : روش نوشتن کامنت



zohresh
جمعه 01 بهمن 1389, 10:26 صبح
سلام
یه برنامه نویس حرفه ای باید بتونه خوب هم برای کد برنامه کامنت بنویسه(بصورت حرفه ای)
اگه کسی از دوستان میتونه تو این زمینه راهنمایی کنه دریغ نفرمایید.

reza_edu
جمعه 01 بهمن 1389, 10:44 صبح
خوب چیکار میخوای انجام بدی؟

zohresh
جمعه 01 بهمن 1389, 12:27 عصر
برای مثال واسه کد زیر میخوام کامنت بنویسم
Imports System.IO.File
Imports WindowsApplication1
Imports System.IO.Stream
Imports System.String
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim a As Array
Dim filename As String = ""
Dim textline As String = ""
Dim s_sh_from As Integer
Dim s_sh_to As Integer
Dim s_sh_step As Integer
Dim counter As Integer
__________________________________________________ __________________________________________________ _______
Private Function s_sh_find_in_text(ByRef objectreader As System.IO.StreamReader, ByVal how_to_find As String, ByRef str As String) As Integer
Dim find As Integer = 0
Do While objectreader.Peek <> -1 And find = 0
str = objectreader.ReadLine()
find = InStr(str, how_to_find)
Loop
Return find
End Function
__________________________________________________ __________________________________________________ _________
Function s_sh_Return_field(ByRef objectreader As System.IO.StreamReader, ByVal pattern As String, ByRef end_of_search As Boolean) As String
'initial
end_of_search = False
Dim str As String = ""
Dim l_location As Integer
Dim r_location As Integer
Dim tmp_s_sh_find_in_text As Integer
tmp_s_sh_find_in_text = s_sh_find_in_text(objectreader, pattern, str)
If tmp_s_sh_find_in_text = 0 Then
end_of_search = True
Return ""
End If
l_location = tmp_s_sh_find_in_text + pattern.Length - 1
r_location = InStr(l_location, str, "<")
Return str.Substring(l_location, r_location - l_location - 1)
End Function
__________________________________________________ __________________________________________________ ________
Private Sub s_sh_save_data_to_database(ByRef record_pattern As String(), ByVal count_of_fields As Integer, ByVal count_of_pattern As Integer)
Dim record_data(count_of_pattern) As String
Dim objreader As New System.IO.StreamReader(WebBrowser1.DocumentStream)
Do Until s_sh_Return_record(objreader, record_pattern, record_data, count_of_fields, count_of_pattern)
Dim constr As String = "provider=microsoft.jet.oledb.4.0;" & "Data Source=db1.mdb"
Dim con As New OleDbConnection(constr)
con.Open()
Dim cmdstr As String = "insert into manager values ("
For i = 1 To count_of_fields
If i <= count_of_pattern Then
cmdstr = cmdstr + "'" + record_data(i) + "',"
Else
cmdstr = cmdstr + "'',"
End If
Next i
cmdstr = cmdstr.Substring(0, cmdstr.Length - 1)
cmdstr = cmdstr + ")"
Dim cmd As New OleDbCommand(cmdstr, con)
cmd.ExecuteNonQuery()
con.Close()
Loop
End If
End Sub
__________________________________________________ __________________________________________________ _______
Private Function s_sh_Return_record(ByRef objreader As System.IO.StreamReader, ByRef record_pattern As String(), ByRef record_data As String(), ByVal number_of_field As Integer, ByVal count_of_pattern As Integer) As Boolean
Dim end_of_page As Boolean = False
For i = 1 To count_of_pattern
record_data(i) = s_sh_Return_field(objreader, record_pattern(i), end_of_page)
Next i
Return end_of_page
End Function
================================================== ================================================== =
Private Sub Button_get_from_net_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_get_from_net.Click
counter = 1
s_sh_from = Val(TextBox_from.Text)
s_sh_to = Val(TextBox_to.Text)
s_sh_step = Val(TextBox_step.Text)
WebBrowser1.Navigate("http://ketabeavval.ir/Search/?q=%D8%AF%D8%A7%D8%B1%D9%88&start=" + Str(s_sh_from) + "&s=~&cache=1&st=a")
ProgressBar1.Minimum = s_sh_from
ProgressBar1.Maximum = s_sh_to
End Sub
================================================== =================================================
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs) Handles WebBrowser1.DocumentCompleted
If counter = 2 Then
Const count_of_pattern = 3
Const count_of_fields = 10
Dim record_pattern(count_of_pattern) As String
record_pattern(1) = "lblCompName"">"
record_pattern(2) = "lblManager"">"
record_pattern(3) = "lblPhone"">"
'record_pattern(4) = "lblFax"">"
'record_pattern(5) = "Address"" class=""sResultContent"">"
'record_pattern(6) = """postcode"">"
s_sh_save_data_to_database(record_pattern, count_of_fields, count_of_pattern)
s_sh_from = s_sh_from + s_sh_step
If s_sh_to < s_sh_from Then s_sh_from = s_sh_to
ProgressBar1.Value = s_sh_from
If s_sh_to > s_sh_from Then
WebBrowser1.Navigate("http://ketabeavval.ir/Search/?q=%D8%AF%D8%A7%D8%B1%D9%88&start=" + Str(s_sh_from) + "&s=~&cache=1&st=a")
End If
counter = 1
End If
counter = counter + 1
End Sub
================================================== =================================================
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As Integer
Dim textline As String = ""
OpenFileDialog1.InitialDirectory = "i:\"
OpenFileDialog1.Title = "open a text file "
OpenFileDialog1.Filter = "text file|*.txt"
f = OpenFileDialog1.ShowDialog()
filename = OpenFileDialog1.FileName
MsgBox(filename)
Dim didwork As Integer = f
If didwork = DialogResult.Cancel Then
MsgBox("cancel Button clicked")
Else
If System.IO.File.Exists(filename) = True Then
Dim objreader As New System.IO.StreamReader(filename)
Do While objreader.Peek <> -1
textline = textline & objreader.ReadLine() & vbNewLine
Loop
RichTextBox1.Text = textline
filename = OpenFileDialog1.FileName
End If
End If
'Dim a As New System.IO.StreamReader(WebBrowser1.DocumentStream)
End Sub

محسن شامحمدی
جمعه 01 بهمن 1389, 16:56 عصر
دوست عزیز
این اگر این تاپیک رو بخونید مطمئنا به یک جواب کامل و فنی می رسید.
موفق باشید
گفتگوی فنی شماره یک - اصول و قواعد کد نویسی (http://barnamenevis.org/showthread.php?224704-%DA%AF%D9%81%D8%AA%DA%AF%D9%88%DB%8C-%D9%81%D9%86%DB%8C-%D8%B4%D9%85%D8%A7%D8%B1%D9%87-%DB%8C%DA%A9-%D8%A7%D8%B5%D9%88%D9%84-%D9%88-%D9%82%D9%88%D8%A7%D8%B9%D8%AF-%DA%A9%D8%AF-%D9%86%D9%88%DB%8C%D8%B3%DB%8C)