اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

فائدة المتغيرات


الردود الموصى بها

السلام عليكم

قرأت موضوع المتغيرات الموجود علي الموقع لكن يبقي السؤال الذي لم يجبني عليه احد

ما الفرق بين الكود الذي يستخدم المتغير و الذي لايستخدمه

وكيف اعلم اذا كان الكود يحتاج متغير ام لا

رابط هذا التعليق
شارك

وعليكم السلام 🙂

 

اذا كانت العملية الحسابية بين حقول في النموذج ، فلا داعي لإستعمال المتغير ، مثلا :

if me.txt1 > me.txt2 then
  
  me.txt1= me.txt2 * 50
endif
  
  
  او
me.txt1= me.txt1 + (me.txt2 * 50 / 5)
  
او تاريخ بكرة
me.Tomorrow= date() + 1

.

بينما اذا اردت ان تحتفظ بقيمة معينه مؤقتا في الكود ، ثم تحتاج للقيمة مرة اخرى ، فالحفظ يكون في متغير ، مثلا :

هذا مسار الصورة
  Application.currentproject.path & "\images\" & me.Project_Name & "\" & me.item_Number & ".jpg"
  
  
  فبدل ان استخدم هذا السطر الطويل ، وكل مرة يضطر الاكسس لقراءة قيم الحقول من النموذج
  
  if dir(Application.currentproject.path & "\images\" & me.Project_Name & "\" & me.item_Number & ".jpg")="" then
     me.img.picture = Application.currentproject.path & "\images\" & me.Project_Name & "\" & me.item_Number & ".jpg"
  else
     msgbox "لم يتم الحصول على الصورة في المسار التالي" & vbcrlf & _
         Application.currentproject.path & "\images\" & me.Project_Name & "\" & me.item_Number & ".jpg"   
     me.img.picture=""
     me.img2.picture = Application.currentproject.path & "\images\" & me.Project_Name & "\" & me.item_Number & ".jpg"
  end if
         
         
 نستطيع اعطاء المسار الى متغير ، ثم نستعمل المتغير
 وبما ان المسار عبارة عن نص
         
   dim myFile as string
   
   myFile = Application.currentproject.path & "\images\" & me.Project_Name & "\" & me.item_Number & ".jpg"      
         
   if dir(myFile)="" then
     me.img.picture = myFile
  else
     msgbox "لم يتم الحصول على الصورة في المسار التالي" & vbcrlf & myFile   
     me.img.picture=""
     me.img2.picture = myFile
  end if        

 

جعفر

  • Like 3
رابط هذا التعليق
شارك

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information