administration Posted April 16, 2014 Report Posted April 16, 2014 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 SubHandler: MsgBox Error$ Resume NextEnd Sub Quote
Active Members dancezar Posted April 16, 2014 Active Members Report Posted April 16, 2014 Text1.text=Mid(Text1.text, 4, Len(Text1.text))Mid String,start,lengthString ->stringul care il modificastart -> caracterul de la care sa porneasca (numerotarea se face de la 1)length -> cate caractere sa cuprinda Quote
administration Posted April 17, 2014 Author Report Posted April 17, 2014 Text1.text=Mid(Text1.text, 4, Len(Text1.text))Mid String,start,lengthString ->stringul care il modificastart -> caracterul de la care sa porneasca (numerotarea se face de la 1)length -> cate caractere sa cuprindavezi 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... Quote
administration Posted April 17, 2014 Author Report Posted April 17, 2014 Ce conflict primesti? Ce zice eroarea?video cu eroarehttp://www.speedyshare.com/cCgps/Untitled44.mp4cod sursahttp://speedy.sh/NuFmr/Download.zip Quote
Active Members dancezar Posted April 17, 2014 Active Members Report Posted April 17, 2014 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 asaText1.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 asaText1.text=Text1.text & Mid(Text1.text, 5, Len(Text1.text))O alta solutie :s=split(text,"DEC:")text1.text=text1.text & s[1] Quote
administration Posted April 19, 2014 Author Report Posted April 19, 2014 (edited) Pai daca vrei ca sa iti adauge la sfarsitul text boxului bagi asaO alta solutie :s=split(text,"DEC:")text1.text=text1.text & s[1]prima solutie nu merge :http://s7.postimg.org/k6m63d1yz/vb1.pnga doua cum declar "s"?Dim s As String ? Edited April 19, 2014 by administration Quote
Wav3 Posted April 20, 2014 Report Posted April 20, 2014 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]) Quote