Título: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 11:58 am Agradezco de antemano si alguien me puede ayudar con esto ^^ parece fácil para alguien que ande en esto.
Supongamos que tengo la variable: Código: X=123456789 y quiero restarle 3 caracteres para que quede: Código: X=123456 no me interesa limitar la cantidad de caracteres, esa variable va a ser siempre de distinta longitud, puede que a veces sean 6 caracteres, a veces 8, etc... Gracias!!! ;-) Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: Novlucker en 10 Diciembre 2010, 12:03 pm Len (http://msdn.microsoft.com/es-es/library/dxsw58z6%28v=vs.80%29.aspx), Right (http://msdn.microsoft.com/es-es/library/dxs6hz0a%28v=vs.80%29.aspx), Left (http://msdn.microsoft.com/es-es/library/y050k1wb%28v=vs.80%29.aspx) y Mid (http://msdn.microsoft.com/es-es/library/05e63829%28v=vs.80%29.aspx)
Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 12:04 pm Graciasssss, ahí pruebo :)
Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: 79137913 en 10 Diciembre 2010, 12:17 pm HOLA!!!
Código
GRACIAS POR LEER!!! Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 12:32 pm HOLA!!! Código
GRACIAS POR LEER!!! Uhhh, es como que me contaste el final de LOST antes de verlo más o menos. jajajaj, gracias! Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: 79137913 en 10 Diciembre 2010, 12:38 pm HOLA!!!
No hay problema, perdon si querias llegar vos solo a verlo :P. IGUAL... ¬¬ EL FINAL DE LOST DEJA MUCHO QUE DESEAR... TODO MAL CON LOS AUTORES. GRACIAS POR LEER!!! Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 13:39 pm Si, yo me quedé desilusionado, la luz en la cueva, la huevada del bien y el mal y los cuidadores de la isla, yo esperaba algo que me atara todos los cabos, y nunca los ataron, incluso me quedé con la intriga de porqué los osos polares en la isla y porqué la revista con el oso polar, eso tendría q haber tenido un significado... luego sacaron 10-15 minutos que nunca habían mostrado, donde explican lo de los osos (lamentable).
Tengo otro problema, y acá si me gustaría que me pongan el código entero porque me voy a volver loco sino. Necesito leer el valor de una key del registro de windows y mostrarla en un msgbox. Me está volviendo loco :$ Gracias de antemano ^^ Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: Novlucker en 10 Diciembre 2010, 13:47 pm Modificar regedit usando visual basic (http://foro.elhacker.net/programacion_visual_basic/modificar_regedit_usando_visual_basic-t245654.0.html)
Manejo basico del registro. (http://foro.elhacker.net/programacion_vb/manejo_basico_del_registro-t20569.0.html) Leer clave de registro con wscript.shell (http://foro.elhacker.net/programacion_vb/leer_clave_de_registro_con_wscriptshell-t291672.0.html) Jugando con el registro de Windows (http://foro.elhacker.net/programacion_visual_basic/jugando_con_el_registro_de_windows-t256688.0.html) Pregunta relacionada con registro de WINDOWS (http://foro.elhacker.net/programacion_visual_basic/pregunta_relacionada_con_registro_de_windows-t256750.0.html) ... Y así puedo seguir, repite conmigo, "no volveré a preguntar sin usar el buscador" :silbar: Saludos Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: raul338 en 10 Diciembre 2010, 13:49 pm INICIO DE APLICACIÓN CON WINDOWS - Leandro Ascierto (http://www.leandroascierto.com.ar/categoria/M%C3%B3dulos/articulo/Inicio%20Aplicaci%C3%B3n%20con%20Windows.php)
El que busca encuentra, miralo, modificalo, toquetealo (?) y APRENDE a tu gusto :P Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 14:02 pm Seré medio bolúdo pero con ese código estoy peor que con el que tenía :S
Ese código es para modificar cierto valor en el registro, pero no veo en que parte toma el valor de la key :-[ Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: raul338 en 10 Diciembre 2010, 14:29 pm Haber.... expliquemos.... para obtener un valor, te pase la siguiente funcion en un link
Código
Vamos por partes (dijo jack el destripador) Se declaran e inicalizan las variables Código Ahi decimos a windows que nos "abra" una "conexion" al registro, en HKEY_CURRENT_USE (en la parte de arriba estan las constantes para las demas ramas), despues le pasamos la ruta de lo que queramos obtener (RAMA_RUN_WINDOWS tambien esta declarado arriba), despues KEY_ALL_ACCESS se explica a si mismo :xD y por ultimo la API guarda el numero de conexion en Handle (es importante esa variable, no debe cambiar hasta que se cierre la conexion, no es bueno dejar cosas abiertas a medida que se ejecuta el programa Código En esta linea vemos si esta vacia la entrada App.Title (puede ser cualquier nombre, pero es el nombre de la clave que queremos obtener) y si no lo esta, devuelve la longitud del valor de la clave App.Title. Como antes, el resultado se guarda en cch (te preguntaras porque lo guarda ahi y no lo devuelve la funcion? Si, es medio lioso la API de windows cuando apenas entra. Lo hace porque la funcion devuelve un codigo de error o si todo esta bien, cosa que si la funcion devolviera FALSO por ejemplo, no sabrias si no existe o si existe o tiene contenido, o si el windows no te dio permiso para comprobar si existe, etc) Compruebas si cch es mayor que 0, por lo tanto EXISTE y pasamos a obtener el valor con Código que le pasamos el numero de conexion, el nombre de la cadena, y un string vacio (de longitud "cch") Y listo, tienes el valor de la cadena que buscas!!! Y por ultimo cierras la cadena con RegCloseHandle :) Espero que te sirva :) Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 14:33 pm A ver si tengo bien el concepto, voy a basarme en en el ejemplo de api guide.
Primero las declaraciones y funciones: Código: Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long 'retrieve nformation about the key lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize) If lResult = 0 Then If lValueType = REG_SZ Then 'Create a buffer strBuf = String(lDataBufSize, Chr$(0)) 'retrieve the key's content lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize) If lResult = 0 Then 'Remove the unnecessary chr$(0)'s RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1) End If ElseIf lValueType = REG_BINARY Then Dim strData As Integer 'retrieve the key's value lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize) If lResult = 0 Then RegQueryStringValue = strData End If End If End If End Function Function GetString(hKey As Long, strPath As String, strValue As String) Dim Ret 'Open the key RegOpenKey hKey, strPath, Ret 'Get the key's content GetString = RegQueryStringValue(Ret, strValue) 'Close the key RegCloseKey Ret End Function Ahora un boton que tome el valor y lo muestre en un msg box: Código: Private Sub Command1_Click() 'Get a string from the registry Ret = GetString(HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Programa", "BinaryValue") If Ret = "" Then MsgBox "No value found !", vbExclamation + vbOKOnly, App.Title: Exit Sub MsgBox "The value is " + Ret, vbOKOnly + vbInformation, App.Title End Sub Que estoy haciendo mal? :/ Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 14:37 pm Ahi intento, repondi sin haber leido tu respuesta >:E
Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 15:22 pm Jeje, te agradezco el intento de explicarme, pero me estoy mareando más aún con ese código... :rolleyes:
Hago una pregunta más concreta usando el ejemplo de API-GUIDE que se me hace más fácil de entender. Código: 'This program needs 3 buttons Const REG_SZ = 1 ' Unicode nul terminated string Const REG_BINARY = 3 ' Free form binary Const HKEY_CURRENT_USER = &H80000001 Const HKEY_LOCAL_MACHINE = &H80000002 Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long 'retrieve nformation about the key lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize) If lResult = 0 Then If lValueType = REG_SZ Then 'Create a buffer strBuf = String(lDataBufSize, Chr$(0)) 'retrieve the key's content lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize) If lResult = 0 Then 'Remove the unnecessary chr$(0)'s RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1) End If ElseIf lValueType = REG_BINARY Then Dim strData As Integer 'retrieve the key's value lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize) If lResult = 0 Then RegQueryStringValue = strData End If End If End If End Function Function GetString(hKey As Long, strPath As String, strValue As String) Dim Ret 'Open the key RegOpenKey hKey, strPath, Ret 'Get the key's content GetString = RegQueryStringValue(Ret, strValue) 'Close the key RegCloseKey Ret End Function Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String) Dim Ret 'Create a new key RegCreateKey hKey, strPath, Ret 'Save a string to the key RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData) 'close the key RegCloseKey Ret End Sub Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String) Dim Ret 'Create a new key RegCreateKey hKey, strPath, Ret 'Set the key's value RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4 'close the key RegCloseKey Ret End Sub Sub DelSetting(hKey As Long, strPath As String, strValue As String) Dim Ret 'Create a new key RegCreateKey hKey, strPath, Ret 'Delete the key's value RegDeleteValue Ret, strValue 'close the key RegCloseKey Ret End Sub Private Sub Command1_Click() Dim strString As String 'Ask for a value strString = InputBox("Please enter a value between 0 and 255 to be saved as a binary value in the registry.", App.Title) If strString = "" Or Val(strString) > 255 Or Val(strString) < 0 Then MsgBox "Invalid value entered ...", vbExclamation + vbOKOnly, App.Title Exit Sub End If 'Save the value to the registry SaveStringLong HKEY_CURRENT_USER, "KPD-Team", "BinaryValue", CByte(strString) End Sub Private Sub Command2_Click() 'Get a string from the registry Ret = GetString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NMap", "BinaryValue") If Ret = "" Then MsgBox "No value found !", vbExclamation + vbOKOnly, App.Title: Exit Sub MsgBox "The value is " + Ret, vbOKOnly + vbInformation, App.Title End Sub Private Sub Command3_Click() 'Delete the setting from the registry DelSetting HKEY_CURRENT_USER, "KPD-Team", "BinaryValue" MsgBox "The value was deleted ...", vbInformation + vbOKOnly, App.Title End Sub Private Sub Form_Load() 'KPD-Team 1998 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net Command1.Caption = "Set Value" Command2.Caption = "Get Value" Command3.Caption = "Delete Value" End Sub No le des importancia al código que no necesito, es sacar los botones y declaraciones que no uso... el objetivo es que el botón 2 me devuelva el valor del registro que quiero. Supongamos que esta es la ruta: (http://img262.imageshack.us/img262/5936/65785482.jpg) Y que esta es la key que quiero ver el valor: (http://img146.imageshack.us/img146/7412/55685519.jpg) La pregunta es... ¿donde pongo el "DisplayName"? y ¿porqué me sigue diciendo "No value found!" cuando la ruta es la correcta? :/ Disculpen si molesto con tanta pregunta, pero realmente quiero comprender que es lo que estoy haciendo y como hacerlo. Título: Re: Restar X cantidad de caracteres al valor de una variable Publicado por: extreme69 en 10 Diciembre 2010, 15:32 pm ahhh, me pasé de newbie :E
ya lo hice xD Gracias a todos !!! unos genios como siempre! |