PDA

View Full Version : سوال: وجود یا عدم وجود یک آبجکت در فرم



میلاد علوی
سه شنبه 07 آذر 1391, 19:57 عصر
سلام
با توجه به کد زیر ،سوال من اینه که چجوری بفهمم که txtTextBox در فرم هست یا نه ؟؟ در ضمن از طریق is nothing و is object هم ارور می دهد


' This program demonstrates how you can add and delete
' controls on your form dynamically.


' Creates text box and label.
Private Sub cmdCreate_Click()
' Creates label. controls.Add function takes three variables.
' first ("vb.label") accepts what type of control you want created,
' second ("lblLabel1") accepts the name of the control, the last
' one (frmControl) accepts where you want this control to be placed.
Set ctlName = frmControl.Controls.Add("vb.label", "lblLabel1", frmControl)
' Make controls visible. This step is required if you want the control
' to be visible.
ctlName.Visible = True
' Move positions the control requires four arguments
' (left, top, width, height)
ctlName.Move 500, 500, 1500, 250
ctlName.Caption = "Label 1"
Set ctlName = _
frmControl.Controls.Add("vb.textbox", "txtTextBox", frmControl)
ctlName.Visible = True
ctlName.Move 2000, 500, 1500, 250

End Sub
' Quits the program.
Private Sub cmdExit_Click()
End
End Sub

' Removes the controls created in the cmdCreate_Click()
' procedure.
Private Sub cmdRemove_Click()
frmControl.Controls.Remove "txtTextBox"
frmControl.Controls.Remove "lblLabel1"
End Sub
با تشکر

محسن واژدی
سه شنبه 07 آذر 1391, 20:16 عصر
سلام علیکم
تابع زیر را بررسی کنید:
Public Function IsObjectExist(fForm As Form, sObjectName$) As Boolean
On Error Resume Next
IsObjectExist = fForm.Controls(sObjectName$).Name > "":
End Function

برای مثال:
Private Sub Command1_Click()
MsgBox IsObjectExist(Me, "Command2")
End Sub

موفق باشید

میلاد علوی
سه شنبه 07 آذر 1391, 20:21 عصر
دست شما درد نکنه ، ایشاا... خیر از دنیات ببینی

میلاد علوی
سه شنبه 07 آذر 1391, 20:31 عصر
مششششکل پیش اومد :(

If frmm.Controls("Timer1") = False Then Set Timer1 = frmm.Controls.Add("VB.Timer", "Timer1")

حالا ارور میده که این آبجکت در فرم نیست

محسن واژدی
سه شنبه 07 آذر 1391, 20:36 عصر
مششششکل پیش اومد :(

If frmm.Controls("Timer1") = False Then Set Timer1 = frmm.Controls.Add("VB.Timer", "Timer1")

حالا ارور میده که این آبجکت در فرم نیست

به این صورت هم تست کنین:

If IsObjectExist(frmm,"Timer1") = False Then Set Timer1 = frmm.Controls.Add("VB.Timer", "Timer1")


موفق باشید

میلاد علوی
سه شنبه 07 آذر 1391, 20:45 عصر
مرسی رفیق ، واقعا ممنونم ازت خیلی لطف کردی