Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
eu fiz 1 codigo para converter 1 linguagem para outra:
Option Explicit
Public Type Word
SentenceWord As String
Position As Long
Size As Long
End Type
Public Type POINTAPI
x As Long
y As Long
End Type
Public Function GetLastWord(Text As String) As String
Dim Words() As String
Words = Split(Text, " ")
GetLastWord = Words(UBound(Words))
End Function
Public Function IsKeyWord(ByVal sWord As String) As Boolean
Dim sWordList() As String
Dim lnglenWord As Long
sWordList = Split("main end write")
' We put the delimiter character "|" at the start and end of the word list
' So that Instr$() Will not accidentally find a sub word, such as "end" in "spend"
IsKeyWord = False
For lnglenWord = 0 To UBound(sWordList)
If sWord = sWordList(lnglenWord) Then
IsKeyWord = True
Exit Function
End If
Next lnglenWord
End Function
Public Function ExpertSplit(Sentence As String) As Word()
Dim lngWord As Long
Dim wrdWord() As Word
Dim blnWordEnter As Boolean
Dim lngSentencePos As Long
Dim blnNoSpace As Boolean
blnWordEnter = False
blnNoSpace = True
For lngSentencePos = 1 To Len(Sentence)
If (Mid(Sentence, lngSentencePos, 1) <> " " Or lngSentencePos = Len(Sentence)) And blnWordEnter = False Then
blnNoSpace = True
blnWordEnter = True
lngWord = lngWord + 1
ReDim Preserve wrdWord(lngWord)
wrdWord(lngWord).Position = lngSentencePos
ElseIf Mid(Sentence, lngSentencePos, 1) = " " And blnWordEnter = True Then
blnNoSpace = False
blnWordEnter = False
wrdWord(lngWord).Size = lngSentencePos - wrdWord(lngWord).Position
wrdWord(lngWord).SentenceWord = Mid(Sentence, wrdWord(lngWord).Position, wrdWord(lngWord).Size)
End If
Next lngSentencePos
If blnNoSpace = True Then
ReDim wrdWord(1)
wrdWord(0).SentenceWord = Sentence
wrdWord(0).Position = 1
wrdWord(0).Size = Len(Sentence)
End If
ExpertSplit = wrdWord()
End Function
Public Function GetTextLine(Text As String, LineNumber As Long) As String
Dim strLines() As String
If Len(Text) = 0 Or LineNumber < 1 Then
GetTextLine = ""
Exit Function
End If
strLines = Split(Text, Chr(13))
If LineNumber > UBound(strLines) Then LineNumber = UBound(strLines)
GetTextLine = strLines(LineNumber)
End Function
Public Function IsString(Text As String) As Boolean
If Len(Text) = 0 Then
IsString = False
Exit Function
End If
If Mid(Text, 1, 1) = """" And Mid(Text, Len(Text), 1) = """" Then
IsString = True
Else
IsString = False
End If
End Function
Public Function LastChar(Text As String) As String
LastChar = Right(Text, 1)
End Function
Public Function GetLineCount(Text As String) As Long
Dim lngLineCount As Long
Dim lngTextPos As Long
If Len(Text) = 0 Then
GetLineCount = 0
Exit Function
Else
lngLineCount = 1
End If
For lngTextPos = 1 To Len(Text)
If Mid(Text, lngTextPos, 2) = vbNewLine Then
lngLineCount = lngLineCount + 1
End If
Next
GetLineCount = lngLineCount
End Function
Public Sub ConvertCode(Destination As RichTextBox, Source As RichTextBox)
Dim lngLineCount As Long
Dim lngLinePos As Long
Dim strLineText As String
Dim lngWordPos As Long
Dim wrdWords() As Word
Destination.SelText = "#include <stdio.h>" & vbNewLine
lngLineCount = GetLineCount(Source.Text) 'diz-me o numero de linhas
For lngLinePos = 1 To lngLineCount
strLineText = GetTextLine(Source.Text, lngLinePos) 'da-me o texto de 1 linha
wrdWords() = ExpertSplit(strLineText) 'mete as palavras separadas em 1 array
For lngWordPos = 0 To UBound(wrdWords) - 1
If wrdWords(lngWordPos).SentenceWord = "main" Then
Destination.SelText = "int main()" & vbNewLine & "{" & vbNewLine
ElseIf wrdWords(lngWordPos).SentenceWord = "end" Then
Destination.SelText = "return 0" & vbNewLine & "}" & vbNewLine
End If
DoEvents
Next lngWordPos
Next lngLinePosalguem me pode explicar o que estou a fazer mal?
Carregando comentários...