iT邦幫忙

0

Power builder程式碼分析

匿名 2011-07-19 18:15:307920 瀏覽

大略說明分析程式語法 那一段是做什麼的就好
祇是想看個懂 當然詳細者得勝

string ls_filename
string ls_path
string ls_data
string ls_new_path
string ls_path_1
integer li_item
integer i
integer li_filenum
integer li_ret
integer li_pos
integer ll_index
string ls_des
string ls_filepath


ls_filepath = parent.is_source + "D*T*.CSV"
parent.lb_1.dirlist(ls_filepath,1)
li_item = parent.lb_1.totalitems()
changedirectory(parent.is_source)

for i = 1 to li_item

	if (((left(parent.lb_1.text(i),3) = "T1M") or (left(parent.lb_1.text(i),2) = "BB")) or (right(parent.lb_1.text(i),3) = "MOK")) then
	else

		if left(parent.lb_1.text(i),1) = "D" and mid(parent.lb_1.text(i),10,1) = "T" then
			ls_filename = trim(parent.lb_1.text(i))
			ll_index = 0
			ls_path = ""
			li_filenum = fileopen(ls_filename,linemode!,read!,lockwrite!,append!)

			if li_filenum = -1 then
			else
				li_ret = fileread(li_filenum,ls_data)

				do while li_ret <> -100
					li_pos = pos(ls_data,"C-Lot NO.,")

					if li_pos > 0 then
						li_pos = pos(ls_data,",")
						ls_path = mid(ls_data,li_pos + 1)

						if ((isnull(ls_path)) or (len(trim(ls_path)) = 0)) then
							fileclose(li_filenum)
							parent.f_directory(parent.is_source,parent.is_err)
							parent.f_fileerror(ls_filename,parent.is_source,parent.is_source + parent.is_err)
							exit
						end if

					end if

					li_pos = pos(ls_data,"Bin Table File")

					if li_pos > 0 then
						li_pos = pos(ls_data,",")

						if li_pos > 0 then
							ls_path = mid(ls_data,li_pos + 1)

							if len(trim(ls_path)) <= 0 then
								fileclose(li_filenum)
								parent.f_directory(parent.is_source,parent.is_err)
								parent.f_fileerror(ls_filename,parent.is_source,parent.is_source + parent.is_err)
							else
								ls_path = mid(ls_path,21)
							end if

							li_ret = fileread(li_filenum,ls_data)
							li_pos = pos(ls_data,"P-Lot NO.,")

							if li_pos > 0 then
								li_pos = pos(ls_data,",")
								ls_path_1 = mid(ls_data,li_pos + 1)

								if ls_path_1 <> left(ls_filename,9) then
									fileclose(li_filenum)
									parent.f_directory(parent.is_source,parent.is_err)
									parent.f_fileerror(ls_filename,parent.is_source,parent.is_source + parent.is_err)
									ls_path_1 = ""
									ls_path = ""
									exit
								end if

							end if

							exit
						end if

					end if

					li_ret = fileread(li_filenum,ls_data)
				loop

				fileclose(li_filenum)

				if ((len(trim(ls_path)) = 0) or (isnull(ls_path))) then
				else
					ls_new_path = ""
					li_pos = pos(ls_path,"\")

					do while li_pos > 0
						ll_index ++

						if ll_index < 4 then
							ls_new_path = ls_new_path + mid(ls_path,1,li_pos)
						end if

						ls_path = mid(ls_path,li_pos + 1)
						li_pos = pos(ls_path,"\")
					loop

					ls_new_path = ls_new_path + mid(ls_path,pos(ls_path,"(") + 1,pos(ls_path,")") - pos(ls_path,"(") - 1) + "\"
					parent.f_directory(parent.is_source,ls_new_path)
					ls_des = ls_new_path + ls_filename
					fileclose(li_filenum)
					li_filenum = filecopy(parent.is_source + ls_filename,ls_des,true)

					if li_filenum <> 1 then
					else
						filedelete(parent.is_source + ls_filename)
					end if

				end if

			end if

		end if

	end if

next

return
ycl8000 iT邦高手 1 級 ‧ 2011-07-20 08:08:39 檢舉
解析 D*T*.CSV 檔案內容的程式
你對照一下程式執行前跟執行後,就知道程式做什麼了.
ycl8000 iT邦高手 1 級 ‧ 2011-08-01 08:13:28 檢舉
"D*T*.CSV"

麻煩將這些檔案的內容PO一些出來, 這樣比較容易看程式.
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

2
wildox
iT邦新手 3 級 ‧ 2011-08-17 14:50:21
最佳解答

我好像太鹹了,請服用:

//要過濾的檔案名稱
ls_filepath = parent.is_source + "D*T*.CSV"
//取得過濾的檔案列表
parent.lb_1.dirlist(ls_filepath,1)
//取得列表的檔案數量
li_item = parent.lb_1.totalitems()
//變更路徑到過濾檔案路徑下
changedirectory(parent.is_source)
//依列表逐一檔案處理
for i = 1 to li_item
//取得檔案列表中去除檔頭T1M*.*和BB*.*和*.MOK不處理
if (((left(parent.lb_1.text(i),3) = "T1M") or (left(parent.lb_1.text(i),2) = "BB")) or (right(parent.lb_1.text(i),3) = "MOK")) then
else
//只處理D*T*.CSV中檔案名稱符合DxxxxxxxxT*.csv的檔案
if left(parent.lb_1.text(i),1) = "D" and mid(parent.lb_1.text(i),10,1) = "T" then
//取得完整檔案名稱
ls_filename = trim(parent.lb_1.text(i))
ll_index = 0
ls_path = ""
//開啟檔案(以單列唯讀取模式)
li_filenum = fileopen(ls_filename,linemode!,read!,lockwrite!,append!)
//開啟失敗不處理
if li_filenum = -1 then
else
//讀取檔案中一行資料
li_ret = fileread(li_filenum,ls_data)
//如果有沒有EOF
do while li_ret <> -100
//檢查該列資料是否有C-Lot NO.資料(可能是第一欄)
li_pos = pos(ls_data,"C-Lot NO.,")
//如果有
if li_pos > 0 then
//取得該資料欄位下一欄(應該是紀錄路徑ls_path)
li_pos = pos(ls_data,",")
ls_path = mid(ls_data,li_pos + 1)
//如果下一欄路徑資料不存在,則紀錄錯誤並停止該檔處理
if ((isnull(ls_path)) or (len(trim(ls_path)) = 0)) then
fileclose(li_filenum)
parent.f_directory(parent.is_source,parent.is_err)
parent.f_fileerror(ls_filename,parent.is_source,parent.is_source + parent.is_err)
exit
end if

end if
//檢查該列資料是否有Bin Table File資料
li_pos = pos(ls_data,"Bin Table File")
//若有
if li_pos > 0 then
//取得第二欄位置
li_pos = pos(ls_data,",")
//若有該欄位
if li_pos > 0 then
//取得該欄位資料
ls_path = mid(ls_data,li_pos + 1)
//如果該欄位是空的則紀錄錯誤,並停止該檔處理
if len(trim(ls_path)) <= 0 then
fileclose(li_filenum)
parent.f_directory(parent.is_source,parent.is_err)
parent.f_fileerror(ls_filename,parent.is_source,parent.is_source + parent.is_err)
else
//取額該欄位資料的第21byte以後的字串當路徑ls_path
ls_path = mid(ls_path,21)
end if
// 讀取下一行(這個讀取是在有Bin Table File行下)
li_ret = fileread(li_filenum,ls_data)
//檢查該行是否有P-Lot NO.資料
li_pos = pos(ls_data,"P-Lot NO.,")
//若有
if li_pos > 0 then
//取得該欄的下一個欄位資料ls_path_1
li_pos = pos(ls_data,",")
ls_path_1 = mid(ls_data,li_pos + 1)
//如果ls_path_1內容與正在處理的檔案前9碼(Dxxxxxxxx)不相同則紀錄錯誤,並停止該檔處理
if ls_path_1 <> left(ls_filename,9) then
fileclose(li_filenum)
parent.f_directory(parent.is_source,parent.is_err)
parent.f_fileerror(ls_filename,parent.is_source,parent.is_source + parent.is_err)
ls_path_1 = ""
ls_path = ""
exit
end if

end if

exit
end if

end if
//若是上述檢查都沒發生,繼續處理下一行
li_ret = fileread(li_filenum,ls_data)
loop
//關閉正在處理的檔案
fileclose(li_filenum)
//如果該檔案內都沒有取得ls_path的紀錄描述則不處理
if ((len(trim(ls_path)) = 0) or (isnull(ls_path))) then
else
//該檔案有取得ls_path紀錄描述
ls_new_path = ""
//則取出第一個路徑節點("\")的字串位置
li_pos = pos(ls_path,"\")
//若有
do while li_pos > 0
ll_index ++
//最多只取得該路徑四層(後面捨棄)ls_new_path
if ll_index < 4 then
ls_new_path = ls_new_path + mid(ls_path,1,li_pos)
end if

ls_path = mid(ls_path,li_pos + 1)
li_pos = pos(ls_path,"\")
loop
//該路徑會再加上一層路徑(ls_path裡背括號刮起來的部份
ls_new_path = ls_new_path + mid(ls_path,pos(ls_path,"(") + 1,pos(ls_path,")") - pos(ls_path,"(") - 1) + "\"
//建立新路徑
parent.f_directory(parent.is_source,ls_new_path)
//產生完整路徑檔案名稱ls_des
ls_des = ls_new_path + ls_filename
//關閉正在處理的檔案
fileclose(li_filenum)
//將正在處理的檔案複製到新的路徑檔案
li_filenum = filecopy(parent.is_source + ls_filename,ls_des,true)
//複製失敗不處理
if li_filenum <> 1 then
else
//複製成功則刪除原始檔案
filedelete(parent.is_source + ls_filename)
end if

end if

end if

end if

end if

next

return

wildox iT邦新手 3 級 ‧ 2011-08-17 14:51:33 檢舉

哎呀,貼回去原始碼,前面的空白都不見了....版面自己理解嚕

gidetw iT邦新手 4 級 ‧ 2011-08-20 13:48:56 檢舉

拍手

gidetw iT邦新手 4 級 ‧ 2011-08-20 13:50:43 檢舉

這年頭非MS即Java,當年 PB 和 delphi 雖仍存在,但要學的很少了

2
gidetw
iT邦新手 4 級 ‧ 2011-07-20 08:57:49

得勝是什麼獎品?你這個應是用反組譯跑出來的程式吧

我要發表回答

立即登入回答