Jump to content
administration

vb6 eliminare primele 3 caractere din txtbox

Recommended Posts

Posted

Am urmatorul cod de mai jos care imi filtreaza imput-ul provenit de la portul COM si care este de forma XXX 123.

Cum fac sa elimin primele trei litere XXX sa imi afiseze doar cifrele?

' This procedure adds data to the Term control's Text property.
' It also filters control characters, such as BACKSPACE,
' carriage return, and line feeds, and writes data to
' an open log file.
' BACKSPACE characters delete the character to the left,
' either in the Text property, or the passed string.
' Line feed characters are appended to all carriage
' returns. The size of the Term control's Text
' property is also monitored so that it never
' exceeds MAXTERMSIZE characters.
Private Static Sub ShowData(Term As Control, Data As String)
On Error GoTo Handler
Const MAXTERMSIZE = 16000
Dim TermSize As Long, i

' Make sure the existing text doesn't get too large.
TermSize = Len(Term.Text)
If TermSize > MAXTERMSIZE Then
Term.Text = Mid$(Term.Text, 4097)
TermSize = Len(Term.Text)
End If

' Point to the end of Term's data.
Term.SelStart = TermSize

' Filter/handle BACKSPACE characters.
Do
i = InStr(Data, Chr$(8))
If i Then
If i = 1 Then
Term.SelStart = TermSize - 1
Term.SelLength = 1
Data = Mid$(Data, i + 1)
Else
Data = Left$(Data, i - 2) & Mid$(Data, i + 1)
End If
End If
Loop While i

' Eliminate line feeds.
Do
i = InStr(Data, Chr$(10))
If i Then
Data = Left$(Data, i - 2) & Mid$(Data, i + 1)
End If
Loop While i

' Make sure all carriage returns have a line feed.
i = 1
Do
i = InStr(i, Data, Chr$(13))
If i Then
Data = Left$(Data, i) & Chr$(10) & Mid$(Data, i + 1)
i = i + 1
End If
Loop While i

' Add the filtered data to the SelText property.
Term.SelText = Data

' Log data to file if requested.
If hLogFile Then
i = 2
Do
Err = 0
Put hLogFile, , Data
If Err Then
i = MsgBox(Error$, 21)
If i = 2 Then
mnuCloseLog_Click
End If
End If
Loop While i <> 2
End If
Term.SelStart = Len(Term.Text)
Exit Sub

Handler:
MsgBox Error$
Resume Next
End Sub

  • Active Members
Posted


Text1.text=Mid(Text1.text, 4, Len(Text1.text))

Mid String,start,length

String ->stringul care il modifica

start -> caracterul de la care sa porneasca (numerotarea se face de la 1)

length -> cate caractere sa cuprinda

Posted

Text1.text=Mid(Text1.text, 4, Len(Text1.text))

Mid String,start,length

String ->stringul care il modifica

start -> caracterul de la care sa porneasca (numerotarea se face de la 1)

length -> cate caractere sa cuprinda

vezi ca sunt niste rectificari de linii acolo care dau conflict cu ce ai scris tu nu merge cu mid...am incercat si nu pot pune if xxx notnumeric then... poate doar sa elimin ceva o sa pun codul complet dar nu cred ca ai iput pe COM...

  • Active Members
Posted
vezi ca sunt niste rectificari de linii acolo care dau conflict cu ce ai scris tu nu merge cu mid...am incercat si nu pot pune if xxx notnumeric then... poate doar sa elimin ceva o sa pun codul complet dar nu cred ca ai iput pe COM...

Pai daca vrei ca sa iti adauge la sfarsitul text boxului bagi asa

Text1.text=Text1.text & Mid(Text1.text, 4, Len(Text1.text))

Am vazut ca stringul tau este DEC:

in cazul asta ca sa il ia si pe : bagi asa

Text1.text=Text1.text & Mid(Text1.text, 5, Len(Text1.text))

O alta solutie :

s=split(text,"DEC:")

text1.text=text1.text & s[1]

Posted

Da, ca String trebuie declarat. Ma indoiesc ca stii ce ai in acel cod sursa (pentru ca nu e al tau) si asta ma face sa cred ca nu ai pus unde trebuie ceea ce ti-a recomandat colegu' de mai sus. Nu m-am uitat prin codul sursa complet, dar cred ca acel Mid trebuia sa-l pui la fiecare linie din text, nu dupa ce se aduna toate.

Dim s() As String si s(x) (nu s[x])

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...