Jump to content

Separ números recebidos da serial


Recommended Posts

Boa noite!

Estou utilizando vb6 em uma aplicação recebendo dados da serial,os dados estáo recebendo pelo text1.text o  seguinte formato:

0,140,450,780,890,560,450,560,250,410,780,620,950,260,150,490,150,460,29

E preciso separar e mostrar no text2.text apenas no formato 0,14.

agradecido

Link to post
Share on other sites
miglaranjeira

Bom dia,

Para duas casas decimais:

Int ( numero_a_truncar* 100 ) / 100

Exemplo

int(0,140*100)/100=0,14

 

Se o tratamento é apenas da string no text1.text, colaca os nºs numa listbox

Dim aux As String
Dim pos, nVirg As Integer

Do
    aux = ""
    pos = 1
    nVirg = 0
    
    If Len(Text1.Text) >= 5 Then
    
        Do
            aux = aux + Mid(Text1.Text, pos, 1)
    
            If Mid(aux, pos, 1) = "," Then nVirg = nVirg + 1
            pos = pos + 1
        Loop Until nVirg = 2
    
            Text1.Text = Mid(Text1.Text, pos - 2, Len(Text1.Text))
            aux = Mid(aux, 1, Len(aux) - 2)
    
            List1.AddItem (aux)
    Else
        List1.AddItem (Text1.Text)
        Exit Do
    End If
    
Loop 

Um abraço

 

Edited by miglaranjeira
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.