0% found this document useful (0 votes)
12 views

Visual Basicfinal Course2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Visual Basicfinal Course2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

‫اﺳم اﻟﻣﺎدة ‪Visual Basic :‬‬

‫اﻟﻣرﺣﻠﺔ ‪ :‬اﻻوﻟﻰ‬
‫اﻟﻘﺳم ‪ :‬اﻟﻔﯾزﯾﺎء‬
‫ﻋﻣﻠﻲ – اﻟﻛورس اﻟﺛﺎﻧﻲ‬
‫ﺑﺄﺷراف م‪ .‬ﺣﯾدر ﻋﺑدﷲ ﻛﺎظم‬
‫اﻋداد‬
‫م ﻋﻠﻲ ﺟﺎﺳم ﻣﺣﻣد ﻋﻠﻲ‬
‫م‪ .‬ﺳﻌد ﻧﺎﻓﻊ اﺑراھﯾم‬

‫اﺣﻤﺪ‬ ‫م‪.‬م زﯾﻧب ﺣﻣﯾد‬

‫م‪.‬م رﻏد ﻋﺑدﷲ ﻛﺎظم‬


‫م‪.‬م ﻟﻘﺎء ﻋﺑد اﻟﻛرﯾم ﺣﺳﯾن‬
‫اﻟﺮؤﯾﺎ‬

‫ﯾﺘﻄﻠﻊ ﻣﺨﺘﺒﺮ اﻟﺤﺎﺳﺒﺎت اﻟﻰ اﻟﺘﻤﯿﺰ ﻣﻦ ﺧﻼل ﺗﻘﺪﯾﻢ ﻣﺠﻤﻮﻋﺔ ﻣﻦ اﻟﻤﺨﺘﺒﺮات اﻟﺒﺮﻣﺠﯿﺔ ﻟﻠﻤﻮاد اﻟﺨﺎﺻﺔ ﺑﻘﺴﻢ اﻟﻔﯿﺰﯾﺎء ﺑﺤﯿﺚ ﯾﺤﻘﻖ‬
‫اﻟﻤﺴﺘﻮﯾﺎت اﻟﻤﻌﯿﺎرﯾﺔ اﻟﻤﺮﻣﻮﻗﺔ ﻓﻲ ﻣﺠﺎل اﻟﺤﺎﺳﺒﺎت ﻣﻤﺎ ﯾﺴﺎﻋﺪ ﻋﻠﻰ إﻋﺪاد ﻛﻔﺎءات وطﻨﯿﺔ ﻣﺆھﻠﺔ وﻣﺪرﺑﺔ ‪.‬اﻟﺘﻤﯿﺰ ﻓﻲ ﻣﺠﺎل اﻟﺘﻌﻠﯿﻢ‬
‫واﻟﺒﺤﺚ اﻟﻌﻠﻤﻲ ﻟﻠﺘﻨﻤﯿﺔ اﻟﻤﺠﺘﻤﻌﯿﺔ ﺑﻤﻌﺎﯾﯿﺮ ﻣﻤﺘﺎزة‪.‬‬

‫اﻟﺮﺳﺎﻟﺔ‬

‫ﺗﻨﺒﺜﻖ رﺳﺎﻟﺔ ﻣﺨﺘﺒﺮ اﻟﺤﺎﺳﺒﺎت ﻣﻦ رﺳﺎﻟﺔ ﻗﺴﻢ اﻟﻔﯿﺰﯾﺎء ﺣﯿﺚ ﯾﮭﺪف ﻗﺴﻢ اﻟﻔﯿﺰﯾﺎء إﻟﻰ إﻋﺪاد ﻣﺘﺨﺼﺼﯿﻦ ﻣﺘﻤﯿﺰﯾﻦ ﻓﻲ ﻣﺠﺎل اﻟﺤﺎﺳﻮب‬
‫ﻓﻲ اﻟﻔﯿﺰﯾﺎء‪ ،‬وﺗﻌﺰﯾﺮ اﻟﺒﺤﺚ اﻟﻌﻠﻤﻲ ‪ ،‬واﻹﺳﮭﺎم ﻓﻲ ﺧﺪﻣﺔ اﻟﻤﺠﺘﻤﻊ ﻣﺤﻠﯿﺎً وإﻗﻠﯿﻤﯿﺎ وﻓﻘﺎً ﻟﻤﻌﺎﯾﯿﺮ اﻟﺠﻮدة اﻟﺸﺎﻣﻠﺔ واﻟﻤﺘﻄﻠﺒﺎت اﻻﺧﻼﻗﯿﺔ‬
‫واﻟﻤﮭﻨﯿﺔ؛ وذﻟﻚ ﻣﻦ ﺧﻼل اﻋﺪاد ﺧﻄﻂ دراﺳﯿﺔ ﺗﺘﻮاﻛﺐ ﻣﻊ اﻟﻤﺴﺘﺠﺪات ﻓﻲ ﺗﺨﺼﺺ ﻋﻠﻮم اﻟﺤﺎﺳﻮب‪ ,‬وﺗﻮظﯿﻒ ﻋﻠﻮم اﻟﺤﺎﺳﻮب ﻓﻲ‬
‫ﻋﻤﻠﯿﺘﻲ اﻟﺘﻌﻠﯿﻢ واﻟﺘﻌﻠﻢ وﺗﺒﻨﻲ اﺣﺪث اﺳﺘﺮاﺗﯿﺠﯿﺎت اﻟﺘﻌﻠﻢ ﻟﺒﻨﺎء اﻟﻤﻌﺮﻓﺔ واﻟﻘﺪرات وﺻﻘﻞ ﻣﮭﺎرات اﻟﻄﻠﺒﺔ‪ .‬اﻋﺪاد وﺗﻄﻮﯾﺮ اﻟﻜﻮادر‬
‫اﻟﻌﻠﻤﯿﺔ اﻟﻤﺘﺨﺼﺼﺔ ﻓﻲ اﻟﻤﺨﺘﺒﺮ ﻟﯿﺼﺒﺢ ﻟﻘﺴﻢ اﻟﻔﯿﺰﯾﺎء أﻧﻤﻮذﺟﺎ أﻛﺎدﯾﻤﯿﺎ راﺋﺪا وﻣﺘﻤﯿﺰا ﻣﻦ ﺧﻼل إﻋﺪاد اﻟﻄﻠﺒﺔ ﻟﺴﻮق اﻟﻌﻤﻞ وﺗﻨﻤﯿﺔ‬
‫ﻗﺪراﺗﮭﻢ ﻋﻠﻰ اﻟﺘﻔﺎﻋﻞ واﻟﺘﻮاﺻﻞ ﻣﻊ اﻵﺧﺮﯾﻦ وﺻﻮﻻ ﻟﻤﺠﺘﻤﻊ اﻟﻤﻌﻠﻮﻣﺎﺗﯿﺔ‪.‬‬

‫اﻷھﺪاف‬

‫ان اﻷھﺪاف اﻟﺮﺋﯿﺴﯿﺔ ﻟﻠﻤﺨﺘﺒﺮ ھﻲ ﺿﻤﺎن أن ﯾﺘﺨﺮج اﻟﻄﺎﻟﺐ وھﻮ ﯾﻤﺘﻠﻚ اﻟﻤﮭﺎرات واﻟﻤﻌﺎرف اﻟﺘﺎﻟﯿﺔ‪:‬‬

‫ﻣﮭﺎرات ﺣﻞ اﻟﻤﺸﺎﻛﻞ‬ ‫‪-‬‬


‫اﻟﻤﻌﺮﻓﺔ اﻟﺠﻮھﺮﯾﺔ ﻟﻔﺌﺔ واﺳﻌﺔ ﻣﻦ ﺗﻘﻨﯿﺎت ﺣﻞ اﻟﻤﺸﺎﻛﻞ )ﻋﻠﻰ ﺳﺒﯿﻞ اﻟﻤﺜﺎل‪ :‬اﻟﺨﻮارزﻣﯿﺎت‪ ،‬اﻻﺳﺘﺪﻻل‪ ،‬وﺗﻘﻨﯿﺎت‬ ‫‪-‬‬
‫اﻟﺒﺮﻣﺠﺔ(‪.‬‬
‫ﻓﮭﻢ ﺟﻮھﺮي ﻷﺳﺎﺳﯿﺎت ﻋﻠﻮم اﻟﺤﺎﺳﺒﺎت‪.‬‬ ‫‪-‬‬
‫اﻟﻘﺪرة ﻋﻠﻰ اﻟﺘﻮاﺻﻞ ﻣﻊ اﻻﺧﺮﯾﻦ ﺑﻮﺿﻮح ﺑﺎﺳﺘﺨﺪام اﻟﻤﻔﺎھﯿﻢ اﻟﺘﻘﻨﯿﺔ ﺷﻔﮭﯿﺎ وﺧﻄﯿﺎ‪.‬‬ ‫‪-‬‬
‫اﻟﻘﺪرة ﻋﻠﻰ اﻟﻌﻤﻞ ﻣﻊ اﻻﺧﺮﯾﻦ ﻣﻦ اﻟﺘﺨﺼﺼﺎت اﻻﺧﺮى‪.‬‬ ‫‪-‬‬
‫اﻟﺘﻄﻮﯾﺮ اﻟﻤﻨﺎﺳﺐ ﻟﻠﻤﻨﺎھﺞ اﻟﺪراﺳﯿﺔ ﺑﻤﺎ ﯾﻀﻤﻦ دﻣﺞ اﻟﺘﻐﯿﺮات ﻓﻲ ﺗﻜﻨﻮﻟﻮﺟﯿﺎ ﻋﻠﻮم اﻟﺤﺎﺳﺒﺎت و اﻟﻔﯿﺰﯾﺎء‪.‬‬ ‫‪-‬‬
‫ﺗﺰوﯾﺪ اﻟﻤﺠﺘﻤﻊ اﻟﻤﺤﻠﻰ ﺑﺎﻟﻜﻮادر اﻟﻤﺆھﻠﺔ ﻋﻠﻤﯿﺎ وﻋﻤﻠﯿﺎ‪.‬‬ ‫‪-‬‬

‫‪1|Page‬‬
‫ﻣﻘﺪﻣﺔ ﻓﻲ اﻟﺒﺮﻣﺠﺔ‬

‫‪Visual Basic‬ﻟﻠﺘﻄﺒﯿﻘﺎت )‪ (VBA‬ھﻲ ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ اﻟﻤﺴﺘﺨﺪﻣﺔ ﻓﻲ ‪ Excel.‬ﻣﻊ ذﻟﻚ ﯾﻤﻜﻨﻚ أﺗﻤﺘﺔ اﻟﻤﮭﺎم‪،‬‬
‫إﺿﺎﻓﺔ ﻣﯿﺰات ﻣﺨﺼﺼﺔ وظﺎﺋﻒ‪ ،‬وﺣﺘﻰ إﻧﺸﺎء ﺗﻄﺒﯿﻘﺎت ﻛﺎﻣﻠﺔ ‪.‬‬

‫ﻓﻲ ‪ Excel‬وﻣﺆﺗﻤﺘﺔ اﻟﻤﮭﺎم ﻣﻦ ﻗﺒﻞ وﺣﺪات اﻟﻤﺎﻛﺮو ‪ -‬ﺳﻠﺴﻠﺔ ﻣﻦ اﻟﺘﻌﻠﯿﻤﺎت اﻟﻤﻜﺘﻮﺑﺔ ﻓﻲ ‪ VB‬أن أﻗﻮل إﻛﺴﻞ ﻣﺎ‬
‫ﯾﺠﺐ اﻟﻘﯿﺎم ﺑﮫ‪ .‬ﻟﺘﺴﮭﯿﻞ ﺧﻠﻘﮭﻢ ﯾﻮﻓﺮ ‪ Excel‬ﻣﯿﺰة ﺗﺴﻤﻰ ﻣﺴﺠﻞ اﻟﻤﺎﻛﺮو ‪ -‬اﻟﺬي ﯾﻜﺘﺐ وﺣﺪات اﻟﻤﺎﻛﺮو ﺑﺎﻟﻨﺴﺒﺔ ﻟﻚ!‬
‫ﻷﻧﮫ ﯾﺨﺰن اﻹﺟﺮاءات ﻟﻮﺣﺔ اﻟﻤﻔﺎﺗﯿﺢ واﻷواﻣﺮ اﻟﺘﻲ ﺗﺴﺘﺨﺪﻣﮭﺎ‪ .‬ﻓﻲ وﻗﺖ ﻻﺣﻖ ﯾﻤﻜﻦ أن ﺗﻘﻮم ﺑﮫ ﻣﺮة أﺧﺮى‪ ،‬أو‬
‫ﺗﺸﻐﯿﻞ‪ ،‬اﻟﻤﺎﻛﺮو ﻟﺘﻜﺮار ﺗﻠﻘﺎﺋﯿﺎ اﻹﺟﺮاءات‪ .‬ورﺑﻤﺎ ھﺬا ھﻮ أﺳﮭﻞ طﺮﯾﻘﺔ ﻟﻠﻮﺻﻮل اﻟﻰ ﺑﺮﻣﺠﺔ ‪ VB‬واﻟﻜﻠﻲ‪ .‬ﺳﻮف‬
‫ﺗﻜﺘﺸﻒ ﻗﺮﯾﺒﺎ ﻛﯿﻒ ﺣﺪات اﻟﻤﺎﻛﺮو ﻣﻔﯿﺪة ﯾﻤﻜﻦ أن ﯾﻜﻮن وﯾﺮﯾﺪون ﺗﻌﺪﯾﻞ اﻟﺘﻌﻠﯿﻤﺎت اﻟﺒﺮﻣﺠﯿﺔ اﻟﻤﺴﺠﻞ وذﻟﻚ‬
‫ﻟﺘﺤﺴﯿﻦ أو ﻻﺳﺘﺨﺪاﻣﮭﺎ ﻓﻲ وﺿﻊ ﻣﺨﺘﻠﻒ ﻗﻠﯿﻼ‪.‬‬

‫إن ﻛﻨﺖ ﺗﻌﺮف اﻟﻤﺰﯾﺪ ﺣﻮل‪ ، Excel‬وأﻓﻀﻞ اﺳﺘﻌﺪادا ﺳﻮف ﺗﻜﻮن ﻟﻮﺣﺪات اﻟﻤﺎﻛﺮو و ‪VB.‬ﻣﻌﻈﻢ وﺣﺪات‬
‫اﻟﻤﺎﻛﺮو ﺗﺆدي ﺳﻠﺴﻠﺔ ﻣﻦ اﻹﺟﺮاءات ﻓﻲ ‪ Excel.‬ﻣﻌﻈﻢ ﺗﻌﻠﯿﻤﺎت اﻟﻜﻠﯿﺔ ﺗﻌﺎدل اﻷواﻣﺮ أو اﻹﺟﺮاءات ﻓﻲ‬
‫‪Excel.‬ﺗﻠﻚ اﻟﺘﻲ ﻟﯿﺴﺖ‪ ،‬ﻣﻊ ذﻟﻚ‪ ،‬ﻣﻦ ﺑﯿﻦ أﻛﺜﺮ ﻓﺎﺋﺪة! وﻣﻊ ذﻟﻚ اﻟﺒﯿﺎﻧﺎت واﻟﻮظﺎﺋﻒ اﻟﻤﺴﺘﺨﺪﻣﺔ ﻟﻜﺘﺎﺑﺔ اﻟﺘﻌﻠﯿﻤﺎت‬
‫ھﻲ أﺳﮭﻞ ﻟﻠﻔﮭﻢ إذا ﻛﻨﺖ ﺗﻌﺮف اﻟﻤﯿﺰات اﻟﺘﻲ ﯾﻤﺜﻠﻮﻧﮭﺎ ﻓﻲ‪Excel.‬‬

‫‪VB‬ﯾﻤﻜﻦ أن ﯾﺒﺪو اﻟﺴﺎﺣﻘﺔ وﺧﺎﺻﺔ إذا ﻛﺎن ﻟﺪﯾﻚ أي ﺧﺒﺮة ﻣﻊ ﻟﻐﺔ اﻟﺒﺮﻣﺠﺔ‪ .‬ﻟﻠﺘﻐﻠﺐ ﻋﻠﻰ ھﺬا ﯾﻤﻜﻨﻨﺎ اﺳﺘﺨﺪام‬
‫ﻣﺮﻓﻖ ﻣﺴﺠﻞ اﻟﻤﺎﻛﺮو ‪ Excel‬ﻟﻨﺮى ﻛﯿﻒ ﺗﺘﺮﺟﻢ إﻟﻰ إﺟﺮاءات إﻛﺴﻞ ‪ VB‬ﺗﻌﻠﯿﻤﺎت واﻟﻌﻜﺲ ﺑﺎﻟﻌﻜﺲ‪ .‬ﺗﻜﺘﯿﻚ‬
‫واﺣﺪ ﻟﻜﺘﺎﺑﺔ ﺟﺰء ﻣﻦ اﻟﻤﺎﻛﺮو اﻟﺨﺎص ﺑﻚ ﻋﻦ طﺮﯾﻖ ﻛﺘﺎﺑﺔ اﻟﺒﯿﺎﻧﺎت ﻣﺒﺎﺷﺮة ‪ VB‬ﻓﻲ اﻟﻤﺎﻛﺮو‪ ،‬ﺛﻢ ﺗﺴﺠﯿﻞ ﺟﺰء‬
‫ﻣﻨﮫ ﺑﺎﺳﺘﺨﺪام ﻣﺴﺠﻞ اﻟﻤﺎﻛﺮو( ﻏﺎﻟﺒﺎ ﻷﻧﻚ ﻻ ﺗﻌﺮف ﻛﯿﻒ ﺗﻜﺘﺐ ھﺬا اﻟﺠﺰء ﻓﻲ )!‪ VB‬ودﻣﺞ اﻷﺟﺰاء‪ .‬ﺗﺴﺠﯿﻞ‬
‫ﺟﺰء ﻣﻦ اﻟﻤﺎﻛﺮو ﻏﺎﻟﺒﺎ ﻣﺎ ﯾﻜﻮن أﺳﺮع وأﺳﮭﻞ ﻣﻦ ﻛﺘﺎﺑﺔ ﺧﺎرج اﻟﻘﻮاﺋﻢ ‪ VB.‬ﻓﻲ وﺣﺪة ﻧﻤﻄﯿﺔ ‪ VB‬ﯾﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ‬
‫اﻟﻜﻠﻤﺔ‪ ،‬وﻣﻊ ﻧﻘﻄﺔ اﻹدراج ﻓﻲ ﻣﻜﺎن ﻣﺎ ﻓﻲ اﻟﻜﻠﻤﺔ‪ ،‬اﺿﻐﻂ ‪ F1‬ﻟﻌﺮض اﻟﺘﻌﻠﯿﻤﺎت ﻋﻠﻰ ھﺬه اﻟﻜﻠﻤﺔ‪ .‬ﺑﺎﻟﻨﺴﺒﺔ ﻟﻜﺜﯿﺮ‬
‫ﻣﻦ اﻟﻜﻠﻤﺎت اﻟﺮﺋﯿﺴﯿﺔ ﯾﺘﻢ إﻋﻄﺎء ھﻨﺎك ﻣﺜﺎل ﻋﻠﻰ اﺳﺘﺨﺪاﻣﮫ واﻟﺬي ﯾﻤﻜﻨﻚ ﻧﺴﺦ وﻟﺼﻖ إﻟﻰ ﻣﺎﻛﺮو اﻟﺨﺎص ﺑﻚ‪.‬‬

‫‪2|Page‬‬
‫أﺳﻠﻮب اﻟﺒﺮﻣﺠﺔ‬

‫وﻣﻦ اﻟﻀﺮوري أن ﯾﻜﻮن ھﻨﺎك اﻟﻜﺜﯿﺮ ﻣﻦ اﻟﺘﻌﻠﯿﻘﺎت ﻓﻲ ﻣﺎﻛﺮو ﺷﺮح ﻣﺎ ﻣﺨﺘﻠﻒ أﻗﺴﺎم رﻣﺰ ﯾﻔﻌﻠﻮن‪ .‬ھﺬه‬
‫اﻟﺘﻌﻠﯿﻘﺎت ﯾﺴﺎﻋﺪ ﻛﺜﯿﺮا ﺗﺼﺤﯿﺢ اﻟﺘﻌﻠﯿﻤﺎت اﻟﺒﺮﻣﺠﯿﺔ‪ .‬ﻛﻨﺖ ﻻ ﺗﺮﯾﺪ أن ﯾﻜﻮن ﻟﻠﻌﻤﻞ اﻟﺨﺮوج ﻓﻲ ﻛﻞ ﻣﺮة ﻣﺎ ﺗﻘﻮم ﺑﮫ‪.‬‬
‫إذا ﻛﺎن ﺑﻌﺪ ﻓﺘﺮة طﻮﯾﻠﺔ ﺗﻌﻮد إﻟﻰ رﻣﺰ ﺑﺪون اﻟﺘﻌﻠﯿﻘﺎت اﻟﺘﻲ ﻣﻦ ﻏﯿﺮ اﻟﻤﺮﺟﺢ أن ﻧﺘﺬﻛﺮ ﻣﺎ ﯾﻔﻌﻠﮫ اﻟﻤﺎﻛﺮو ﻓﻲ‬
‫اﻟﺘﻔﺎﺻﯿﻞ‪ ،‬ﻋﻠﻰ ﻛﻞ ﺣﺎل‪ .‬اﻟﻔﺎﺻﻠﺔ اﻟﻌﻠﯿﺎ )'( ﺑﺘﻘﺪﯾﻢ ﺗﻌﻠﯿﻖ ﻓﻲ اﻟﺘﻌﻠﯿﻤﺎت اﻟﺒﺮﻣﺠﯿﺔ‪ .‬ﻻ ﯾﺘﻢ ﺗﻨﻔﯿﺬ ﺗﺼﺮﯾﺤﺎت ﻟﻠﯿﻤﯿﻦ‬
‫"ﻋﻠﻰ ﻧﻔﺲ اﻟﺨﻂ‪.‬‬

‫وﻣﻦ اﻟﻤﻔﯿﺪ ﺗﺒﻨﻲ أﺳﻠﻮب اﻟﺒﺮﻣﺠﺔ ﻟﺴﮭﻮﻟﺔ ﻗﺮاءة اﻟﺘﻌﻠﯿﻤﺎت اﻟﺒﺮﻣﺠﯿﺔ‪ .‬وﺳﻨﻌﻤﻞ ﻋﻠﻰ اﻻﺳﺘﻔﺎدة أﺳﻤﺎء وﺣﺪات‬
‫اﻟﻤﺎﻛﺮو واﻟﺪاﻻت اﻟﻤﻌﺮﻓﺔ ﻣﻦ ﻗﺒﻞ اﻟﻤﺴﺘﺨﺪم‪ .‬ﻻ ﯾﻤﻜﻦ أن ﺗﺘﻀﻤﻦ أﺳﻤﺎء ووظﺎﺋﻒ اﻟﻜﻠﻰ اﻟﻤﺴﺎﺣﺎت ﺣﺘﻰ إذا‬
‫ﯾﺘﻜﻮن اﺳﻢ أﻛﺜﺮ ﻣﻦ ﻛﻠﻤﺔ واﺣﺪة وﺑﻌﺒﺎرة أﺧﺮى ﻗﺪ رﺳﺎﺋﻠﮭﻢ اﻷوﻟﯿﺔ رﺳﻤﻠﺘﮭﺎ‪ ،‬ﻋﻠﻰ ﺳﺒﯿﻞ اﻟﻤﺜﺎل‪، TaxReturns‬‬
‫اﻟﺪورات اﻟﺪراﺳﯿﺔ‪.‬‬

‫وﯾﺒﺪو أن اﻟﺤﺠﺞ وأﺳﻤﺎء اﻟﻤﺘﻐﯿﺮات ﻣﻊ اﻷﺣﺮف اﻷوﻟﻰ ﻓﻲ ﺻﻐﯿﺮة ‪ -‬ﻟﺘﻤﯿﯿﺰھﺎ ﻋﻦ وﺣﺪات اﻟﻤﺎﻛﺮو‪ ،‬وظﺎﺋﻒ‪،‬‬
‫ﺧﺼﺎﺋﺺ وأﺳﺎﻟﯿﺐ وأﺳﻤﺎء اﻟﻜﺎﺋﻨﺎت‪.‬‬

‫وﯾﺒﺪو أن ﻛﻠﻤﺎت ﻣﻊ اﻟﺤﺮف اﻷول رﺳﻤﻠﺘﮭﺎ‪.‬‬

‫اﻟﻤﺪﻣﺞ ﻓﻲ اﻟﺜﻮاﺑﺖ ﺗﻈﮭﺮ ﻣﻊ ﺻﻐﯿﺮة "‪ "XL‬أو "رﻣﻮز‪".‬‬

‫وﺑﺎدﺋﺔ ﻛﺘﻞ اﻟﺘﺤﻜﻢ واﻟﺒﯿﺎﻧﺎت ﻓﻲ اﻹﺟﺮاءات اﻟﻔﺮﻋﯿﺔ وظﯿﻔﺔ ﺿﻤﻦ رﻣﺰ‪.‬‬

‫ﺣﺮف ﻣﺘﺎﺑﻌﺔ اﻟﺴﻄﺮ‪ ،‬ﺗﺴﻄﯿﺮ‪ ،(_) ،‬ﯾﺸﯿﺮ إﻟﻰ أن رﻣﺰ اﺳﺘﻤﺮ ﻣﻦ ﺳﻄﺮ واﺣﺪ إﻟﻰ اﻟﺘﺎﻟﻲ ھﻮ ﺟﺰء ﻣﻦ اﻟﺒﯿﺎن ﻧﻔﺴﮫ‬

‫‪.‬‬ ‫)‪Function Discount(quantity, price‬‬

‫‪‘ calculates discount‬‬

‫‪‘ discount is only given for orders of more than‬‬

‫‪‘ 100 widgets‬‬

‫‪If quantity >= 100 Then‬‬

‫_ * ‪Discount = quantity‬‬ ‫‪price * 0.1‬‬

‫‪Else‬‬

‫‪Discount = 0‬‬

‫‪End If‬‬

‫)‪Discount = Application.Round(Discount,2‬‬

‫‪End Function‬‬

‫‪3|Page‬‬
Visual basic statements 1.1

‫ھﻨﺎك‬Visual Basic ‫ﻓﻲ ﺑﺮﻧﺎﻣﺞ‬


‫ أﻧﮫ ﯾﺤﺘﻮي‬b‫ أي‬،‫أرﺑﻌﺔ أﺟﺰاء أﺳﺎﺳﯿﺔ‬
‫ﻋﻠﻰ‬
:‫اﻟﻌﺒﺎرات اﻟﺘﺎﻟﯿﺔ‬
‫إﻋﻼن اﻟﻤﺘﻐﯿﺮات واﻟﺜﻮاﺑﺖ‬1-
‫إدﺧﺎل‬-‫اﻟﻤﺘﻐﯿﺮات‬2-
‫ﻣﺸﻐﻠﻲ ﻟﻠﻤﺘﻐﯿﺮات‬3-
‫اﻟﻤﺘﻐﯿﺮات إﺧﺮاج‬4-

1- Declaration of a variable and constants


The declaration means defining the data type (variable or constant).

* Variables

A variable is a space in memory filled with data (value, character, time


or date).

Notes:

- Variable name must start with character (not number or function) and
maximum length 256 character, and does not contain point or symbol.

- Variable name must not repeat for other values.

The variable has to be declared. Variable type is defined by its content .The
content may be data as numeric or character or string or Boolean or date, or any
type of data (called variant), these types declared as:

Dim variable name as type

Or
Global variable name as type

4|Page
Note: The Dim declaration written in general part of the form or in any place
in form or sub procedure which used for one form. While Global declaration
used for all forms

The types of variables that are allowed in visual basic are stated in the table
below.

Types of variables

Type Value range Declaration


1-Integer -32768<x<32768 Dim x as integer
2-Long -2.1 e+009<x<2.1 e+009 Dim x as long
3-Single 1.4e-045 <|x|<3.4e+038 Dim x as single
4-Double 4.9e-324<x<1.79e+308 Dim x as double
5-String 65535 characters Dim x as string
6-Boolean True or false Dim x as Boolean
7-Date Computer time and date Dim x as date
Jan 100<x< 31 Dec 9999

* Constants

It is a space in memory filled with fixed value that will not be changed.
Constant may be declared as:

Const constant name = value

5|Page
Inputting variables
There are methods to input variable x as stated in the following:

Method of input For all type of variable


In text tool X=textno.text
In input box X=inputbox("prompt","title")

Note: To enter many variables we usually use the second method with loop.

3- Operators for variables


The operators that are used for variable are described in the following
table
+ addition
- subtraction
* multiplication
Arithmetic operators
/ division
mod Modulus –rest of division
^ exponent
= equal
< Less than
<= Less or equal
Relational operators
> Greater than
>= Greater or equal
<> Not equal

Note: The order of operations when executing arithmetic operation is:


Exponentiation - multiplication division and mod - finally addition and
subtraction.

The mathematical representation must be written as visual basic


representation in the code as following examples:

Mathematical representation Programming representation


3(x+4y) 3*(x+4*y)
X 2 42 X ^2  4 / 2
4
16  33  10  5  4  3 2  2 3 16^ (1/ 4)  3^3  10  (5 * 4) / 3^2  2^3
5y (5*y)/(x^2-4)+x-1
 x 1
x 42

6|Page
e2x Exp(2*x)/(cos(2*x)+sin(x))
cos(2x)  sin(x)

‫ ﻧﻌﻠﻦ س ك ﺛﺎﺑﺖ‬:(1) ‫ﻣﺜﺎل‬


‫ وﺿﻊ ﺗﺼﻤﯿﻢ ﻣﻨﺎﺳﺐ‬.‫ ﺛﻢ ﺣﺴﺎب ﻣﺴﺎﺣﺔ اﻟﺪاﺋﺮة‬،(P)

Sol:

Area

code stage:

Const p = 3.14159
Dim a, r As Single

Private Sub Command1_Click()


r = Val (Text1.Text)
a=r^2*p
Text1.Text = a
End sub

7|Page
.‫ ﻛﺗﺎﺑﺔ ﺑرﻧﺎﻣﺞ ﻟﺗﻧﻔﯾذ اﻟﻌﻣﻠﯾﺎت اﻷرﺑﻊ وﻓﻘﺎ ﻟﺗﺻﻣﯾم اﻟﺗﺎﻟﯾﺔ‬:(2) ‫ﻣﺛﺎل‬

Label1 Command1

Label2 Command2

Label3 Command3
Command4
Command6 Command5

Code stage:
Dim a,b, c as single
Private sub command1_click ()
a=val(text1.text)
b=val(text2.text)
c=a + b
End sub
Private sub command2_click ()
a=val(text1.text)
b=val(text2.text)
c=a - b
End sub
Private sub command3_click ()
a=val(text1.text)
b=val(text2.text)
c=a * b
End sub
Private sub command4_click ()
a=val(text1.text)
b=val(text2.text)
c=a / b
End sub
Private sub command5_click ()
Text3.text=cstr(c)
End sub
Private sub command6_click ()
Text1.text=" "
8|Page
Text2.text=" "
Text3.text=" " End sub

Check box:
Any number of check boxes can be used on a form. They work independently.
Its Property value could be changed in design stage manually, or in running stage by code.

‫ ﺗﻐﯿﯿﺮ‬:‫ ﺗﺼﻤﯿﻢ ﻧﻤﻮذج ﻣﻊ ﻣﺮﺑﻊ ﻧﺺ واﺣﺪ وﺛﻼﺛﺔ ﺧﺎﻧﺎت اﻻﺧﺘﯿﺎر ﺑﺤﯿﺚ ﻋﻨﺪﻣﺎ ﺗﻀﻐﻂ ﻋﻠﻰ ﻣﺮﺑﻌﺎت ﯾﺘﻢ اﻟﺘﺎﻟﯿﺔ‬:(3) ‫ﻣﺜﺎل‬
.Sol:‫ ﺗﺴﻄﯿﺮ‬،‫ ﻣﺎﺋﻞ‬،‫اﻟﻜﺘﺎﺑﺔ ﻟﻌﺮﯾﺾ‬
Text1
Text ‫ﻓﺎﺭﻍ‬
Text1
Check1
caption Bold
Check2 Check1
caption Italic Check2
Check3
caption underline Check3

Private Sub Check1_Click()


Text1.FontBold = Check1.Value End Sub
Private Sub Check2_Click()
Text1.FontItalic = Check2.Value End Sub
Private Sub Check3_Click()
Text1.FontUnderline = Check3.Value End Sub

Run stage:

9|Page
2.1Conditional statements

There are two types of conditional statements:

1- If statement
2- Select case

1- If statement: The comparison operations are used with conditional


statements.

The comparison operations are: (<, <=, >, >=, =, <>, and, or)

There are four structures for if statement. a)


Simple structure If.. then:

Used for running one programming statement only if the required


condition satisfied.

The general form is: If condition then statement

Example (4): write a program to enter a mark of a student then print (pass) if
he successful.

Sol:
Dim x as integer
Private sub command1_click()
X= val(text1.text)
If x>= 50 then text2.text= "pass"
End sub

10 | P a g e
b) If block structure: Used for running many programming statements if the
required condition satisfied.

The general form is:

If condition then
Statements
End if

‫ ﺗﺼﻤﯿﻢ ﻧﻤﻮذج ﻣﻊ ﻣﺮﺑﻊ ﻧﺺ واﺣﺪ وﺛﻼﺛﺔ ﺧﺎﻧﺎت اﻻﺧﺘﯿﺎر ﺑﺤﯿﺚ ﻋﻨﺪﻣﺎ ﺗﻀﻐﻂ ﻋﻠﻰ ﻣﺮﺑﻌﺎت ﯾﺘﻢ‬:(3) ‫ﻣﺜﺎل‬
.‫ ﺗﺴﻄﯿﺮ‬،‫ ﻣﺎﺋﻞ‬،‫ ﺗﻐﯿﯿﺮ اﻟﻜﺘﺎﺑﺔ ﻟﻌﺮﯾﺾ‬:‫اﻟﺘﺎﻟﯿﺔ‬

Sol:
Dim x as integer
Private sub command1_click()
X= val(text1.text)
If x>= 50 then
text2.text= "pass"
text2.fontsize=18
end if
End sub

11 | P a g e
If.. Then.. Else structure: Used for running many programming statements if the
required condition satisfied. And running another programming statements (after
else) if the required condition not satisfied.

The general form is:

If condition then
Statements Else
Statements End if

‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻹدﺧﺎل ﻋﻼﻣﺔ اﻟﻄﺎﻟﺐ ﺛﻢ طﺒﺎﻋﺘﮭﺎ )ﺗﻤﺮﯾﺮ( إذا ﻛﺎن ﻧﺎﺟﺤﺎ واﻟﻄﺒﺎﻋﺔ )ﺗﻔﺸﻞ( ﺧﻼف‬:(6) ‫ﻣﺜﺎل‬
.‫ذﻟﻚ‬

Sol:
Dim x As Integer
Private Sub command1_click()
x = val(Text1.Text)
If x >= 50 Then
Text2.Text = "pass"
Else
Text2.Text = "fail"
End If
End Sub

d) If.. Then.. Elseif.. Else structure:

Used if we have many conditions to be satisfied

12 | P a g e
،(‫ أول واﺣﺪ ل)ﻣﻨﻰ‬.‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻹدﺧﺎل اﺳﻢ اﻟﻤﺴﺘﺨﺪم وﻋﺮض اﻟﺮﺳﺎﻟﺔ )ﻣﺮﺣﺒﺎ( ﺛﻼث ﻣﺮات‬:(7) ‫ﻣﺜﺎل‬
.‫واﻟﺜﺎﻧﯿﺔ ﻋﻦ )ﻣﮭﺎ( واﻟﺜﺎﻟﺜﺔ ﻷي ﻣﺴﺘﺨﺪم ﻛﻀﯿﻒ‬

Sol:
Dim x As String
Private Sub command1_click() Hello Muna
x = Text1.Text
If x = "Muna" Then
Label1.caption= "hello, Muna"
ElseIf x = "Maha" Then
Label1.caption= "hello,Maha"
Else
Label1.caption= "hello, guest"
End If
End Sub

‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﺘﺼﻨﯿﻒ أي ﻋﺪد دﺧﻠﺖ وﻓﻘﺎ ﻟﻌﻼﻣﺔ وﻋﺮض ﻋﺒﺎرة )رﻗﻢ ﺳﺎﻟﺐ( ﻋﻨﺪﻣﺎ ﻛﺎن اﻟﺮﻗﻢ‬:(8) ‫ﻣﺜﺎل‬
.(‫ وإﻻ ﻋﺮض ﻋﺒﺎرة )ﻻ اﯾﺠﺎﺑﯿﺔ وﻻ ﺳﻠﺒﯿﺔ‬،‫ﺳﺎﻟﺒﺎ وﻋﺒﺎرة )رﻗﻢ ﻣﻮﺟﺐ( ﻋﻨﺪﻣﺎ ﯾﻜﻮن ﻋﺪد إﯾﺠﺎﺑﯿﺔ‬

Sol:
Dim x As Single
Private Sub command1_click ()
x = Val(Text1.Text)
If x > 0 Then
Label1.caption= "positive
number" ElseIf x < 0 Then
Label1. caption = "negative
number" Else
Label1. caption = "neither positive nor
negative"
End If
End Sub

13 | P a g e
‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻹدﺧﺎل رﻗﻤﯿﻦ وﺣﺴﺎب ﻋﻤﻠﯿﺎت اﻟﻀﺮب واﻟﻘﺴﻤﺔ‬:(9) ‫ﻣﺜﺎل‬
‫ﺑﺎﺳﺘﺨﺪام زر اﻟﺨﯿﺎر ﻣﻊ اﻟﻌﺮض ﻋﺒﺎرة )ﻋﻤﻠﯿﺔ ﺗﻘﺴﯿﻢ ﻏﯿﺮ ﻗﺎﻧﻮﻧﯿﺔ( ﻋﻨﺪﻣﺎ‬
.‫اﻟﻘﺎﺳﻢ ھﻮ ﺻﻔﺮ‬
Sol:
Dim a, b, c As Single
Private Sub command1_click()
a = Val(Text1.Text)
b = Val(Text2.Text)
If Option1.Value Then
c=a*b
Text3.Text =c elseIf b <>
0 Then
c=a/b
Text3.Text =c)
Else
Text3.Text = "illegal division operation"
End If
End If
End Sub

-Select statement
Used for applying many statements depending on one variable. The general
form is:

Select case variable Case


value1 statements
Case value2
Statements
.
.
.
Case value n
Statements
Case else
Statements
End select

14 | P a g e
‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﻄﺒﺎﻋﺔ أﯾﺎم اﻷﺳﺒﻮع ﻋﻨﺪﻣﺎ ﻧﺪﺧﻞ رﻗﻤﮫ‬:(10) ‫ﻣﺜﺎل‬
Sol:
Dim x As Integer
Private Sub Command1_Click()
x = val(Text1.Text)
Select Case x
Case 1
Label1. caption ="Sunday"
Case 2
Label1. caption = "Monday"
Case 3
Label1. caption = "Tuesday"
Case 4
Label1. caption = "Thursday"
Case 5
Label1. caption = "Wednesday
Case 6
Label1. caption =
"Friday"
Case 7
Label1. caption =
"Saturday"
End Select
End Sub

15 | P a g e
:‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻹﻋﻄﺎء ﺗﻘﯿﯿﻢ ﻟﻌﻼﻣﺎت ﻣﺨﺘﻠﻔﺔ ﻋﻠﻰ اﻟﻨﺤﻮ اﻟﺘﺎﻟﻲ‬:(11) ‫ﻣﺜﺎل‬

mark evaluation
90-100 Excellent
80-89 Very good
70-79 Good
60-69 Medium
50-59 Pass
0-49 Fail

Dim x As Integer
Private Sub Command1_Click()
x=
val(Text1.Tex
t)
Select Case x
Case 90 To 100
Label1. caption
= "excellent"
Case 80 To 89
Label1. caption
= "very good"
Case 70 To 79
Label1.
caption =
"good"
Case 60
To 69
Label1.
caption =
"medium"
Case 50 To 59
Label1.
caption =
"pass"
Case 0 To
49
Label1. caption = "fail"
Case Else
Label1. caption = "the range is 0-100"
16 | P a g e
End Select
End Sub

3.Loop statement:
Visual basic supports statement to perform loops. The loops statements could
have different structures as follows:
1- Counter loop.
2- Conditional loop.

1- Counter loop:
Loops apply programming statements for fixed number of times using counter
(for… next) statement.

The general form is:


For variable = start value to end value step step value
Stateme
nts
Next variable

.‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﻄﺒﺎﻋﺔ )ﻣﺮﺣﺒﺎ( ﺧﻤﺲ ﻣﺮات‬:9 ‫ﻣﺜﺎل‬

Sol:
Dim i as integer
Private Sub Command1_Click ()
For i = 1 To 5
Print "hello"
Next i
End Sub

.10-1 ‫ اﻛﺘﺐ ﺑﺮﻧﺎﻣﺠﺎ ﻟﻄﺒﺎﻋﺔ أرﻗﺎم ﺣﺘﻰ‬:10 ‫ﻣﺜﺎل‬

Sol:
Dim i as integer
Private Sub Command1_Click ()
For i = 2 To 10 step 2
Print i
Next i
End Sub

Notes:
1-The variable's value that we use as counter must be integer value (integer, long).
2- If we don’t determined the step value then the assumed value is 1.
3- If the final value smallest than the initial value, then the step value must
be negative.

17 | P a g e
4.Nested loop:

The nested loops are the loops that are placed inside each other. The most
inner
loop will be executed first, then the outer ones. These loops should neither
intersect, nor have the same index. As follows:

For i = 1 To n
For j = 1 To m
Statements
Next j
Next i

‫ ﺛم ﺟﻌل ﺗﻐﯾﯾر اﻟﻠون وﺣﺟم‬.‫ وأول واﺣد ﻣﻊ ﺣﺟم اﻟﻌﺎدﯾﺔ واﻟﻠون‬،‫ ﻛﺗﺎﺑﺔ ﺑرﻧﺎﻣﺞ ﻟطﺑﺎﻋﺔ )ﺗرﺣﯾب( ﻋﺷر ﻣرات‬:(12) ‫ﻣﺛﺎل‬
.‫أﻛﺑر ﻓﻲ ﻛل ﻣرة‬

Sol:
Dim i As Integer
Private Sub
Command1_Click()
Print "welcome"
For i = 1 To 9
FontSize = 10 + i
ForeColor =
QBColor(i)
Print "welcome"
Next i
End Sub

18 | P a g e
.1‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﺘﻮﻟﯿﺪ اﻷرﻗﺎم ﻓﻲ اﻟﻨﻤﻮذج اﻟﺘﺎﻟﻲ‬:(13) ‫ﻣﺜﺎل‬
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Sol:
Dim I, j As Integer
Private Sub
command1_click() For I =
1 To 5
For j = 1 To i
Print
j;
Nexj
Print
NexI
End
Sub

.‫ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﻄﺒﺎﻋﺔ ﺟﺪول اﻟﻀﺮب‬: (12)‫ﻣﺘﺎل‬


Sol:

Dim I, j As Integer
Private Sub
command1_click() For I =
1 To 10
For j = 1 To
10 p = I * j
Print I; "*"; j;
"="; p, Next j
Print
Next
I
End
Sub

19 | P a g e
Series:
To compute the value of series, we use suitable loop statements according to
the
boundaries (limits) of each series.

:‫ ھﻮ ﻋﺪد ﺻﺤﯿﺢ‬x ‫ ﺣﯿﺚ‬، + X2 + X3 + ... + XN‫ س‬+ 1 = ‫ اﻟﺒﺤﺚ ﺟﻤﻊ‬:(15) ‫ﻣﺜﺎل‬

Dim I, n, x, sum as integer


Private Sub command1_click ()
sum = 1
n=cint(text1.t
ext)
x=val(text2.text)
For i = 1 To
n Sum =
sum +x^i
Next i
Text3.text=cstr(s
um) End Sub

20 | P a g e
Input - output boxes
There are two types of dialog boxes which are inputbox and messagebox. The first is
used to input variable and the second to output variable or message. Both needs code
and appear at run time.

a) Inputbox
Inputbox used to input value or characters for one variable from keyboard at running
stage.
This box needs a code in code sheet and could be written in any event or command
X=inputbox(" prompt or remark", "title")

inputboxSol:‫ ﺑﺎﺳﺘﺨﺪام‬x ‫ إدﺧﺎل ﻗﯿﻤﺔ‬:(16) ‫ﻣﺜﺎل‬

Private Sub Form_Load()


X=Inputbox("enter value of x", "calculation")
End Sub

21 | P a g e
Message box
It is used to output a message to the user (at running stage) the code needed could be
written in code sheet and in any event or command.

The available icons for message box


structure value icon
vbcritical 16

vbquestion 32

vbexclamation 48

vbinformation 64

The available commands for message box


structure value Commands
Vbokonly 0 Ok
Vbokcancel 1 Ok, Cancel
vbAbortRetryIgnor 2 Abort, Retry, Ignore
vbYesNoCancel 3 Yes, No, Cancel
vbYesNo 4 Yes, No
vbRetryCancel 5 Retry, Cancel

For example if we write the following statement then a message box will be appear as
shown below

MsgBox "please close your program", 16, "Error"

or
MsgBox "please close your program", vbcritical, "Error"

Example: show what appear after running the following statement


MsgBox "are you sure you want to delete this file", 32 + 4, "delete"

or
MsgBox "are you sure you want to delete this file",vbQuestion+vbYesNo,"delete"
Sol:
Example (16): write a program to move the text (excellent) from textbox to message box
and change the color of the text after click on command button (display).
Sol:

22 | P a g e
Text1: text="excellent" Command1:
caption="‫"ضﺮﻋ‬

Private Sub Command1_Click()


MsgBox (Text1.Text) Text1.BackColor
= QBColor(9) Text1.Text = " "
End Sub

Or we can write the following code: Private

Sub Command1_Click()
X= Text1.Text
MsgBox (X)
Text1.BackColor = QBColor(9)
Text1.Text = " "
End Sub

23 | P a g e
Menu

‫ وﯾﻤﻜﻦ‬.‫ وﻟﻜﻦ ﯾﻤﻜﻦ ﻟﻠﻤﺴﺘﺨﺪم إﺿﺎﻓﺘﮫ‬،‫ ﺷﻜﻞ ھﻮ ﻣﻌﯿﺎرﻋﺮض دون اﻟﻘﺎﺋﻤﺔ‬.‫اﻟﻘﺎﺋﻤﺔ ھﻮ ﺷﺮﯾﻂ ﻓﻲ أﻋﻠﻰ اﻟﻨﻤﻮذج‬
‫ ﻓﻲ اﻟﻤﻘﻄﻊ اﻟﺘﺎﻟﻲ ﻣﺤﺮر اﻟﻘﺎﺋﻤﺔ وﺳﻮف ﺗﻨﺎﻗﺶ رﻣﺰ‬.‫إدراج ھﺬه اﻟﻘﺎﺋﻤﺔ ﻓﻲ اﻟﻨﻤﻮذج ﺑﺎﺳﺘﺨﺪام ﻣﺤﺮر اﻟﻘﺎﺋﻤﺔ‬
.‫اﻟﻤﻄﻠﻮﺑﺔ‬
Menu Editor
To use menu there are three ways:
1- Press menu icon from toolbar .
2- press (ctrl+E) from key board.
3- click on: tools>Menu Editor.
Menu editor box appears as shown below.

Move item down Select


short cut
Move item up
Add …
Remove …

Move to next item in the list Delet item

The steps of applying menu editor box are as follows:


To add item Use menu editor as follows

24 | P a g e
To add many items Use the menu Editor

25 | P a g e
Create sub Menu list Use menu Editor

Create Shortcut Use & with caption and select shortcut

Code for menu items


Each item in menu or sub menu is considered as a command which
takes the event click only. The user can add code for each item:
click on item>code for that item appears on code sheet. Also code can be
added to form: click on item >code for that item appears on code sheet.
This is described in the following figure:

Click on item

‫ اﺣﺗوت اﻟﻘﺎﺋﻣﺔ ﻋﻠﻰ اﻟﻠون ﻋﻧﺻر واﺣد ﻣﻊ ﻋﻧﺎﺻر اﻟﻘﺎﺋﻣﺔ‬.‫ ﺗﺻﻣﯾم ﻧﻣوذج ﻣﻊ اﻟﻘﺎﺋﻣﺔ واﻟﺗﺳﻣﯾﺔ ﻣﻊ ﻋﻧوان ﻣﺣدد‬:(17) ‫ﻣﺛﺎل‬
.‫ ﻟﺗﻠوﯾن اﻟﺗﺳﻣﯾﺔ ﻓﻲ اﻷﺣﻣر واﻷﺧﺿر واﻷزرق ﺛم اﻟﺧروج ﻣن اﻟﺑرﻧﺎﻣﺞ‬،‫ اﻷﺣﻣر واﻷﺧﺿر واﻷزرق واﻟﺧروج‬:‫اﻟﻔرﻋﯾﺔ‬
(‫ ﻣﻊ أي ﺷرح ﻋﻠﻰ ﺳﺑﯾل اﻟﻣﺛﺎل )ﻣرﺣﺑﺎ‬Label1 ‫ وﺿﻊ‬:‫ﺳول‬

Caption: color Create standard menu (color) from menu


Name: command1 editor>next
Caption: red Add sub menu items by pressing then enter
Name:command2 the caption and name>next.

26 | P a g e
Caption: green Do the same thinks for other items>ok
Name:command3
Caption: blue
Name:command4
Caption: exit
Name:command5
Shortcut: ctrl+E

To programming these commands click on each one to open its code


window and write the following code:

Private sub command2_click ()


Label1.backcolor=vbred
End Sub

Private sub command3_click ()


Label1.backcolor=vbgreen
End Sub

Private sub command4_click ()


Label1.backcolor=vbblue
End Sub

Private sub command5_click ()


End
End Sub

27 | P a g e
Assignment statement
There are many statements ways to fill a variable as follows:
Variable = expression

Expression may include variables, operations and functions as follows:


1- Numerical variable. For example: i=3
2- Mathematical relation. For example: x=a/b
3- Characters variable (string). For example: t="abc"
4- Boolean variable (logical). For example: p=true

Functions for variables


The numeric and string variables are the most common used variables
in programming, therefore V.B provides the user with many functions to be
used with a variable to perform certain operations or type convention. The
most common functions for numerical variable x

Function Description
Abs(x) Absolute of x
Sqr(x) Square root of x
Int(x) Integer of x
Exp(x) Exponential of x (ex)
Fix(x) Take the integer part
Sin(x), cos(x), tan(x) Trigonometric functions
Log(x) Natural logarithms
Len(x) Number of character of variable x
Lcase(x) Change the text x to small letters
Ucase(x) Change the text x to capital letters
Cint(x) Convert x to integer
Clong(x) Convert x to long integer
Cdbl(x) Convert x to double precision
Cstr(x) Convert variable x to string
Val(x) Convert string x to numerical variable
Note: the last five functions are called conversion functions.

The following functions for different x are given for comparison.


Function output
X=lcase("MY NAME IS") my name is
X=ucase("my name is") MY NAME IS
int(2.5) 2
Int(-2.5) -3
Fix(2.5) 2
Fix(-2.5) -2
28 | P a g e
Outputting variables
There are methods to output variable x as stated in the following:

Method of output For all type of variable


On form Print x
Note: in load event we must use the statement:
(form1.show)
to text tool textno.text =X
to label tool Labelno.caption=x
By message box msgbox (x)
Or msgbox ("remark"& x)

The instruction print could be very helpful to display data and used as
follows:

Code Description example


print To leave one line and
print on next
Print "a", "b", "c" Use (,) to print a distance a b c
between outputs
Print "a"; "b"; "c" Use (;) to print the abc
outputs adjacent
Print "a","b"; Print a, b then print c on abc
Print "c" the same line

.‫ وﺿﻊ ﺗﺻﻣﯾم ﻣﻧﺎﺳب‬.‫ﻛﺗﺎﺑﺔ ﺑرﻧﺎﻣﺞ ﻹدﺧﺎل أي ﻧص وﺣﺳﺎب طوﻟﮫ‬: (18)‫ﻣﺗﺎل‬


Sol:

Design stage:

Form1
Caption String length
Command1
caption Click here
Label1
Caption Length=
Text1
Text

29 | P a g e
Code stage:
Dim s As String
Private Sub Command1_Click()
s = InputBox("inter string")
L = Len(s)
Text1.Text = CStr(L)
End Sub

Running stage:

‫ اﺳﺘﺨﺪم ﻣﺮﺑﻊ رﺳﺎﻟﺔ‬.‫ ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﺠﻤﻊ وطﺮح رﻗﻤﯿﻦ ﺻﺤﯿﺢ ﺑﻌﺪ وﺿﻊ ﺗﺼﻤﯿﻢ ﻣﻨﺎﺳﺐ‬:19 ‫ﻣﺜﺎل‬
.‫ﻹﺧﺮاج‬

Design stage:

form
caption calculator
Command1
caption +
Command2
Caption -
Label1
Caption Enter no.1
Label2
Caption Enter no.2
text ‫ ﻤﻥ ﺨﺎﺼﻴﺔ‬text1, text2 ‫ﻭﻨﻔﺭﻍ‬

30 | P a g e
Code stage:
Dim x, y, z as integer
Private sub command1_click ()
X=val(text1.text)
Y=val(text2.text)
Z=x + y
Msgbox("addition result="&z)
End sub
Private sub command2_click ()
X=val(text1.text)
Y=val(text2.text)
Z=x - y
Msgbox("subtraction result="&z)
End sub
Running stage
Enter two values in text1 and text2. When click on command (+) or (-) the
addition or subtraction result appears in message box.

.‫ﻛﺗﺎﺑﺔ ﺑرﻧﺎﻣﺞ ﻟﺗﻧﻔﯾذ اﻟﻌﻣﻠﯾﺎت اﻷرﺑﻊ وﻓﻘﺎ ﻟﺗﺻﻣﯾم اﻟﺗﺎﻟﯾﺔ‬: (20)‫ﻣﻧﺎل‬

Label1 Command1

Label2 Command2

Label3 Command3
Command4
Command6 Command5

Code stage:
Dim a,b, c as single
Private sub command1_click ()
a=val(text1.text)
b=val(text2.text)
c=a + b
End sub

31 | P a g e
Private sub command2_click ()
a=val(text1.text)
b=val(text2.text)
c=a - b
End sub
Private sub command3_click ()
a=val(text1.text)
b=val(text2.text)
c=a * b
End sub
Private sub command4_click ()
a=val(text1.text)
b=val(text2.text)
c=a / b
End sub
Private sub command5_click ()
Text3.text=cstr(c)
End sub
Private sub command6_click ()
Text1.text=" "
Text2.text=" "
Text3.text=" "
End sub

‫ اﻟﻘﯿﻤﺔ‬،‫ ﻣﺮﺑﻊ‬،‫ ﻗﯿﻤﺔ ﻋﺪدﯾﺔ‬،‫ اﻟﺠﯿﺐ وﺟﯿﺐ اﻟﺘﻤﺎم‬:‫ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﺤﺴﺎب وظﺎﺋﻒ ھﻲ‬: (21)‫ﻣﺘﺎل‬
.:‫اﻟﻤﻄﻠﻘﺔ‬

Design stage:
Dim x, y As Single
Private Sub command1_click()
x = Val(Text1.Text)
y = Abs(x)
Text1.Text = CStr(y)
End Sub
Private Sub Command2_Click()
x = Val(Text1.Text)
y = Sqr(x)
Text1.Text = CStr(y)
End Sub

32 | P a g e
Private Sub Command3_Click()
x = Val(Text1.Text)
y = Int(x)
Text1.Text = CStr(y) End Sub
Private Sub Command4_Click()
x = Val(Text1.Text)
y = Sin(x * 3.14159 / 180) Text1.Text =
CStr(y)
End Sub
Private Sub Command5_Click()
x = Val(Text1.Text)
y = Cos(x * 3.14159 / 180) Text1.Text =
CStr(y)
End Sub

Running stage

33 | P a g e
‫ﺗﻤﺎرﯾﻦ‬
‫‪Q1 /‬ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﺤﺴﺎب ﻣﺴﺎﺣﺔ اﻟﻤﺜﻠﺚ ﻣﻊ اﻟﺘﺼﻤﯿﻢ‪.‬‬

‫‪Q2 /‬ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻹدﺧﺎل اﺳﻢ اﻟﻄﺎﻟﺐ وﻋﻼﻣﺘﻲ ﻓﻲ أي ﻣﻮﺿﻮع ﻣﻦ ﻗﺒﻞ ﻣﺮﺑﻊ اﻹدﺧﺎل ﺛﻢ ﯾﺤﺴﺐ اﻟﻤﺘﻮﺳﻂ‪ ،‬وﻋﺮض اﺳﻢ واﻟﻤﺘﻮﺳﻂ ﻓﻲ اﺛﻨﯿﻦ ﻣﻦ‬
‫اﻟﺘﺴﻤﯿﺎت‪.‬‬

‫‪Q3 /‬اﻛﺘﺐ ﺑﺮﻧﺎﻣﺠﺎ ﻹدﺧﺎل رﻗﻢ ﺣﻘﯿﻘﻲ ﺛﻢ ﺗﺠﺪ ﻣﺮﺑﻊ ﻟﮭﺎ ﺑﻌﺪ وﺿﻊ ﺗﺼﻤﯿﻢ ﻣﻨﺎﺳﺐ‪.‬‬

‫‪Q4 /‬ﺗﺼﻤﯿﻢ ﻣﺸﺮوع ﻣﻊ ﺛﻼﺛﺔ أﺷﻜﺎل‪ ،‬ﻣﺜﻞ أن ‪ form1‬ﯾﺤﺘﻮي ﻋﻠﻰ زري اﻷﻣﺮ "اﻟﻤﻌﺎدﻟﺔ "‪Pethagors‬و "ﻣﻨﻄﻘﺔ اﻟﻤﺜﻠﺚ" ھﺬه اﻟﺘﻲ‬
‫ﻋﻨﺪﻣﺎ اﻧﻘﺮ ﻓﻮق " ‪Command1‬ﻓﯿﺜﺎﻏﻮرس اﻟﻤﻌﺎدﻟﺔ"‪ form2 ،‬ﺳﻮف ﺗﻈﮭﺮ ﺣﺘﻰ ﻓﻲ ھﺬا اﻟﺸﻜﻞ اﻟﻀﻠﻊ اﻟﺜﺎﻟﺚ ﻣﻦ اﻟﻤﺜﻠﺚ ﺳﯿﻜﻮن ﺣﺴﺎب ﻣﻊ‬
‫ﻓﯿﺜﺎﻏﻮرس اﻟﻤﻌﺎدﻟﺔ ﺑﻌﺪ دﺧﻮل اﻟﺠﺎﻧﺐ اﻷول واﻟﺜﺎﻧﻲ‪ ،‬وﻋﻨﺪﻣﺎ ﺗﻀﻐﻂ ﻋﻠﻰ "ﻣﻨﻄﻘﺔ اﻟﻤﺜﻠﺚ" ﺷﻜﻞ ﺛﺎﻟﺚ ﻋﺮض ذﻟﻚ أن اﻟﻤﻨﻄﻘﺔ ﺳﻮف ﯾﻜﻮن ﺣﺴﺎب‬
‫ﺑﻌﺪ دﺧﻮل اﻟﻘﺎﻋﺪة واﻻرﺗﻔﺎع‪ .‬اﺳﺘﺨﺪام اﻟﻤﺨﺮﺟﺎت واﻟﻤﺪﺧﻼت اﻟﻄﺮق اﻟﻤﻨﺎﺳﺒﺔ‪.‬‬

‫‪Q5 /‬ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﻌﺮض اﻟﺮﺳﺎﻟﺔ أدﻧﺎه ﺑﻌﺪ اﻟﻨﻘﺮ ﻋﻠﻰ زر اﻷﻣﺮ "ﺗﺸﻐﯿﻞ"‪.‬‬

‫‪Q6 /‬ﻛﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻟﻌﺮض اﻟﻮﻗﺖ واﻟﺘﺎرﯾﺦ‪ ،‬ووﺿﻊ ﺗﺼﻤﯿﻢ ﻣﻨﺎﺳﺐ‪.‬‬

‫‪34 | P a g e‬‬
References

- Balena, Francesco. Programming Microsoft Visual Basic. NET Version 2003. Antonio Faustino, 2004.

- Kurniadi, Adi. "Pemrograman Microsoft Visual Basic 6." Elex Media Komputindo, Jakarta (2000).

- Petroutsos, Evangelos. Mastering Database Programming with Visual Basic 6. SYBEX Inc., 1999.

- "Microsoft Basic Logical Expression Evaluation". Vb.mvps.org. Retrieved 2009.

- Root, Randal; Romero Sweeney, Mary (2006).

35 | P a g e

You might also like