CONST, ARRAY
Aew pessoal....
Tipow... como que eu declaro uma constante de array em inteiros e string???
Se alguem poder me ajudar fico muito grato!
Tipow... como que eu declaro uma constante de array em inteiros e string???
Se alguem poder me ajudar fico muito grato!
Não tem como declarar uma constante de array
Poderia me dizer o que tu queria para entender melhor
Poderia me dizer o que tu queria para entender melhor
Coloque o teu código em DELPHI que converto para Ti
Function DECTOROMAN(DECIMAL as LONG) as string
Dim TArray AS VARIANT,TArabics AS VARIANT
TArray = split(",I,IV,V,IX,X,XL,L,XC,C,CD,D,CM,M",",")
TArabics = SPLIT(",1,4,5,9,10,40,50,90,100,400,500,900,1000",",")
DIM S AS STRING
S = TRIM(STR(DECIMAL))
DIM I AS INTEGER
FOR I= 1 TO 13
IF TArabics(I) = DECIMAL THEN
DECTOROMAN = TArabics(I)
EXIT FUNCTION
END IF
NEXT
END FUNCTION
Dim TArray AS VARIANT,TArabics AS VARIANT
TArray = split(",I,IV,V,IX,X,XL,L,XC,C,CD,D,CM,M",",")
TArabics = SPLIT(",1,4,5,9,10,40,50,90,100,400,500,900,1000",",")
DIM S AS STRING
S = TRIM(STR(DECIMAL))
DIM I AS INTEGER
FOR I= 1 TO 13
IF TArabics(I) = DECIMAL THEN
DECTOROMAN = TArabics(I)
EXIT FUNCTION
END IF
NEXT
END FUNCTION
• Choice - Expressão Variant contendo uma das possÃveis escolhas.
Exemplo:
Teste = Escolha(2)
Function Escolha(Indice As Integer)
Escolha = Choose(Indice, "Valor1", "Valor2", "Valor3")
End Function
vAI RETORNAR A SEGUNDA OPÇÃO
Exemplo:
Teste = Escolha(2)
Function Escolha(Indice As Integer)
Escolha = Choose(Indice, "Valor1", "Valor2", "Valor3")
End Function
vAI RETORNAR A SEGUNDA OPÇÃO
nO TEU CODIGO valoresromanos E valoresarabianos DEVEM SER variant
Function DECTOROMAN(Num As Integer) As String
Dim ValoresRomanos As VARIANT
Dim ValoresArabians As VARIANT
ValoresRomanos =
Array("I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M")
ValoresArabians = Array(1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000)
Dim S As String
Dim I As Integer
For I = 1 To 13 Step -1
Do While (Num = ValoresArabians(I))
Num = Num + ValoresArabians(I)
S = S + ValoresRomanos(I)
Loop
Exit Function
Next
MsgBox (S)
End Function
Function DECTOROMAN(Num As Integer) As String
Dim ValoresRomanos As VARIANT
Dim ValoresArabians As VARIANT
ValoresRomanos =
Array("I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M")
ValoresArabians = Array(1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000)
Dim S As String
Dim I As Integer
For I = 1 To 13 Step -1
Do While (Num = ValoresArabians(I))
Num = Num + ValoresArabians(I)
S = S + ValoresRomanos(I)
Loop
Exit Function
Next
MsgBox (S)
End Function
e AI JOSE é O SEGUINTE O DONATELO ME PASSOU POR EMAIL O CÓ“DIGO ACIMA E AO INVEZ DE DECLARAR COMO VARIANT AS VARIAVEIS ELE COLOCOU COMO STRING E LONG E COLOQUEI APENAS PARA CORRIGIR A PARTE ACIMA O CÓ“DIGO QUE EU POSTEI FOI OUTRO QUE ELE NÃO USOU QUE SERIA O QUE ESTà  ABAIXO
Function DECTOROMAN(DECIMAL as LONG) as string
Dim TArray AS VARIANT,TArabics AS VARIANT
TArray = split(",I,IV,V,IX,X,XL,L,XC,C,CD,D,CM,M",",")
TArabics = SPLIT(",1,4,5,9,10,40,50,90,100,400,500,900,1000",",")
DIM S AS STRING
S = TRIM(STR(DECIMAL))
DIM I AS INTEGER
FOR I= 1 TO 13
IF TArabics(I) = DECIMAL THEN
DECTOROMAN = TArabics(I)
EXIT FUNCTION
END IF
NEXT
END FUNCTION
Function DECTOROMAN(DECIMAL as LONG) as string
Dim TArray AS VARIANT,TArabics AS VARIANT
TArray = split(",I,IV,V,IX,X,XL,L,XC,C,CD,D,CM,M",",")
TArabics = SPLIT(",1,4,5,9,10,40,50,90,100,400,500,900,1000",",")
DIM S AS STRING
S = TRIM(STR(DECIMAL))
DIM I AS INTEGER
FOR I= 1 TO 13
IF TArabics(I) = DECIMAL THEN
DECTOROMAN = TArabics(I)
EXIT FUNCTION
END IF
NEXT
END FUNCTION
Faça o meu código de exemplo que comigo está funcionando
Decidi colocar duas funções que tenho guardado converte de romano para decimal e vice-versa
'*********************************
Function romtodec(roman As String) As Integer
Dim buffer As Integer
Dim thisnumber As String * 1
Dim nextnumber As String * 1
Dim number As Integer
Dim p As Integer
For p = Len(roman) To 1 Step -1
thisnumber = UCase(Mid$(roman, p, 1))
Select Case thisnumber
Case "M"
buffer = buffer + 1000
Case "D"
buffer = buffer + 500
Case "C"
If UCase(nextnumber) = "M" Then
buffer = buffer - 100
Else
buffer = buffer + 100
End If
Case "L"
buffer = buffer + 50
Case "X"
If UCase(nextnumber) = "C" Then
buffer = buffer - 10
Else
buffer = buffer + 10
End If
Case "V"
buffer = buffer + 5
Case "I"
If UCase(nextnumber) = "V" Or UCase(nextnumber) = "X" Then
buffer = buffer - 1
Else
buffer = buffer + 1
End If
End Select
nextnumber = thisnumber
Next p
romtodec = buffer
End Function
'****************
Function dectorom(decgetal As Integer) As String
Dim buffer As String
Dim restgetal As Integer
Dim test As Integer
If decgetal 5000 Or decgetal 1 Then
dectorom = "FOUT"
Exit Function
End If
restgetal = decgetal
Do
test = restgetal - 1000
If Not test 0 Then
buffer = buffer & "M"
restgetal = restgetal - 1000
End If
Loop Until test 1000
test = restgetal - 900
If Not test 0 Then
buffer = buffer & "CM"
restgetal = restgetal - 900
End If
test = restgetal - 500
If Not test 0 Then
buffer = buffer & "D"
restgetal = restgetal - 500
End If
Do
test = restgetal - 100
If Not test 0 Then
buffer = buffer & "C"
restgetal = restgetal - 100
End If
Loop Until test 100
test = restgetal - 50
If Not test 0 Then
buffer = buffer & "L"
restgetal = restgetal - 50
End If
Do
test = restgetal - 10
If Not test 0 Then
buffer = buffer & "X"
restgetal = restgetal - 10
End If
Loop Until test 10
test = restgetal - 9
If Not test 0 Then
buffer = buffer & "IX"
restgetal = restgetal - 9
End If
test = restgetal - 5
If Not test 0 Then
buffer = buffer & "V"
restgetal = restgetal - 5
End If
test = restgetal - 4
If Not test 0 Then
buffer = buffer & "IV"
restgetal = restgetal - 4
End If
Do
test = restgetal - 1
If Not test 0 Then
buffer = buffer & "I"
restgetal = restgetal - 1
End If
Loop Until test 0
dectorom = buffer
End Function
'*********************************
Function romtodec(roman As String) As Integer
Dim buffer As Integer
Dim thisnumber As String * 1
Dim nextnumber As String * 1
Dim number As Integer
Dim p As Integer
For p = Len(roman) To 1 Step -1
thisnumber = UCase(Mid$(roman, p, 1))
Select Case thisnumber
Case "M"
buffer = buffer + 1000
Case "D"
buffer = buffer + 500
Case "C"
If UCase(nextnumber) = "M" Then
buffer = buffer - 100
Else
buffer = buffer + 100
End If
Case "L"
buffer = buffer + 50
Case "X"
If UCase(nextnumber) = "C" Then
buffer = buffer - 10
Else
buffer = buffer + 10
End If
Case "V"
buffer = buffer + 5
Case "I"
If UCase(nextnumber) = "V" Or UCase(nextnumber) = "X" Then
buffer = buffer - 1
Else
buffer = buffer + 1
End If
End Select
nextnumber = thisnumber
Next p
romtodec = buffer
End Function
'****************
Function dectorom(decgetal As Integer) As String
Dim buffer As String
Dim restgetal As Integer
Dim test As Integer
If decgetal 5000 Or decgetal 1 Then
dectorom = "FOUT"
Exit Function
End If
restgetal = decgetal
Do
test = restgetal - 1000
If Not test 0 Then
buffer = buffer & "M"
restgetal = restgetal - 1000
End If
Loop Until test 1000
test = restgetal - 900
If Not test 0 Then
buffer = buffer & "CM"
restgetal = restgetal - 900
End If
test = restgetal - 500
If Not test 0 Then
buffer = buffer & "D"
restgetal = restgetal - 500
End If
Do
test = restgetal - 100
If Not test 0 Then
buffer = buffer & "C"
restgetal = restgetal - 100
End If
Loop Until test 100
test = restgetal - 50
If Not test 0 Then
buffer = buffer & "L"
restgetal = restgetal - 50
End If
Do
test = restgetal - 10
If Not test 0 Then
buffer = buffer & "X"
restgetal = restgetal - 10
End If
Loop Until test 10
test = restgetal - 9
If Not test 0 Then
buffer = buffer & "IX"
restgetal = restgetal - 9
End If
test = restgetal - 5
If Not test 0 Then
buffer = buffer & "V"
restgetal = restgetal - 5
End If
test = restgetal - 4
If Not test 0 Then
buffer = buffer & "IV"
restgetal = restgetal - 4
End If
Do
test = restgetal - 1
If Not test 0 Then
buffer = buffer & "I"
restgetal = restgetal - 1
End If
Loop Until test 0
dectorom = buffer
End Function
Tópico encerrado , respostas não são mais permitidas