elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  remplazar linea de un textbox multi linea
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: remplazar linea de un textbox multi linea  (Leído 9,079 veces)
andrer03

Desconectado Desconectado

Mensajes: 72


Ver Perfil
remplazar linea de un textbox multi linea
« en: 7 Mayo 2009, 20:27 pm »


hola tengo una pregunta que no se resolverla
tengo un textbox1 multilinea y necesito remplazar el texto de la linea 5(por ejemplo)  del texbox1 en otro textbox2 por medio de un boton.

el codigo de remplace es este


Código:
Private Sub Command1_Click()
textbox2.Text = Replace(textbox1.Text, "blabla", "line5")
End Sub

el codigo quedaria algo asi pero no se como decirle que me remplace la linea 5 del texbox1(multilinea) en el texbox2

ESPERO QUE ALGUIEN ME PUEDA AYUDAR GRACIAS!!!


En línea

APOKLIPTICO


Desconectado Desconectado

Mensajes: 3.871


Toys in the attic.


Ver Perfil
Re: remplazar linea de un textbox multi linea
« Respuesta #1 en: 7 Mayo 2009, 20:30 pm »

Podes usar un loop que cuente los vbcrlfs que hay, y que luego reemplaze esa linea, tambien podes usar el comando split y usar ocmo separador el vbcrlf y un matriz para almacenar los datos.


En línea

AMD Phenom II 1075T X6 @ 290 Mhz x 11 (HT 2036 Mhz NB Link 2616 Mhz) 1.23 Vcore
ASUS M4A89GTD-PRO/USB3
2x2gb G-Skill RipjawsX DDR3 1600 Mhz CL7 (7-8-7-24-25-1T)
Seagate 500 Gb
XFX HD4850 512Mb GDDR3. 650 Mhz/995 Mhz 1.1 Tflops.
andrer03

Desconectado Desconectado

Mensajes: 72


Ver Perfil
Re: remplazar linea de un textbox multi linea
« Respuesta #2 en: 7 Mayo 2009, 20:57 pm »

gracias pero no tengo ni iedea de como hacer eso ;/
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: remplazar linea de un textbox multi linea
« Respuesta #3 en: 8 Mayo 2009, 06:38 am »

gracias pero no tengo ni iedea de como hacer eso ;/

Aqui te pongo un pequeño codigo que uso para identificar lineas en archivos de texto plano...¡!
Ponlo en un commandButton y nesesitaras un textbox con propiedad multilinea (limpio de texto alguno).

Código
  1. Private Sub Command1_Click()
  2.    spli = Split(Text1, vbNewLine)
  3.    Text1 = 1 & vbTab & spli(0)
  4.    For i = 1 To UBound(spli)
  5.        Text1 = Text1 & vbNewLine & (i + 1) & vbTab & spli(i)
  6.    Next i
  7. End Sub
  8.  

Despues solo ejecutalo y en el texbox pega un texto cualsea con saltos de linea oprime el boton y el resultado seria algo similar al siguiente:

Texto a que pegue en el Texbox con multilinea=true

Espero te Sirva de Algo en lo que deseas.

Código
  1. <html>
  2. <head>
  3. <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
  4. <title>Ranking</title>
  5. <LINK REL="StyleSheet" HREF="style.css" TYPE="text/css">
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
  7. </head>
  8. body { background-image: url(http://musanto.webcindario.com/main_fondo.jpg); background-color: #000000; } .Estilo3 {color: #000000} </style>
  9. <body bgproperties="fixed" background="http://musanto.webcindario.com/main_fondo.jpg" style="margin-top:2px; width:634px; height:400px; padding:2px";>
  10. <table width="328" border="0" align="center"><tr><td width="322"></td></tr><tr><td>
  11. <?php
  12. include("logo.php");
  13. require 'config.htpasswd';
  14. $conn=mssql_connect($dbhost,$dbuser,$dbpasswd);
  15. $selected=mssql_select_db('MuOnline', $conn);
  16. $display_order= stripslashes($_REQUEST['requested']);
  17. if ($requested == NULL) { $display_order=clevel; }
  18. $query = "select Name,Class,cLevel,Mana,Vitality,Strength,Energy,Dexterity from Character order by $display_order desc";
  19. $result = mssql_query( $query );
  20. $sql_resets = 'Select Name, Resets from Character order by Resets desc';
  21. $resets = mssql_query( $sql_resets );
  22. echo '<div style="filter:alpha(Opacity=90); height:5px solid black; margin-bottom:2px;"><font color="#ffffff"><b><center>[ Top Players ]</center></b></font></div>';
  23. echo '<div style="filter:alpha(Opacity=90); margin-bottom:7px; margin-left:5px;width:600px; height:235px; solid black; padding:10px">';
  24. echo '<table border=0 cellSpacing=1 width=570 align=center><tr><td><b>Rank</b></td><td><b>Character</b></td><td><b>Status</b></td><td><b>Class</b></td><td><a href=topplayers.php?requested=clevel><b>Level</b></a></td><td><a href=topplayers.php?requested=mana><b>Mana</b></a></td><td><a href=topplayers.php?requested=vitality><b>VIT</b></a></td><td><a href=topplayers.php?requested=strength><b>STR</b></a></td><td><a href=topplayers.php?requested=energy><b>ENG</b></a></td><td><a href=topplayers.php?requested=dexterity><b>AGI</b></a></td> </tr>';
  25. // For Top 100 or whatever you wish just change below
  26. //$i<mssql_num_rows($result) to $i < 100
  27. for($i=0;$i < 30;++$i) {
  28. $row = mssql_fetch_row($result);
  29. echo "<tr><td>";
  30. echo $i+1;
  31. echo "</td><td><b><a href=whoiz.php?name=$row[0]>$row[0]</a></b></td><td>";
  32. $hehe = "select AccountID from Character where Name='$row[0]'";
  33. $hihi = mssql_query( $hehe );
  34. $fi4 = mssql_fetch_row($hihi);
  35. $zzz = $fi4[0];
  36. $query12 = "select ConnectStat from memb_stat where memb___id='$zzz'";
  37. $result12 = mssql_query( $query12 );
  38. $rowx = mssql_fetch_row($result12);
  39. $gas = "select bloc_code from memb_info where memb___Id='$zzz'";
  40. $gsresult = mssql_query( $gas );
  41. $gsrow = mssql_fetch_row($gsresult);
  42. $gaq = "select ctlcode from Character where Name='$row[0]'";
  43. $garesult = mssql_query( $gaq );
  44. $garow = mssql_fetch_row($garesult);
  45. if ($rowx[0] == 1) { $xir = "<center><font color=green><img src=img/on.jpg></font></center>"; }
  46. if ($rowx[0] == 0) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
  47. if ($gsrow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
  48. if ($garow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
  49. if ($garow[0] == 8) { $xir = "<font color=darkblue>Master</font></center>"; }
  50. if ($garow[0] == 24) { $xir = "<center><img src='img/a.gif'>"; }
  51. echo $xir;
  52. echo '</td><td><b>';
  53. if($row[1] == 0){ echo 'DW'; }
  54. if($row[1] == 1){ echo 'SM'; }
  55. if($row[1] == 16){echo 'DK';}
  56. if($row[1] == 17){echo 'BK';}
  57. if($row[1] == 32){echo 'Elf';}
  58. if($row[1] == 33){echo 'M. Elf';}
  59. if($row[1] == 48){echo 'MG';}
  60. if($row[1] == 64){echo 'DL';}
  61. echo "</b></td><td><b>$row[2]</b></td><td>$row[3]</td><td><b>$row[4]</b></td><td>";
  62. echo ROUND($row[5],0);
  63. echo "</td><td>$row[6]</td><td>$row[7]</td></tr>";
  64. }
  65. echo '</table>';
  66. echo '<table cellspacing=1>';
  67. echo '<div style="filter:alpha(Opacity=90); height:5px solid black; margin-bottom:2px;"><font color="#ffffff"><b><center>[ Top Resets ]</center></b></font></div>';
  68. echo '<tr><td><center><b>Rank</b></center></td><td ><b>Character</b></td><td ><b>Resets</b></td></tr>';
  69. for($i=0;$i < 10;++$i){
  70. $top = mssql_fetch_row($resets);
  71. echo "<tr><td>";
  72. echo $i + 1;
  73. echo "</td><td><b><a href=whoiz.php?name=$top[0]>$top[0]</a></b></td><td>$top[1]</td>";
  74. }
  75. echo '</tr></table>';
  76. $conn=mssql_close();
  77. $i = 0;
  78. $query = 'Select TOP 5 G_Name, G_Score, G_Notice, G_Master From Guild order by G_Score desc';
  79. $result = mssql_query( $query );
  80. echo '<center><table border=0 cellSpacing=0 width=400 align=left>';
  81. echo '<div style="filter:alpha(Opacity=90); height:5px solid black; margin-bottom:2px;"><font color="#ffffff"><b><center>[ Top Clanes ]</center></b></font></div>';
  82. echo '<tr><td><center><font color=green face=Arial >Rank</font></center></td><td><center><font color=green face=Arial >Guild</font></center></td><td><center><font color=green face=Arial >Master</font></center></td><td><center><font color=green face=Arial >Members</font></center></td><td><center><font color=green face=Arial >Score</font></center></td>';
  83. //$i<mssql_num_rows($result) to $i < 100
  84. $waw = mssql_query("SELECT count(*) FROM Guild");
  85. $xex = mssql_result($waw, 0, 0);
  86. for($i=0;$i < 5;++$i)
  87. {
  88. $row = mssql_fetch_row($result);
  89. $sxs = mssql_query("SELECT count(*) FROM GuildMember WHERE G_Name='$row[0]'");
  90. $ccc = mssql_result($sxs, 0, 0);
  91. echo "<tr><td><center>";
  92. echo $i+1;
  93. echo "</center></td><td width=80><center><font color=blue><a href=gu1ld.php?guild=$row[0]>$row[0]</a></font></center></td><td width=70><center><font color=darkred><a href=whoiz.php?name=$row[3]>$row[3]</a></font></center></td><td width=100><center><font color=darkred>$ccc";
  94. echo '</font></center></td><td width=80><table style="filter:glow(color=yellow,strength=5)" align="center">';
  95. if($row[1] == null){echo "=|-Null-|=";}
  96. elseif($row[1] ==1){echo "=|-0000-|=";}
  97. elseif($row[1] <= 0){echo "=|-"; echo $row[1]+100; echo "-|=";}
  98. elseif($row[1] >=0){echo "=|-"; echo $row[1]; echo "-|=";}
  99. elseif($row[1] >=2){echo "=|-"; echo $row[1]+98; echo "-|=";}
  100. echo '</table></td>';
  101. }
  102. echo '</td></tr></table>';
  103. echo '</body>';
  104. echo '</html>';
  105. $conn=mssql_close();
  106.  
  107.  
  108. $cntACmp =ob_get_contents();
  109. $cntACmp=str_replace("\n",' ',$cntACmp);
  110. $cntACmp=ereg_replace('[[:space:]]+',' ',$cntACmp);
  111. ob_start("ob_gzhandler");
  112. echo $cntACmp;
  113. ?>
  114.  
Al apretar el boton
Código
  1. 1 <html>
  2. 2 <head>
  3. 3 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
  4. 4 <title>Ranking</title>
  5. 5 <LINK REL="StyleSheet" HREF="style.css" TYPE="text/css">
  6. 6 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
  7. 7 </head>
  8. 8 body { background-image: url(http://musanto.webcindario.com/main_fondo.jpg); background-color: #000000; } .Estilo3 {color: #000000} </style>
  9. 9 <body bgproperties="fixed" background="http://musanto.webcindario.com/main_fondo.jpg" style="margin-top:2px; width:634px; height:400px; padding:2px";>
  10. 10 <table width="328" border="0" align="center"><tr><td width="322"></td></tr><tr><td>
  11. 11 <?php
  12. 12 ob_start();
  13. 13 include("logo.php");
  14. 14 require 'config.htpasswd';
  15. 15 $conn=mssql_connect($dbhost,$dbuser,$dbpasswd);
  16. 16 $selected=mssql_select_db('MuOnline', $conn);
  17. 17 $display_order= stripslashes($_REQUEST['requested']);
  18. 18 if ($requested == NULL) { $display_order=clevel; }
  19. 19 $query = "select Name,Class,cLevel,Mana,Vitality,Strength,Energy,Dexterity from Character order by $display_order desc";
  20. 20 $result = mssql_query( $query );
  21. 21 $sql_resets = 'Select Name, Resets from Character order by Resets desc';
  22. 22 $resets = mssql_query( $sql_resets );
  23. 23 echo '<div style="filter:alpha(Opacity=90); height:5px solid black; margin-bottom:2px;"><font color="#ffffff"><b><center>[ Top Players ]</center></b></font></div>';
  24. 24 echo '<div style="filter:alpha(Opacity=90); margin-bottom:7px; margin-left:5px;width:600px; height:235px; solid black; padding:10px">';
  25. 25 echo '<table border=0 cellSpacing=1 width=570 align=center><tr><td><b>Rank</b></td><td><b>Character</b></td><td><b>Status</b></td><td><b>Class</b></td><td><a href=topplayers.php?requested=clevel><b>Level</b></a></td><td><a href=topplayers.php?requested=mana><b>Mana</b></a></td><td><a href=topplayers.php?requested=vitality><b>VIT</b></a></td><td><a href=topplayers.php?requested=strength><b>STR</b></a></td><td><a href=topplayers.php?requested=energy><b>ENG</b></a></td><td><a href=topplayers.php?requested=dexterity><b>AGI</b></a></td> </tr>';
  26. 26 // For Top 100 or whatever you wish just change below
  27. 27 //$i<mssql_num_rows($result) to $i < 100
  28. 28 for($i=0;$i < 30;++$i) {
  29. 29 $row = mssql_fetch_row($result);
  30. 30 echo "<tr><td>";
  31. 31 echo $i+1;
  32. 32 echo "</td><td><b><a href=whoiz.php?name=$row[0]>$row[0]</a></b></td><td>";
  33. 33 $hehe = "select AccountID from Character where Name='$row[0]'";
  34. 34 $hihi = mssql_query( $hehe );
  35. 35 $fi4 = mssql_fetch_row($hihi);
  36. 36 $zzz = $fi4[0];
  37. 37 $query12 = "select ConnectStat from memb_stat where memb___id='$zzz'";
  38. 38 $result12 = mssql_query( $query12 );
  39. 39 $rowx = mssql_fetch_row($result12);
  40. 40 $gas = "select bloc_code from memb_info where memb___Id='$zzz'";
  41. 41 $gsresult = mssql_query( $gas );
  42. 42 $gsrow = mssql_fetch_row($gsresult);
  43. 43 $gaq = "select ctlcode from Character where Name='$row[0]'";
  44. 44 $garesult = mssql_query( $gaq );
  45. 45 $garow = mssql_fetch_row($garesult);
  46. 46 if ($rowx[0] == 1) { $xir = "<center><font color=green><img src=img/on.jpg></font></center>"; }
  47. 47 if ($rowx[0] == 0) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
  48. 48 if ($gsrow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
  49. 49 if ($garow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
  50. 50 if ($garow[0] == 8) { $xir = "<font color=darkblue>Master</font></center>"; }
  51. 51 if ($garow[0] == 24) { $xir = "<center><img src='img/a.gif'>"; }
  52. 52 echo $xir;
  53. 53 echo '</td><td><b>';
  54. 54 if($row[1] == 0){ echo 'DW'; }
  55. 55 if($row[1] == 1){ echo 'SM'; }
  56. 56 if($row[1] == 16){echo 'DK';}
  57. 57 if($row[1] == 17){echo 'BK';}
  58. 58 if($row[1] == 32){echo 'Elf';}
  59. 59 if($row[1] == 33){echo 'M. Elf';}
  60. 60 if($row[1] == 48){echo 'MG';}
  61. 61 if($row[1] == 64){echo 'DL';}
  62. 62 echo "</b></td><td><b>$row[2]</b></td><td>$row[3]</td><td><b>$row[4]</b></td><td>";
  63. 63 echo ROUND($row[5],0);
  64. 64 echo "</td><td>$row[6]</td><td>$row[7]</td></tr>";
  65. 65 }
  66. 66 echo '</table>';
  67. 67 echo '<table cellspacing=1>';
  68. 68 echo '<div style="filter:alpha(Opacity=90); height:5px solid black; margin-bottom:2px;"><font color="#ffffff"><b><center>[ Top Resets ]</center></b></font></div>';
  69. 69 echo '<tr><td><center><b>Rank</b></center></td><td ><b>Character</b></td><td ><b>Resets</b></td></tr>';
  70. 70 for($i=0;$i < 10;++$i){
  71. 71 $top = mssql_fetch_row($resets);
  72. 72 echo "<tr><td>";
  73. 73 echo $i + 1;
  74. 74 echo "</td><td><b><a href=whoiz.php?name=$top[0]>$top[0]</a></b></td><td>$top[1]</td>";
  75. 75 }
  76. 76 echo '</tr></table>';
  77. 77 $conn=mssql_close();
  78. 78 $i = 0;
  79. 79 $query = 'Select TOP 5 G_Name, G_Score, G_Notice, G_Master From Guild order by G_Score desc';
  80. 80 $result = mssql_query( $query );
  81. 81 echo '<center><table border=0 cellSpacing=0 width=400 align=left>';
  82. 82 echo '<div style="filter:alpha(Opacity=90); height:5px solid black; margin-bottom:2px;"><font color="#ffffff"><b><center>[ Top Clanes ]</center></b></font></div>';
  83. 83 echo '<tr><td><center><font color=green face=Arial >Rank</font></center></td><td><center><font color=green face=Arial >Guild</font></center></td><td><center><font color=green face=Arial >Master</font></center></td><td><center><font color=green face=Arial >Members</font></center></td><td><center><font color=green face=Arial >Score</font></center></td>';
  84. 84 //$i<mssql_num_rows($result) to $i < 100
  85. 85 $waw = mssql_query("SELECT count(*) FROM Guild");
  86. 86 $xex = mssql_result($waw, 0, 0);
  87. 87 for($i=0;$i < 5;++$i)
  88. 88 {
  89. 89 $row = mssql_fetch_row($result);
  90. 90 $sxs = mssql_query("SELECT count(*) FROM GuildMember WHERE G_Name='$row[0]'");
  91. 91 $ccc = mssql_result($sxs, 0, 0);
  92. 92 echo "<tr><td><center>";
  93. 93 echo $i+1;
  94. 94 echo "</center></td><td width=80><center><font color=blue><a href=gu1ld.php?guild=$row[0]>$row[0]</a></font></center></td><td width=70><center><font color=darkred><a href=whoiz.php?name=$row[3]>$row[3]</a></font></center></td><td width=100><center><font color=darkred>$ccc";
  95. 95 echo '</font></center></td><td width=80><table style="filter:glow(color=yellow,strength=5)" align="center">';
  96. 96 if($row[1] == null){echo "=|-Null-|=";}
  97. 97 elseif($row[1] ==1){echo "=|-0000-|=";}
  98. 98 elseif($row[1] <= 0){echo "=|-"; echo $row[1]+100; echo "-|=";}
  99. 99 elseif($row[1] >=0){echo "=|-"; echo $row[1]; echo "-|=";}
  100. 100 elseif($row[1] >=2){echo "=|-"; echo $row[1]+98; echo "-|=";}
  101. 101 echo '</table></td>';
  102. 102 }
  103. 103 echo '</td></tr></table>';
  104. 104 echo '</body>';
  105. 105 echo '</html>';
  106. 106 $conn=mssql_close();
  107. 107
  108. 108
  109. 109 $cntACmp =ob_get_contents();
  110. 111 $cntACmp=str_replace("\n",' ',$cntACmp);
  111. 112 $cntACmp=ereg_replace('[[:space:]]+',' ',$cntACmp);
  112. 113 ob_start("ob_gzhandler");
  113. 114 echo $cntACmp;
  114. 115 ob_end_flush();
  115. 116 ?>
  116.  

Espero te aya Servido de Algo...¡!

Dulces Luinas
« Última modificación: 8 Mayo 2009, 06:43 am por ░▒▓BlackZeroҖ▓▒░ » En línea

The Dark Shadow is my passion.
EddyW

Desconectado Desconectado

Mensajes: 187



Ver Perfil WWW
Re: remplazar linea de un textbox multi linea
« Respuesta #4 en: 8 Mayo 2009, 11:38 am »

Copia esta funcion en Codigo General del form1:
Código
  1. Private Function ReplaceT(OutPut As Object, Txt1 As String, Txt2 As String, Line As Long)
  2. Dim Spli() As String
  3. Dim Tmp As String
  4. Dim LineTmp As String
  5. Spli = Split(OutPut, vbNewLine)
  6. For i = 0 To UBound(Spli)
  7.    If i = Val(Line - 1) Then
  8.        LineTmp = Spli(Line - 1)
  9.        LineTmp = Replace(LineTmp, Txt1, Txt2)
  10.        Tmp = Tmp & LineTmp & vbNewLine
  11.    Else
  12.        Tmp = Tmp & Spli(i) & vbNewLine
  13.    End If
  14. Next i
  15. ReplaceT = Tmp
  16. End Function
Ese es el code que busca y reemplaza caracteres por linea lo usas asi con un command button:
Código
  1. Private Sub Command1_Click()
  2. Text2.Text = ReplaceT(Text1, "Esto", "Por esto", 1)
  3. End Sub
Text2 obtendra los cambios leidos del objeto Text1, en este caso solo se pone text1 son .text "Esto" es el texto que se va ha buscar y "Por Esto" es por el que se va ha reemplazar y 1 es la linea de texto donde se va a buscar..
Espero te sirva esta funcion..
SaluDOS!!!
PD: Cualquier duda posteas..
« Última modificación: 8 Mayo 2009, 11:40 am por 3D1 » En línea

cassiani


Desconectado Desconectado

Mensajes: 978


« Anterior | Próximo »


Ver Perfil WWW
Re: remplazar linea de un textbox multi linea
« Respuesta #5 en: 8 Mayo 2009, 17:30 pm »


hola tengo una pregunta que no se resolverla
tengo un textbox1 multilinea y necesito remplazar el texto de la linea 5(por ejemplo)  del texbox1 en otro textbox2 por medio de un boton.

Hola, hace tiempo me hice una función para ello, deja y te la busco ..

edit:

Código
  1. Option Explicit
  2.  
  3. Private Sub Command1_Click()
  4. On Error GoTo sError
  5.  
  6.    txtMultilinea.Text = ReplaceLine(txtMultilinea.Text, txtCadena, Int(txtNumLinea.Text))
  7.  
  8.    Exit Sub
  9. sError:
  10.    MsgBox "Error número: " & Err.Number & ", descripción: " & Err.Description
  11.    Resume Next
  12. End Sub
  13.  
  14. Function ReplaceLine(ByVal sCadena As String, sForReplace As String, Linea As Integer) As String
  15. On Error GoTo sError
  16. Dim sArray() As String
  17. Dim I        As Integer
  18.  
  19.    If sCadena = vbNullString Or sForReplace = vbNullString Then
  20.        MsgBox "¡Parámetros incorrectos!", vbCritical
  21.        ReplaceLine = sCadena
  22.        Exit Function
  23.    End If
  24.  
  25.    sArray() = Split(sCadena, vbCrLf)
  26.  
  27.    If Linea > UBound(sArray) Then
  28.        MsgBox "¡Ha introducido " & Linea & " como número de línea, pero solo hay " _
  29.        & UBound(sArray) & "!"
  30.        ReplaceLine = sCadena
  31.        Exit Function
  32.    End If
  33.  
  34.    sArray(Linea - 1) = sForReplace
  35.    sCadena = vbNullString
  36.    For I = LBound(sArray) To UBound(sArray)
  37.        If I = LBound(sArray) Then
  38.            sCadena = sArray(I)
  39.        Else
  40.            sCadena = sCadena & vbCrLf & sArray(I)
  41.        End If
  42.    Next
  43.    ReplaceLine = sCadena
  44.  
  45.    Exit Function
  46. sError:
  47.    MsgBox "Error número: " & Err.Number & ", descripción: " & Err.Description
  48.    Resume Next
  49. End Function
  50.  
  51. Private Sub txtNumLinea_KeyPress(KeyAscii As Integer)
  52.    If Not IsNumeric(Chr(KeyAscii)) And Not KeyAscii = 8 Then KeyAscii = 0
  53. End Sub
  54.  

see, se ve un poco largo, pero así es cuando debemos aplicarle validaciones  :-X
no me da tiempo de revisar si algo debe cambiar, pero así funciona perfecto...

saludos,
« Última modificación: 8 Mayo 2009, 17:45 pm por cΔssiΔnі » En línea

andrer03

Desconectado Desconectado

Mensajes: 72


Ver Perfil
Re: remplazar linea de un textbox multi linea
« Respuesta #6 en: 8 Mayo 2009, 19:51 pm »

gracias ya lo he solucionado con este modulo

MODULO
Código:
Option Explicit

Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_GETLINE = &HC4

Private Declare Function SendMessage Lib "user32" _
                                         Alias "SendMessageA" _
                                         (ByVal hwnd As Long, _
                                         ByVal wMsg As Long, _
                                         ByVal wParam As Long, _
                                         ByVal lParam As String) _
                                         As Long
'

Public Function GetLine(txtTextBox As TextBox, Optional Linea As Long) As String
    Dim LineaActual As String * 255
    Dim LineaNumero As Long
    Dim Longitud As Long
    If Linea = 0 Then 'No se pasó línea
        'La que está en la posición del cursor:
        LineaNumero = SendMessage(txtTextBox.hwnd, EM_LINEFROMCHAR, txtTextBox.SelStart, 0&)
    Else
        LineaNumero = Linea - 1 '(Base 0)
    End If
    LineaActual = String(255, Chr(255))

    Call SendMessage(txtTextBox.hwnd, EM_GETLINE, LineaNumero, LineaActual)
    Longitud = InStr(LineaActual, Chr(255))
    If Longitud > 0 Then
        GetLine = Left(LineaActual, Longitud - 1)
    Else
        GetLine = LineaActual
    End If
End Function


Replace Code

Código:
largo = Len(GetLine(Text1, 5))
busco = "email:"
For i = 0 To largo Step 1
busco = busco & " "
Next
txt_Contenido = Replace(txt_Contenido, busco, "email: " & GetLine(Text1, 5))

funciona bien y facil de entender gracias por su ayuda de todos modos :)

En línea

APOKLIPTICO


Desconectado Desconectado

Mensajes: 3.871


Toys in the attic.


Ver Perfil
Re: remplazar linea de un textbox multi linea
« Respuesta #7 en: 8 Mayo 2009, 23:24 pm »

Apis para un problema tan simple???
En línea

AMD Phenom II 1075T X6 @ 290 Mhz x 11 (HT 2036 Mhz NB Link 2616 Mhz) 1.23 Vcore
ASUS M4A89GTD-PRO/USB3
2x2gb G-Skill RipjawsX DDR3 1600 Mhz CL7 (7-8-7-24-25-1T)
Seagate 500 Gb
XFX HD4850 512Mb GDDR3. 650 Mhz/995 Mhz 1.1 Tflops.
YST


Desconectado Desconectado

Mensajes: 965


I'm you


Ver Perfil WWW
Re: remplazar linea de un textbox multi linea
« Respuesta #8 en: 8 Mayo 2009, 23:48 pm »

public function GetLine (cTextBox as textbox,line as integer ) as string
dim variante as variant
variante  = Split(cTextBox.text, vbNewLine)
if ubound(variante) < 4 then
 GetLine = "0"
else
 GetLine = variante(4)
end if
end function

Estoy en linux no tengo el visual basic para probarla si tiene algun error perdón :P
En línea



Yo le enseñe a Kayser a usar objetos en ASM
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: remplazar linea de un textbox multi linea
« Respuesta #9 en: 9 Mayo 2009, 01:00 am »

gracias ya lo he solucionado con este modulo

MODULO
Código:
Option Explicit

Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_GETLINE = &HC4

Private Declare Function SendMessage Lib "user32" _
                                         Alias "SendMessageA" _
                                         (ByVal hwnd As Long, _
                                         ByVal wMsg As Long, _
                                         ByVal wParam As Long, _
                                         ByVal lParam As String) _
                                         As Long
'

Public Function GetLine(txtTextBox As TextBox, Optional Linea As Long) As String
    Dim LineaActual As String * 255
    Dim LineaNumero As Long
    Dim Longitud As Long
    If Linea = 0 Then 'No se pasó línea
        'La que está en la posición del cursor:
        LineaNumero = SendMessage(txtTextBox.hwnd, EM_LINEFROMCHAR, txtTextBox.SelStart, 0&)
    Else
        LineaNumero = Linea - 1 '(Base 0)
    End If
    LineaActual = String(255, Chr(255))

    Call SendMessage(txtTextBox.hwnd, EM_GETLINE, LineaNumero, LineaActual)
    Longitud = InStr(LineaActual, Chr(255))
    If Longitud > 0 Then
        GetLine = Left(LineaActual, Longitud - 1)
    Else
        GetLine = LineaActual
    End If
End Function


Replace Code

Código:
largo = Len(GetLine(Text1, 5))
busco = "email:"
For i = 0 To largo Step 1
busco = busco & " "
Next
txt_Contenido = Replace(txt_Contenido, busco, "email: " & GetLine(Text1, 5))

funciona bien y facil de entender gracias por su ayuda de todos modos :)



mmm analisa bien ese modulo busca una cadena de texto y devuelve la linea pertinente imagina si se aya ese mismo texto en otra linea que pasaria? pensaste en ello? mejor usa una funcion de las que ya te postearon o ajusta este modulo por que no me convence realmente

por ejemplo en vez de que sea

Código
  1. Public Function GetLine(txtTextBox As TextBox, Optional Linea As Long) As String
Deberia ser

Código
  1. Public Function GetLine(txtTextBox As String, byval Optional Linea As Long) As String

Puesto que una funcion deberia trabajar de forma un poco general y no Estandar si no despues tendrias que estar moviendole a tu codigo y si este fuese bastamente grande tendrias problemas, asi lo veo.!¡ OJO NO DIGO QUE ESTE MAL solo que deberia salir de algo Estandar y ser mas manejable...¡!

Dulces Lunas
En línea

The Dark Shadow is my passion.
Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Duda Leer Linea por Linea de Un textBox
Programación Visual Basic
NsTeam 2 7,505 Último mensaje 1 Diciembre 2010, 02:58 am
por Stelio Kontos
Remplazar texto: salto de línea
Dudas Generales
MasterPunk 6 33,599 Último mensaje 1 Agosto 2011, 07:01 am
por WaAYa HaCK
Extraer texto de textarea linea por linea
Programación General
alcipri 6 9,579 Último mensaje 24 Octubre 2014, 13:29 pm
por alcipri
Lectura de Línea a Línea de un archivo de números enteros en C++
Programación C/C++
julian21931500 7 9,883 Último mensaje 25 Febrero 2015, 04:11 am
por julian21931500
Remplazar la linea entera...
Scripting
Cascuda 2 2,192 Último mensaje 25 Abril 2015, 22:25 pm
por Cascuda
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines