bue estoy haciendo un pequeño trabajo para la escuela en el cual cifro un texto de la formma siguiente:
For x = 1 To MaxText
crypted = crypted & Chr(Asc(Mid(Form1.Texto.Text, x, 1)) + Asc(Mid(pass.Text, y, 1)))
If (y = MaxPass) Then
y = 1
End If
y = y + 1
Next x
Form1.Texto.Text = crypted
lo que hago es agarrar char por char del texto y sumarle el ascii del char que recivo en el pass, es simple y funciona
el problema es que cuando abro un txt cifrado anterior mente me sale un error en la linea:
crypted = crypted & Chr(Asc(Mid(Form1.Texto.Text, x, 1)) + Asc(Mid(Text1.Text, y, 1)))
aca les paso el codigo de todo el programa:
<<<Form1.frm - principal>>>
Dim File As Integer, txt As String
Private Sub Form_Resize()
On Error GoTo fin
If Form1.Height < 825 Then
Form1.Height = 826
End If
If Form1.Width < 120 Then
Form1.Width = 121
End If
Texto.Height = Form1.Height - 825
Texto.Width = Form1.Width - 120
fin:
End Sub
Private Sub menuDecryptItem_Click()
Load Form3
Form3.Visible = True
End Sub
Private Sub menuEncryptItem_Click()
Load Form2
Form2.Visible = True
End Sub
Private Sub menuExitItem_Click()
End
End Sub
Private Sub menuFontItem_Click()
CD.ShowColor
Texto.ForeColor = CD.Color
End Sub
Private Sub menuNewItem_Click()
Texto.Text = ""
encrypted = 0
End Sub
Private Sub menuOpenItem_Click()
On Error GoTo fin
Dim leng As Long
Dim x As Long
File = FreeFile
CD.Filter = "Text Files (*.txt)|*.txt"
CD.ShowOpen
Open CD.FileName For Binary As #File
txt = Space(LOF(File))
Get #File, , txt
Close File
Texto.Text = txt
fin:
End Sub
Private Sub menuSaveItem_Click()
On Error GoTo fin
File = FreeFile
CD.Filter = "Text Files (*.txt)|*.txt"
CD.ShowSave
Open CD.FileName For Output As #File
Print #File, Texto.Text
Close File
fin:
End Sub
<<<Form2.frm - encriptacion>>>
Dim x, MaxText, y, MaxPass As Long, crypted As String
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub Form_Load()
Label2.Visible = False
End Sub
Private Sub OKButton_Click()
Label1.Visible = False
Text1.Visible = False
OKButton.Visible = False
CancelButton.Visible = False
Label2.Visible = True
MaxText = Len(Form1.Texto.Text)
MaxPass = Len(Text1.Text)
y = 1
crypted = ""
For x = 1 To MaxText
crypted = crypted & Chr(Asc(Mid(Form1.Texto.Text, x, 1)) + Asc(Mid(Text1.Text, y, 1)))
If (y = MaxPass) Then
y = 1
End If
y = y + 1
Next x
Form1.Texto.Text = crypted
Unload Me
End Sub
<<<Form3.frm Decriptacion>>>
Dim x, MaxText, y, MaxPass As Long, decrypted As String
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub OKButton_Click()
On Error GoTo fin
Label1.Visible = False
Text1.Visible = False
OKButton.Visible = False
CancelButton.Visible = False
Label2.Visible = True
MaxText = Len(Form1.Texto.Text)
MaxPass = Len(Text1.Text)
y = 1
decrypted = ""
For x = 1 To MaxText
decrypted = decrypted & Chr(Asc(Mid(Form1.Texto.Text, x, 1)) - Asc(Mid(Text1.Text, y, 1)))
If (y = MaxPass) Then
y = 1
End If
y = y + 1
Next x
Form1.Texto.Text = decrypted
Unload Me
fin:
Unload Me
End Sub
aver si alguien me puede explicar porque cada ves que abro un archivo no salta el error en esa linea?
osea si abro el txt y le cambio algo tonces anda pero si no toco el texto despues que lo abro no anda...
alguien tiene alguna solucion?