Buscar un caracter dentro de una cadena
Hola estoy haciendo una peque帽a aplicaci贸n para pasar los datos de un fichero de texto plano a una base de datos sql server. Bien tengo un campo (telefono) que en la base de datos es de tipo entero y en el fichero de texto es de tipo caracter. Al recoger los datos como tiene nueve posiciones entran perfectamente sin dar ning煤n tipo de error, pero el problema biene cuando se en cuentra con un cararacter en blanco entre medias del n煤mero.la pregunta es ¿como puedo detectar que hay un espacio?, cuando lo detecte en el caso de que haya un blanco el campo lo cambio de valor y lo inserto como 0.
Aqui pongo una muestra de lo que llevo hecho
telefono = Trim$(Mid$(texto$, 181, 9))
If ((InStr(CStr(telefono), "") <> 0)) Then
telefono = 0
ElseIf ((Len(CStr(telefono)) <> 9) Or telefono = "") Then
telefono = 0
RsODBC("alojamientos_tlf") = telefono
Else
RsODBC("alojamientos_tlf") = telefono
End If
Por favor necesito ayuda urgentemente. Gracias de antemano
Aqui pongo una muestra de lo que llevo hecho
telefono = Trim$(Mid$(texto$, 181, 9))
If ((InStr(CStr(telefono), "") <> 0)) Then
telefono = 0
ElseIf ((Len(CStr(telefono)) <> 9) Or telefono = "") Then
telefono = 0
RsODBC("alojamientos_tlf") = telefono
Else
RsODBC("alojamientos_tlf") = telefono
End If
Por favor necesito ayuda urgentemente. Gracias de antemano
Dim Telefono as string
Telefono=trim(mid(Texto,181,9))
if instr(telefono," ")>0 then Telefono="0"
RsODBC("alojamientos_tlf")=val(Telefono)
Telefono=trim(mid(Texto,181,9))
if instr(telefono," ")>0 then Telefono="0"
RsODBC("alojamientos_tlf")=val(Telefono)
Muchisimas gracias por tu ayuda, funciona perfectamente me has salvado el d铆a
Hola Oscar
Aqui te mando este codigo que espero que te sirva,suerte
Private Sub Command1_Click()
Dim a As String
a = Text1.Text
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = " " Then
Mid(a, i, 1) = 0
End If
Next i
Text1.Text = a
End Sub
Saludos
Aqui te mando este codigo que espero que te sirva,suerte
Private Sub Command1_Click()
Dim a As String
a = Text1.Text
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = " " Then
Mid(a, i, 1) = 0
End If
Next i
Text1.Text = a
End Sub
Saludos
No se si es lo que quieres exactamente, pero este c贸digo elimina de cualquier string los espacios en blanco, para eso necesito crear un objeto TextBox para aprovechar sus metodos.
En el option explicit pones:
Public WithEvents tlf As TextBox
y donde quieras :
Set tlf = Controls.Add("VB.TextBox", "tlf")
Dim Search
Dim Where As Integer
dtxt = " "
tlf.Text = " 988 9098 98 "
Search = dtxt
Where = InStr(tlf, Search)
If Where >= 1 Then
While Where <> 0
tlf.SelStart = Where - 1
tlf.SelLength = Len(Search)
tlf.SelText = ""
Where = InStr(tlf, Search)
Wend
mm = MsgBox("" & tlf.Text & "")
End If
En este ejemplo se eliminan todos los espacios de tlf.
Espero que te oriente.
En el option explicit pones:
Public WithEvents tlf As TextBox
y donde quieras :
Set tlf = Controls.Add("VB.TextBox", "tlf")
Dim Search
Dim Where As Integer
dtxt = " "
tlf.Text = " 988 9098 98 "
Search = dtxt
Where = InStr(tlf, Search)
If Where >= 1 Then
While Where <> 0
tlf.SelStart = Where - 1
tlf.SelLength = Len(Search)
tlf.SelText = ""
Where = InStr(tlf, Search)
Wend
mm = MsgBox("" & tlf.Text & "")
End If
En este ejemplo se eliminan todos los espacios de tlf.
Espero que te oriente.
