نقل قول: تعریف متغیر سراسری
نقل قول:
نوشته شده توسط
shahabbasic
چجوری میتونم مثلا متغیر b1 رو سراسری تعریف کنم طوری که فقط در یک رخداد قابل استفاده نباشه بلکه در تمام برنامه بشه ازش استفاده کرد؟
داخل یک ماژول تعریفش کن.
نقل قول: تعریف متغیر سراسری
اگه بخوای توی کل برنامه(همه فرم ها) قابل استفاده باشه توی ماژول تعریفش کن. ولی اگه بخوای توی کل رویداد های فرم جاری استفاده کنی تو قسمت General(بالاتر از همه کدها) تعریفش کن.
نقل قول: تعریف متغیر سراسری
ببین عزیز
ما برای تعیین محدوده اثر یک متغیر سه جور میتونیم اونو تعریف کنیم:
1- که از همه معمول تره با استفاده از Dim
این دستور از همه محدودتره مثلا اگه ما داخل یک تابع (فانکشن) یا زیر روال(سابروتین) اونو بکار ببریم، فقط تو همین زیر روال یا تابع کاربرد داره
و اگه در بالای یک فرم یا کلاس یا یوزرکنترل یا مدول یا ... بکار ببریم، در تمام اون فرم یا کلاس یا ... قابل دسترسیه (فقط در همون فرم یا ...)
2- دستور public:
این دستور معمولا برای تعریف متغیر در یک فرم بکار میره و باعث میشه فرمها و مدول های دیگه هم به اون دسترسی داشته باشن
مثلا فرض کن شما در فرم 1 مینویسی Public x as Integer بعد در فرم دو میتونی بنویسی Form1.x=10
3- دستور Global که عمومی ترین نوع تعریف متغیره
شما این دستور رو باید در یک مدول بنویسی و اونوقت این متغیر در تمام برنامه قابل دسترسیه!
نقل قول: تعریف متغیر سراسری
نقل قول:
نوشته شده توسط
asedjavad
3- دستور Global که عمومی ترین نوع تعریف متغیره
شما این دستور رو باید در یک مدول بنویسی و اونوقت این متغیر در تمام برنامه قابل دسترسیه!
البته این که شما فرمودین دستور نیست ،مکان هست.:لبخندساده:
نقل قول: تعریف متغیر سراسری
نقل قول:
نوشته شده توسط
ASedJavad
ببین عزیز
ما برای تعیین محدوده اثر یک متغیر سه جور میتونیم اونو تعریف کنیم:
1- که از همه معمول تره با استفاده از Dim
این دستور از همه محدودتره مثلا اگه ما داخل یک تابع (فانکشن) یا زیر روال(سابروتین) اونو بکار ببریم، فقط تو همین زیر روال یا تابع کاربرد داره
و اگه در بالای یک فرم یا کلاس یا یوزرکنترل یا مدول یا ... بکار ببریم، در تمام اون فرم یا کلاس یا ... قابل دسترسیه (فقط در همون فرم یا ...)
2- دستور public:
این دستور معمولا برای تعریف متغیر در یک فرم بکار میره و باعث میشه فرمها و مدول های دیگه هم به اون دسترسی داشته باشن
مثلا فرض کن شما در فرم 1 مینویسی Public x as Integer بعد در فرم دو میتونی بنویسی Form1.x=10
3- دستور Global که عمومی ترین نوع تعریف متغیره
شما این دستور رو باید در یک مدول بنویسی و اونوقت این متغیر در تمام برنامه قابل دسترسیه!
Pulic زو من ه زجا تعریف میکنم خطا میگیره
واسه من اینجوریه؟ یا کلا اینجوریه؟
نقل قول: تعریف متغیر سراسری
نقل قول:
نوشته شده توسط
javady_joon
Pulic زو من ه زجا تعریف میکنم خطا میگیره
واسه من اینجوریه؟ یا کلا اینجوریه؟
باسلام
جدول ضرب اشتباه نیست بلکه ما در محاسبه اشتباه میکنیم. پس Public هم مشکلی نداره قطعا اشتباهی میکنید که خطا میده ضمنا برای درک موضوع بهتره حداقل متن ارور رو بذارید اینم نمونه که بدون مشکل عمل میکنه و در ماژول نوشته میشه:
Public User_Name As Boolean
نقل قول: تعریف متغیر سراسری
نقل قول:
نوشته شده توسط
ایلیا آخوندزاده
باسلام
جدول ضرب اشتباه نیست بلکه ما در محاسبه اشتباه میکنیم. پس Public هم مشکلی نداره قطعا اشتباهی میکنید که خطا میده ضمنا برای درک موضوع بهتره حداقل متن ارور رو بذارید اینم نمونه که بدون مشکل عمل میکنه و در ماژول نوشته میشه:
Public User_Name As Boolean
البته بیشتر منظورم کجا تعریف کردنش بود
نقل قول: تعریف متغیر سراسری
نقل قول:
نوشته شده توسط
javady_joon
البته بیشتر منظورم کجا تعریف کردنش بود
باسلام و درود
دقت کرده باشین نوشتم که در ماژول تعریف کنید.
موفق باشید