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
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!!!
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.
gracias pero no tengo ni iedea de como hacer eso ;/
Cita de: andrer03 en 7 Mayo 2009, 20:57 PM
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).
Private Sub Command1_Click()
spli = Split(Text1, vbNewLine)
Text1 = 1 & vbTab & spli(0)
For i = 1 To UBound(spli)
Text1 = Text1 & vbNewLine & (i + 1) & vbTab & spli(i)
Next i
End Sub
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.
<html>
<head>
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title>Ranking</title>
<LINK REL="StyleSheet" HREF="style.css" TYPE="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
</head>
body { background-image: url(http://musanto.webcindario.com/main_fondo.jpg); background-color: #000000; } .Estilo3 {color: #000000} </style>
<body bgproperties="fixed" background="http://musanto.webcindario.com/main_fondo.jpg" style="margin-top:2px; width:634px; height:400px; padding:2px";>
<table width="328" border="0" align="center"><tr><td width="322"></td></tr><tr><td>
<?php
ob_start();
include("logo.php");
require 'config.htpasswd';
$conn=mssql_connect($dbhost,$dbuser,$dbpasswd);
$selected=mssql_select_db('MuOnline', $conn);
$display_order= stripslashes($_REQUEST['requested']);
if ($requested == NULL) { $display_order=clevel; }
$query = "select Name,Class,cLevel,Mana,Vitality,Strength,Energy,Dexterity from Character order by $display_order desc";
$result = mssql_query( $query );
$sql_resets = 'Select Name, Resets from Character order by Resets desc';
$resets = mssql_query( $sql_resets );
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>';
echo '<div style="filter:alpha(Opacity=90); margin-bottom:7px; margin-left:5px;width:600px; height:235px; solid black; padding:10px">';
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>';
// For Top 100 or whatever you wish just change below
//$i<mssql_num_rows($result) to $i < 100
for($i=0;$i < 30;++$i) {
$row = mssql_fetch_row($result);
echo "<tr><td>";
echo $i+1;
echo "</td><td><b><a href=whoiz.php?name=$row[0]>$row[0]</a></b></td><td>";
$hehe = "select AccountID from Character where Name='$row[0]'";
$hihi = mssql_query( $hehe );
$fi4 = mssql_fetch_row($hihi);
$zzz = $fi4[0];
$query12 = "select ConnectStat from memb_stat where memb___id='$zzz'";
$result12 = mssql_query( $query12 );
$rowx = mssql_fetch_row($result12);
$gas = "select bloc_code from memb_info where memb___Id='$zzz'";
$gsresult = mssql_query( $gas );
$gsrow = mssql_fetch_row($gsresult);
$gaq = "select ctlcode from Character where Name='$row[0]'";
$garesult = mssql_query( $gaq );
$garow = mssql_fetch_row($garesult);
if ($rowx[0] == 1) { $xir = "<center><font color=green><img src=img/on.jpg></font></center>"; }
if ($rowx[0] == 0) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
if ($gsrow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
if ($garow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
if ($garow[0] == 8) { $xir = "<font color=darkblue>Master</font></center>"; }
if ($garow[0] == 24) { $xir = "<center><img src='img/a.gif'>"; }
echo $xir;
echo '</td><td><b>';
if($row[1] == 0){ echo 'DW'; }
if($row[1] == 1){ echo 'SM'; }
if($row[1] == 16){echo 'DK';}
if($row[1] == 17){echo 'BK';}
if($row[1] == 32){echo 'Elf';}
if($row[1] == 33){echo 'M. Elf';}
if($row[1] == 48){echo 'MG';}
if($row[1] == 64){echo 'DL';}
echo "</b></td><td><b>$row[2]</b></td><td>$row[3]</td><td><b>$row[4]</b></td><td>";
echo ROUND($row[5],0);
echo "</td><td>$row[6]</td><td>$row[7]</td></tr>";
}
echo '</table>';
echo '<table cellspacing=1>';
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>';
echo '<tr><td><center><b>Rank</b></center></td><td ><b>Character</b></td><td ><b>Resets</b></td></tr>';
for($i=0;$i < 10;++$i){
$top = mssql_fetch_row($resets);
echo "<tr><td>";
echo $i + 1;
echo "</td><td><b><a href=whoiz.php?name=$top[0]>$top[0]</a></b></td><td>$top[1]</td>";
}
echo '</tr></table>';
$conn=mssql_close();
$i = 0;
$query = 'Select TOP 5 G_Name, G_Score, G_Notice, G_Master From Guild order by G_Score desc';
$result = mssql_query( $query );
echo '<center><table border=0 cellSpacing=0 width=400 align=left>';
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>';
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>';
//$i<mssql_num_rows($result) to $i < 100
$waw = mssql_query("SELECT count(*) FROM Guild");
$xex = mssql_result($waw, 0, 0);
for($i=0;$i < 5;++$i)
{
$row = mssql_fetch_row($result);
$sxs = mssql_query("SELECT count(*) FROM GuildMember WHERE G_Name='$row[0]'");
$ccc = mssql_result($sxs, 0, 0);
echo "<tr><td><center>";
echo $i+1;
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";
echo '</font></center></td><td width=80><table style="filter:glow(color=yellow,strength=5)" align="center">';
if($row[1] == null){echo "=|-Null-|=";}
elseif($row[1] ==1){echo "=|-0000-|=";}
elseif($row[1] <= 0){echo "=|-"; echo $row[1]+100; echo "-|=";}
elseif($row[1] >=0){echo "=|-"; echo $row[1]; echo "-|=";}
elseif($row[1] >=2){echo "=|-"; echo $row[1]+98; echo "-|=";}
echo '</table></td>';
}
echo '</td></tr></table>';
echo '</body>';
echo '</html>';
$conn=mssql_close();
$cntACmp =ob_get_contents();
ob_end_clean();
$cntACmp=str_replace("\n",' ',$cntACmp);
$cntACmp=ereg_replace('[[:space:]]+',' ',$cntACmp);
ob_start("ob_gzhandler");
echo $cntACmp;
ob_end_flush();
?>
Al apretar el boton
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 ob_start();
13 include("logo.php");
14 require 'config.htpasswd';
15 $conn=mssql_connect($dbhost,$dbuser,$dbpasswd);
16 $selected=mssql_select_db('MuOnline', $conn);
17 $display_order= stripslashes($_REQUEST['requested']);
18 if ($requested == NULL) { $display_order=clevel; }
19 $query = "select Name,Class,cLevel,Mana,Vitality,Strength,Energy,Dexterity from Character order by $display_order desc";
20 $result = mssql_query( $query );
21 $sql_resets = 'Select Name, Resets from Character order by Resets desc';
22 $resets = mssql_query( $sql_resets );
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 echo '<div style="filter:alpha(Opacity=90); margin-bottom:7px; margin-left:5px;width:600px; height:235px; solid black; padding:10px">';
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 // For Top 100 or whatever you wish just change below
27 //$i<mssql_num_rows($result) to $i < 100
28 for($i=0;$i < 30;++$i) {
29 $row = mssql_fetch_row($result);
30 echo "<tr><td>";
31 echo $i+1;
32 echo "</td><td><b><a href=whoiz.php?name=$row[0]>$row[0]</a></b></td><td>";
33 $hehe = "select AccountID from Character where Name='$row[0]'";
34 $hihi = mssql_query( $hehe );
35 $fi4 = mssql_fetch_row($hihi);
36 $zzz = $fi4[0];
37 $query12 = "select ConnectStat from memb_stat where memb___id='$zzz'";
38 $result12 = mssql_query( $query12 );
39 $rowx = mssql_fetch_row($result12);
40 $gas = "select bloc_code from memb_info where memb___Id='$zzz'";
41 $gsresult = mssql_query( $gas );
42 $gsrow = mssql_fetch_row($gsresult);
43 $gaq = "select ctlcode from Character where Name='$row[0]'";
44 $garesult = mssql_query( $gaq );
45 $garow = mssql_fetch_row($garesult);
46 if ($rowx[0] == 1) { $xir = "<center><font color=green><img src=img/on.jpg></font></center>"; }
47 if ($rowx[0] == 0) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
48 if ($gsrow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
49 if ($garow[0] == 1) { $xir = "<center><font color=red><img src=img/off.jpg></font></center>"; }
50 if ($garow[0] == 8) { $xir = "<font color=darkblue>Master</font></center>"; }
51 if ($garow[0] == 24) { $xir = "<center><img src='img/a.gif'>"; }
52 echo $xir;
53 echo '</td><td><b>';
54 if($row[1] == 0){ echo 'DW'; }
55 if($row[1] == 1){ echo 'SM'; }
56 if($row[1] == 16){echo 'DK';}
57 if($row[1] == 17){echo 'BK';}
58 if($row[1] == 32){echo 'Elf';}
59 if($row[1] == 33){echo 'M. Elf';}
60 if($row[1] == 48){echo 'MG';}
61 if($row[1] == 64){echo 'DL';}
62 echo "</b></td><td><b>$row[2]</b></td><td>$row[3]</td><td><b>$row[4]</b></td><td>";
63 echo ROUND($row[5],0);
64 echo "</td><td>$row[6]</td><td>$row[7]</td></tr>";
65 }
66 echo '</table>';
67 echo '<table cellspacing=1>';
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 echo '<tr><td><center><b>Rank</b></center></td><td ><b>Character</b></td><td ><b>Resets</b></td></tr>';
70 for($i=0;$i < 10;++$i){
71 $top = mssql_fetch_row($resets);
72 echo "<tr><td>";
73 echo $i + 1;
74 echo "</td><td><b><a href=whoiz.php?name=$top[0]>$top[0]</a></b></td><td>$top[1]</td>";
75 }
76 echo '</tr></table>';
77 $conn=mssql_close();
78 $i = 0;
79 $query = 'Select TOP 5 G_Name, G_Score, G_Notice, G_Master From Guild order by G_Score desc';
80 $result = mssql_query( $query );
81 echo '<center><table border=0 cellSpacing=0 width=400 align=left>';
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 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 //$i<mssql_num_rows($result) to $i < 100
85 $waw = mssql_query("SELECT count(*) FROM Guild");
86 $xex = mssql_result($waw, 0, 0);
87 for($i=0;$i < 5;++$i)
88 {
89 $row = mssql_fetch_row($result);
90 $sxs = mssql_query("SELECT count(*) FROM GuildMember WHERE G_Name='$row[0]'");
91 $ccc = mssql_result($sxs, 0, 0);
92 echo "<tr><td><center>";
93 echo $i+1;
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 echo '</font></center></td><td width=80><table style="filter:glow(color=yellow,strength=5)" align="center">';
96 if($row[1] == null){echo "=|-Null-|=";}
97 elseif($row[1] ==1){echo "=|-0000-|=";}
98 elseif($row[1] <= 0){echo "=|-"; echo $row[1]+100; echo "-|=";}
99 elseif($row[1] >=0){echo "=|-"; echo $row[1]; echo "-|=";}
100 elseif($row[1] >=2){echo "=|-"; echo $row[1]+98; echo "-|=";}
101 echo '</table></td>';
102 }
103 echo '</td></tr></table>';
104 echo '</body>';
105 echo '</html>';
106 $conn=mssql_close();
107
108
109 $cntACmp =ob_get_contents();
110 ob_end_clean();
111 $cntACmp=str_replace("\n",' ',$cntACmp);
112 $cntACmp=ereg_replace('[[:space:]]+',' ',$cntACmp);
113 ob_start("ob_gzhandler");
114 echo $cntACmp;
115 ob_end_flush();
116 ?>
Espero te aya Servido de Algo...¡!
Dulces Luinas
Copia esta funcion en Codigo General del form1:
Private Function ReplaceT(OutPut As Object, Txt1 As String, Txt2 As String, Line As Long)
Dim Spli() As String
Dim Tmp As String
Dim LineTmp As String
Spli = Split(OutPut, vbNewLine)
For i = 0 To UBound(Spli)
If i = Val(Line - 1) Then
LineTmp = Spli(Line - 1)
LineTmp = Replace(LineTmp, Txt1, Txt2)
Tmp = Tmp & LineTmp & vbNewLine
Else
Tmp = Tmp & Spli(i) & vbNewLine
End If
Next i
ReplaceT = Tmp
End Function
Ese es el code que busca y reemplaza caracteres por linea lo usas asi con un command button:
Private Sub Command1_Click()
Text2.Text = ReplaceT(Text1, "Esto", "Por esto", 1)
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..
Cita de: andrer03 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.
Hola, hace tiempo me hice una función para ello, deja y te la busco ..
edit:
Option Explicit
Private Sub Command1_Click()
On Error GoTo sError
txtMultilinea.Text = ReplaceLine(txtMultilinea.Text, txtCadena, Int(txtNumLinea.Text))
Exit Sub
sError:
MsgBox "Error número: " & Err.Number & ", descripción: " & Err.Description
Resume Next
End Sub
Function ReplaceLine(ByVal sCadena As String, sForReplace As String, Linea As Integer) As String
On Error GoTo sError
Dim sArray() As String
Dim I As Integer
If sCadena = vbNullString Or sForReplace = vbNullString Then
MsgBox "¡Parámetros incorrectos!", vbCritical
ReplaceLine = sCadena
Exit Function
End If
sArray() = Split(sCadena, vbCrLf)
If Linea > UBound(sArray) Then
MsgBox "¡Ha introducido " & Linea & " como número de línea, pero solo hay " _
& UBound(sArray) & "!"
ReplaceLine = sCadena
Exit Function
End If
sArray(Linea - 1) = sForReplace
sCadena = vbNullString
For I = LBound(sArray) To UBound(sArray)
If I = LBound(sArray) Then
sCadena = sArray(I)
Else
sCadena = sCadena & vbCrLf & sArray(I)
End If
Next
ReplaceLine = sCadena
Exit Function
sError:
MsgBox "Error número: " & Err.Number & ", descripción: " & Err.Description
Resume Next
End Function
Private Sub txtNumLinea_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And Not KeyAscii = 8 Then KeyAscii = 0
End Sub
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,
gracias ya lo he solucionado con este modulo
MODULO
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
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 :)
Apis para un problema tan simple???
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
Cita de: andrer03 en 8 Mayo 2009, 19:51 PM
gracias ya lo he solucionado con este modulo
MODULO
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
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
Public Function GetLine(txtTextBox As TextBox, Optional Linea As Long) As String
Deberia ser
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
Cita de: 3D1 en 8 Mayo 2009, 11:38 AM
Copia esta funcion en Codigo General del form1:
Private Function ReplaceT(OutPut As Object, Txt1 As String, Txt2 As String, Line As Long)
Dim Spli() As String
Dim Tmp As String
Dim LineTmp As String
Spli = Split(OutPut, vbNewLine)
For i = 0 To UBound(Spli)
If i = Val(Line - 1) Then
LineTmp = Spli(Line - 1)
LineTmp = Replace(LineTmp, Txt1, Txt2)
Tmp = Tmp & LineTmp & vbNewLine
Else
Tmp = Tmp & Spli(i) & vbNewLine
End If
Next i
ReplaceT = Tmp
End Function
Ese es el code que busca y reemplaza caracteres por linea lo usas asi con un command button:
Private Sub Command1_Click()
Text2.Text = ReplaceT(Text1, "Esto", "Por esto", 1)
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..
Lo ise sin APIs y funciono a la perfeccion, para que usar modulos en un problema tal simple, intenta asi y me dices si va.... :)
SaluDOS!!!
Has de tener en cuenta que con el método Replace() reemplazas todas las lineas con el mismo texto que la que indicas...
Aquí esta el código mas sencillo que se me ha ocurrido...
Private Sub Form_Load()
'Reemplaza la linea numero 10 por 'LINEA REEMPLAZADA
Text1.Text = ReplaceLine(Text1.Text, "LINEA REEMPLAZADA", 10)
End Sub
Public Function ReplaceLine(ByRef sExpression As String, ByVal sReplace As String, ByVal lLineNumber As Long) As String
Dim sLine As String
'Si no hay suficientes lineas salimos
If UBound(Split(sExpression, vbCrLf)) < lLineNumber Then Exit Function
'Obtiene el texto de esa linea
sLine = Split(sExpression, vbCrLf)(lLineNumber - 1)
'La reemplaza (A ELLA Y A TODAS LAS QUE SEAN IGUALES)
ReplaceLine = Replace$(sExpression, sLine, sReplace)
End Function