Título: my.resources.source.replace(variable, variable) Ayuda codedom Publicado por: 70N1 en 18 Octubre 2011, 12:56 pm Lo que quiero es pasar una variable temporal a my.resource.source
Me explico bien? Espero buestra ayuda algo como: button1_click Código: dim cadena as string = "toni" my.resources.source.replace("%1%", cadena) my.resources.source.txt Código: dim toni as string = %1% Me tira error. no reconoce el caracter.... no se. Título: Re: my.resources.source.replace(variable, variable) Ayuda, reemplazar variable Publicado por: Keyen Night en 18 Octubre 2011, 16:11 pm My.Resources.Source es String?
Replace es una intrucción que devuelve el reemplazo no que lo ejecuta. Por ejemplo: Código
Pero si lo hacemos así, no pasa nada: Código
En tal caso sería: Código
Lo que hace el código es bucar el texto %1% y remplazarlo por el valor de la variable cadena ("toni") y luego lo guarda en la variable toni. Título: Re: my.resources.source.replace(variable, variable) Ayuda, reemplazar variable Publicado por: 70N1 en 18 Octubre 2011, 17:50 pm Código: Dim cadena1 As String = my.resources.source1 cadena1 = My.Resources.source1.Replace("cadena", cadena.ToString) En cadena.tostring ahi un exe en formato ascii y me tira errores de carateres no validos en la depuracion. Si puedes ayudar se te agradeceria. Porsierto, muchas gracias por tu explicacion, es algo que no savia. Esta es la llamada a la funcion para crear el exe Código: CompileCode(New Microsoft.VisualBasic.VBCodeProvider(), _VBSourceCode, Nothing, SaveFileDialog1.FileName, Nothing, Nothing, _Errors) Y esta es la funcion para generar el ejecutable Código: Public Function CompileCode(ByVal _CodeProvider As System.CodeDom.Compiler.CodeDomProvider, ByVal _SourceCode As String, ByVal _SourceFile As String, ByVal _ExeFile As String, ByVal _AssemblyName As String, ByVal _ResourceFiles() As String, ByRef _Errors As String) As Boolean ' set interface for compilation Dim _CodeCompiler As System.CodeDom.Compiler.ICodeCompiler = _CodeProvider.CreateCompiler() ' Define parameters to invoke a compiler Dim _CompilerParameters As New System.CodeDom.Compiler.CompilerParameters() If _ExeFile IsNot Nothing Then ' Set the assembly file name to generate. _CompilerParameters.OutputAssembly = _ExeFile ' Generate an executable instead of a class library. _CompilerParameters.GenerateExecutable = True _CompilerParameters.GenerateInMemory = False ElseIf _AssemblyName IsNot Nothing Then ' Set the assembly file name to generate. _CompilerParameters.OutputAssembly = _AssemblyName ' Generate an executable instead of a class library. _CompilerParameters.GenerateExecutable = False _CompilerParameters.GenerateInMemory = False Else ' Generate an executable instead of a class library. _CompilerParameters.GenerateExecutable = False _CompilerParameters.GenerateInMemory = True End If ' Generate debug information. '_CompilerParameters.IncludeDebugInformation = true; ' Set the level at which the compiler ' should start displaying warnings. _CompilerParameters.WarningLevel = 3 ' Set whether to treat all warnings as errors. _CompilerParameters.TreatWarningsAsErrors = False ' Set compiler argument to optimize output. _CompilerParameters.CompilerOptions = "/optimize" ' Set a temporary files collection. ' The TempFileCollection stores the temporary files ' generated during a build in the current directory, ' and does not delete them after compilation. _CompilerParameters.TempFiles = New System.CodeDom.Compiler.TempFileCollection(".", True) If _ResourceFiles IsNot Nothing AndAlso _ResourceFiles.Length > 0 Then For Each _ResourceFile As String In _ResourceFiles ' Set the embedded resource file of the assembly. _CompilerParameters.EmbeddedResources.Add(_ResourceFile) Next _ResourceFile End If Try ' Invoke compilation Dim _CompilerResults As System.CodeDom.Compiler.CompilerResults = Nothing If _SourceFile IsNot Nothing AndAlso System.IO.File.Exists(_SourceFile) Then ' soruce code in external file _CompilerResults = _CodeCompiler.CompileAssemblyFromFile(_CompilerParameters, _SourceFile) Else ' source code pass as a string _CompilerResults = _CodeCompiler.CompileAssemblyFromSource(_CompilerParameters, _SourceCode) End If If _CompilerResults.Errors.Count > 0 Then ' Return compilation errors _Errors = "" : For Each CompErr As System.CodeDom.Compiler.CompilerError In _CompilerResults.Errors _Errors &= "Line number " & CompErr.Line & ", Error Number: " & CompErr.ErrorNumber & ", '" & CompErr.ErrorText & ";" & Constants.vbCrLf & Constants.vbCrLf Next CompErr ' Return the results of compilation - Failed Return False Else ' no compile errors _Errors = Nothing End If Catch _Exception As Exception ' Error occurred when trying to compile the code _Errors = _Exception.Message Return False End Try ' Return the results of compilation - Success Return True End Function Título: Re: my.resources.source.replace(variable, variable) Ayuda codedom Publicado por: Keyen Night en 19 Octubre 2011, 06:22 am Este problema es más común de lo que piensas, los Resources se guardan de 2 formas básicas para no entrar en detalles, en array de Bytes y en String, el problema común es creer que los resources como ejecutables, imagenes, etc; se guardan a forma de String cuando estos son realmentes Array de Bytes, otra cosa que suele pasar es aplicar .ToString creyendo que vamos a pasar los Bytes a String.
Ahora vamos con tu error concretamente, si My.Resources.Source1 es un ejecutable en resources, osea un Array de Bytes, y quieres reemplazar una palabra o cadena en especifico, debes pasar el resource a String cuidando el Encoding, reemplazar el texto y devolverlo a Array Bytes algo parecido a esto: Código
Claro hay está todo en una línea. Título: Re: my.resources.source.replace(variable, variable) Ayuda codedom Publicado por: 70N1 en 19 Octubre 2011, 12:57 pm Al final el problema era que tenia que cortar el string en lineas y ponerle al final de cada linea la ( _ varra baja) y encapsularlo con chr(34) que es en ascii ( " las comillas)
Muchas gracias por la voluntad. Código: dim cadena as string = "exe en base64string" my.resources.source.replace("%1%", formato(cadena)) function formato splitstring tal cual pin pan. |