Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Problema: Object variable or With block variable not set

Estas en el tema de Problema: Object variable or With block variable not set en el foro de Visual Basic clásico en Foros del Web. Hola a todos, Tengo Visual Basic 6 y estoy trabajanado en una aplicación que me da el error : "Object variable or With block variable ...
  #1 (permalink)  
Antiguo 01/08/2008, 11:22
Avatar de Marea2  
Fecha de Ingreso: febrero-2008
Mensajes: 71
Antigüedad: 16 años, 2 meses
Puntos: 0
Problema: Object variable or With block variable not set

Hola a todos,

Tengo Visual Basic 6 y estoy trabajanado en una aplicación que me da el error : "Object variable or With block variable not set".
Mi apliación funciona de la siguiente manera:

Cuando hago clic en un commandbutton me crea dos textbox en tiempo de ejecución. Despues con un Timer hago referencia a los textbox y me da el error :
"Object variable or With block variable not set".

Aquí el codigo:

Private Sub Command1_Click()
Dim txt1 As TextBox
Dim txt2 As TextBox

text1.text = x

Set txt1 = Form1.Controls.Add("VB.textbox", Text1.Text)
With txt1
.Visible = True
.Width = 2000
.Height = 2000
.Top = 8500
.Text = ""
.Enabled = False

End With

Set txt2 = Form1.Controls.Add("VB.textbox", Text1.Text & "comp")
With txt2
.Visible = True
.Width = 2000
.Top = 6000
.Text = ""
.Enabled = False

End With
End sub

--------------------------------( hasta aquí todo bien)------------------------------

Private Sub Timer2_Timer() 'el intervalo es de 3000

Dim txt1 As TextBox
Dim txt2 As TextBox


If Text1.Text = "" Then 'mediante esto hago que se hayan creado los textbox
goto ini
End If


If txt1.Name = Text1.Text Then 'aqui es donde me da el error
txt2.Text = "True"
Load Form2
End If




If txt2.Text = "True" Then
txt1.Text = txt1.Name & vbNewLine & Form2.Text1.Text
Else
Text1.Text = ""
End If
End sub


Espero que me puedan ayudar a solucionar este error.


Muchisimas Gracias
  #2 (permalink)  
Antiguo 01/08/2008, 11:24
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Problema: Object variable or With block variable not set

Debes poner que las variables tengan alcance de módulo.
Quita estas líneas en ambas funciones:
Código PHP:
Dim txt1 As TextBox
Dim txt2 
As TextBox 
Y coloca en las declaraciones del módulo (arriba de todo):
Código PHP:
Private txt1 As TextBox
Private txt2 As TextBox 
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 01/08/2008, 11:38
Avatar de Marea2  
Fecha de Ingreso: febrero-2008
Mensajes: 71
Antigüedad: 16 años, 2 meses
Puntos: 0
Respuesta: Problema: Object variable or With block variable not set

David eres un genio muchas gracias.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:03.