Dim ProcudureNow As String 'ประกาศตัวแปรนี้ไว้บนหัว Module
'คำสั่งอันที่ 1 Sub TestCommand01() ProcudureNow="TestCommand01" ..... ..... End Sub
'คำสั่งอันที่ 2 Sub TestCommand02() ProcudureNow="TestCommand02" ..... ..... End Sub
'คำสั่งที่ใช้ตรวจสอบว่า Procudure ตัวใหนกำลังทำงาน Sub CheckProcudureName() if ProcudureNow="TestCommand01" then ..... ..... elseif ProcudureNow="TestCommand02" then ..... ..... End if End Sub
จากโค้ดข้างบน ผมไม่ต้องประกาศตัวแปร Dim ProcudureNow As String นี้ไว้บนหัว Module กันแล้ว เพราะหันมา Function เป็นตัวช่วยตรวจสอบ พร้อมๆกับอ้างชื่อได้ในขณะทำงานเลย รูปแบบเป็นดั่งนี้
'คำสั่งอันที่ 1 Sub TestCommand01() CheckProcudureName "TestCommand01" 'ระบุชื่อไปพร้อมๆกับการเรียกใช้ฟังก์ชั่น ..... ..... End Sub
'คำสั่งอันที่ 2 Sub TestCommand02() CheckProcudureName "TestCommand02" ..... ..... End Sub
'คำสั่งที่ใช้ตรวจสอบว่า Procudure ตัวใหนกำลังทำงาน Function CheckProcudureName(ProcudureNow As String) if ProcudureNow="TestCommand01" then ..... ..... elseif ProcudureNow="TestCommand02" then ..... ..... End if End Sub