PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 25 → WX - Função Picture(valor_numerico,valor_string_formatado)
WX - Função Picture(valor_numerico,valor_string_formatado)
Started by adrianoboller, Aug., 21 2015 7:55 PM - 7 replies
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 21 2015 - 7:55 PM
Procedure Picture(valor, formato)

NewFormat is string = ""

IF valor <> "" AND formato <> "" THEN

Pos01 is int = 0
Pos02 is int = 0
Total is int = Length(formato)

LOOP (Total)

Pos01 += 1

IF formato[[Pos01]] = 9 THEN
Pos02 += 1
NewFormat += Middle(valor,Pos02,1)
ELSE
NewFormat += Middle(formato,Pos01,1)
END

END

END

RESULT(NewFormat)
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 21 2015 - 8:00 PM
Exemplo de uso:

valor is string = Picture(123456789012345,"99.999.999/9999-99")

valor = 12.3456.789/0123-45


Ou

valor is string = Picture(12345678901,"999.999.999-99")

valor = 123.456.789-01


Ou

valor is string = Picture(1234567890,"(99)9999 99999")

valor = (12) 3456 7890
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 24 2015 - 4:09 PM
Procedure NoPicture(valor)

NewFormat is string = ""

NewFormat = Replace(valor,"/","")
NewFormat = Replace(valor,"\","")
NewFormat = Replace(valor,".","")
NewFormat = Replace(valor,",","")
NewFormat = Replace(valor,";","")
NewFormat = Replace(valor,":","")
NewFormat = Replace(valor,"_","")
NewFormat = Replace(valor,"-","")
NewFormat = Replace(valor,"+","")

RESULT(NewFormat)
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 24 2015 - 4:09 PM
:merci:
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 24 2015 - 4:12 PM
Procedure NoPicture(valor)

NewFormat is string = valor

NewFormat = Replace(NewFormat,"(","")
NewFormat = Replace(NewFormat,")","")
NewFormat = Replace(NewFormat,"[","")
NewFormat = Replace(NewFormat,"]","")
NewFormat = Replace(NewFormat,"{","")
NewFormat = Replace(NewFormat,"}","")
NewFormat = Replace(NewFormat,"/","")
NewFormat = Replace(NewFormat,"\","")
NewFormat = Replace(NewFormat,".","")
NewFormat = Replace(NewFormat,",","")
NewFormat = Replace(NewFormat,";","")
NewFormat = Replace(NewFormat,":","")
NewFormat = Replace(NewFormat,"_","")
NewFormat = Replace(NewFormat,"-","")
NewFormat = Replace(NewFormat,"+","")
NewFormat = Replace(NewFormat," ","")
NewFormat = Replace(NewFormat," ","")
NewFormat = NoSpace(NewFormat)
NewFormat = NoAccent(NewFormat)

RESULT(NewFormat)
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 24 2015 - 6:43 PM
Nova Versão
Procedure Picture(valor, formato)

Tamanho is int = Length(formato)
Zeros, NewFormat is string = ""

IF valor <> "" AND formato <> "" AND Length(valor) < Length(formato) AND PositionOccurrence(formato,"0",firstRank,FromBeginning) > 0 THEN

NewFormat = NumToString(valor, "0"+Tamanho+".0f")

ELSE IF valor <> "" AND formato <> "" AND PositionOccurrence(formato,"0",firstRank,FromBeginning) = 0

//Completa com zeros no caso de cpf ou cnpj que inicia com zero
IF Length(valor) < Length(formato) THEN
Diferenca is int = Length(formato) - Length(valor)
LOOP (Diferenca)
Zeros += "0"
END
valor = Zeros + valor
END

Pos01 is int = 0
Pos02 is int = 0
Total is int = Length(formato)

LOOP (Total)

Pos01 += 1

IF formato[[Pos01]] = 9 THEN
Pos02 += 1
NewFormat += Middle(valor,Pos02,1)
ELSE
NewFormat += Middle(formato,Pos01,1)
END

END

END

RESULT(NewFormat)
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 24 2015 - 6:57 PM
Alguns Ajustes finos - Versao Final

Procedure Picture(valor is string, formato is string)

NewValor is int = Val(valor)
Tamanho is int = Length(formato)
Zeros, NewFormat is string = ""

IF valor <> "" AND formato <> "" AND Length(valor) < Length(formato) AND PositionOccurrence(formato,"0",firstRank,FromBeginning) > 0 THEN

NewFormat = NumToString(NewValor, "0"+Tamanho+".0f")

ELSE IF valor <> "" AND formato <> "" AND PositionOccurrence(formato,"0",firstRank,FromBeginning) = 0

//Completa com zeros no caso de cpf ou cnpj que inicia com zero
IF Length(valor) < Length(NoPicture(formato)) THEN
Diferenca is int = Length(NoPicture(formato)) - Length(valor)
LOOP (Diferenca)
Zeros += "0"
END
valor = Zeros +""+ valor
END

Pos01 is int = 0
Pos02 is int = 0
Total is int = Length(formato)

LOOP (Total)

Pos01 += 1

IF formato[[Pos01]] = 9 THEN
Pos02 += 1
NewFormat += Middle(valor,Pos02,1)
ELSE
NewFormat += Middle(formato,Pos01,1)
END

END

END

RESULT(NewFormat)
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on August, 24 2015 - 6:58 PM
Exemplo de Uso
sNValor01 is string = Picture(1,"000000")
sNValor01 = "000001"

sNValor02 is string = Picture(1234567890,"999.999.999-99")
sNValor02 = "012.345.678-90"