Visual Basic - problema con if...then...else...end if

Life is soft - evento anual de software empresarial
 
Vista:

problema con if...then...else...end if

Publicado por scorpionhack (120 intervenciones) el 03/12/2005 21:22:11
Buenas kiero hacer un programa k kntiene dos variables , y dos textbox. Pero tengo un problema lo k kiero hacer esk si la variable primera (x1) es "chatcnt" y si el text 1 tiene algo ya vacio haga esto(Form2.chat.Text = Form2.chat + vbCrLf + "Remoto: " + x2) y si no esta vacio haga esto(chat = "Remoto: " + x2)
y si la primera variable(x1) es "log" y el text2 tiene algo escrito haga ( txtlog.Text = txtlog.Text + vbCrLf + x2) y si esta vacio haga(txtlog.Text = x2).

Yo ya h escrito el codigo pero debe tener algun error pork no me hace la funcion k deberia tener.
aqui os dejo el kodigo aer si me lo pueden mirar.

If x1 = "chatcnt" Then
If Form2.chat.Text <> "" Then
Form2.chat.Text = Form2.chat + vbCrLf + "Remoto: " + x2
Else
chat = "Remoto: " + x2
End If
If x1 = "log" Then
If Form2.chat.Text <> "" Then
txtlog.Text = txtlog.Text + vbCrLf + x2
Else
txtlog.Text = x2
End If
End If
End If
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:problema con if...then...else...end if

Publicado por dennys oliver (8 intervenciones) el 05/12/2005 06:14:20
en
chat="remoto"+x2
pon
form2.chat.text="remoto"+x2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema con if...then...else...end if

Publicado por Zoto (4 intervenciones) el 08/12/2005 19:47:22
Hola scorpionhack.

El código que has escrito, está sintácticamente correcto, pero según he visto, comparando el pseudocódigo que escribes al principio y el código en Visual Basic, hay una diferencia.

Cuando en el pseudocódigo dices:

"si la variable primera (x1) es "chatcnt" y si el text 1 tiene algo ya vacio haga esto(Form2.chat.Text = Form2.chat + vbCrLf + "Remoto: " + x2) y si no esta vacio haga esto(chat = "Remoto: " + x2)"

En el código, escribes:

If x1 = "chatcnt" Then
If Form2.chat.Text <> "" Then
Form2.chat.Text = Form2.chat + vbCrLf + "Remoto: " + x2
Else
chat = "Remoto: " + x2
End If

Esto hace (Form2.chat.Text = Form2.chat + vbCrLf + "Remoto: " + x2) si el TextBox TIENE ALGO ESCRITO, cuando lo que tu querías era que lo hiciera si NO TENIA NADA ESCRITO.

El código debería cambiarse por el siguiente:

If x1 = "chatcnt" Then
If Form2.chat.Text = "" Then
Form2.chat.Text = Form2.chat + vbCrLf + "Remoto: " + x2
Else
chat = "Remoto: " + x2
End If

Simplemente, se cambia el símbolo <> (negación, Not) por el signo de igual = :

If Form2.chat.Text <> "" Then ---> If Form2.chat.Text = "" Then

Así determinas que si el texto está vacío "", se haga lo deseado, tal y como dices en el pseudocódigo.
Este era (según creo yo) el simple e insignificante error que, como ves, ha sido capaz de cambiar radicalmente una parte del código...

Bueno, espero que te sirva este comentario y que no te resulte pesado.

Hasta otra,

Zoto
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar