Delete first part of field (97 )
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 252   1
URL.หัวข้อ / URL
Delete first part of field (97 )

มีคนถามคำถามนี้ไว้ที่ 
http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=acc&Number=164497&page=2&view=expanded&sb=5&o=0&fpart= 
 
ถามไว้ดังนี้ 
 
I have been given a project which involves housing properties. My problem involves getting rid of the house numbers at the first part of the field as the data has been set up with the house/flat number and the road in the same field. The second problem is that it comes on different formats as listed below: 
1 Acacia Avenue 
1-11 Acacia Avenue 
11 Acacia Avenue 
111 Acacia Avenue 
 
Is there some code can loop through the data and removes these spurious numbers and hyphens which stops at the First Letter so that I can sort by road name and not the house number.  
 
สรุปได้ว่า เขามีฟีลด์ที่เก็บบ้านเลขที่ และถนนไว้ในฟีลด์เดียวกัน เขาต้องการที่จะเอาบ้านเลขที่ออก ให้เหลือแต่ชื่อถนน เพื่อจะได้เรียงข้อมูลใน Query ตามชื่อถนนได้ 
 
มีคนตอบไว้แล้วครับ ลองเข้าไปดู 
 
แต่ผมได้นำคำถามนี้มาคิดต่อในแนวทางของผม คือ การสร้างฟังก์ชันขึ้นมา เพื่อให้เหลือแต่ชื่อถนน ได้โค้ดดังนี้ครับ 
 
Function RemoveHouseNo(strString As String) 
Dim I As Integer, strRdName As String 
For I = 1 To Len(strString) 
    If Asc(Mid(strString, I, 1)) > 64 Then 
        strRdName = Mid(strString, I) 
        Exit For 
    End If 
Next I 
RemoveHouseNo = strRdName 
End Function 
 
การทดสอบการใช้งาน ได้ผลดังนี้ 
? RemoveHouseNo("1 Acacia Avenue") 
Acacia Avenue 
 
? RemoveHouseNo("1-11 Acacia Avenue") 
Acacia Avenue 
 
? RemoveHouseNo("11 Acacia Avenue") 
Acacia Avenue 
 
? RemoveHouseNo("111 Acacia Avenue") 
Acacia Avenue 
 
เวลานำไปใช้ใน Query ก็เพียงแต่ให้เพิ่มฟีลด์ลงไปอีก 1 ฟีลด์ แล้วใส่ค่าเหล่านี้ลงไปครับ 
 
SortByRoad: RemoveHouseNo([ชื่อฟีลด์ที่เก็บบ้านเลขที่และถนน]) 
*** Edited by Supap Chaiya *** 30/4/2003 21:36:21

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06536
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0566s