Mkäköhän on kun vb sanoo "Type mismatch" tummennetusta kohdasta?
Public Function GetHit() Dim mouseyx(9) As POINTAPI Dim I As Long For I = 0 To 9 [b]mouseyx(I) = [/b]FindBitmapMask(stat(I), SelWnd, 5, 8, 647, 206, 654, 216, 0) Select Case mouseyx(I).x Case Is <> -1: Number = I End Select Next I For I = 0 To 9 mouseyx(I) = FindBitmapMask(stat(I), SelWnd, 5, 8, 655, 209, 663, 220, 0) Select Case mouseyx(I).x Case Is <> -1: number2 = I End Select Next I If number2 = 0 And mouseyx(0).x < 0 Then number2 = "" GetHit = Number & number2 End Function
Yrittäkää edes arvata mikä on ongelma. :D
Onko funktion FindBitmapMask palautusarvon tyyppi POINTAPI?
...tai onko stat():n arvo numeerinen koko välillä 0-9?
En oikein ymmärtänyt. Mitä tuo virhe on suomeksi?
Haittaako jos monessa moduulissa ja yhdessä formissa on "Public/private type POINTAPI tjsp. jne." ?
Tuo GetHit toimii toisessa projektissa.
Voin lähettää nuo funktiot kun pääsen kotiin.
Eli:
Public Function FindBitmapMask( ... ) As POINTAPI
Onko tämä POINTAPI, kuten yllä?
Lisäksi stat pitäisi olla ilmeisesti Long. Tarkista että se on.
Type Mismatch tulee silloin, kun yrittää syöttää väärää muuttujatyyppiä jonnekin, minne se ei kelpaa. VB6 tosin yrittää monissa eri tapauksissa pakottaa muuttujan oikeaan muotoon, mutta se ei aina onnistu, näin esimerkiksi UDT:tä käytettäessä (User Defined Type, POINTAPI on tällainen). Yleensä kuitenkin on hyvä välttää muuttujatyyppipakottaminen ja muuntaa muuttujat muodosta toiseen esim. CLng, CStr jne. funktioiden avulla.
En voi editoida edellistä viestiä joten tässä funktiot (tulee vähän pitkä viesti):
'***Class Moduulissa*** Sub RunSIfHPU(Hitpoints As Long) Dim Randi7 As Integer Dim Randi8 As Integer Dim Randi11 As Integer Randomize Form1.MMSetCursor 585, 187 WaitMs (Int(Rnd * 100) + 10) Randomize Randi11 = Int(Rnd * 50) + 10 WaitMs (Randi11) LeftClick WaitMs (Randi11 * 0.5) Form1.GetHP If Form1.GetHP <= (Hitpoints) Then GoSouth Randomize Randi8 = Int(Rnd * 50) + 10 WaitMs (Randi8) SetRun WaitMs (Randi8) OpenInv End If End Sub
'***MODUULI*** Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Public Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Public Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Type POINTAPI X As Long Y As Long End Type Public Function FindBitmapMask(SBitmapDC As Long, SelWnd As Long, Width As Long, Height As Long, posx1 As Long, posy1 As Long, posx2 As Long, posy2 As Long, MaskColor As Long) As POINTAPI Dim X As Long, X2 As Long, Y As Long, Y2 As Long, tmpPixel1 As Long, tmpPixel2 As Long, PBitmapDC As Long, mouseyx As POINTAPI, FirstPixel As Long, FirstPoint As POINTAPI PBitmapDC = GetDC(SelWnd) For Y = 0 To Height - 1 For X = 0 To Width - 1 tmpPixel1 = GetPixel(SBitmapDC, X, Y) If tmpPixel1 <> MaskColor Then FirstPixel = tmpPixel1 FirstPoint.X = X FirstPoint.Y = Y GoTo Coolz0rz End If Next X Next Y Coolz0rz: For Y = posy1 To posy2 For X = posx1 To posx2 tmpPixel1 = GetPixel(PBitmapDC, X, Y) If tmpPixel1 = FirstPixel Then For Y2 = Y - FirstPoint.Y To Y + Height - 1 - FirstPoint.Y 'Image1 is the quick and lazy way For X2 = X - FirstPoint.X To X + Width - 1 - FirstPoint.X ' to get height and width, lol tmpPixel1 = GetPixel(PBitmapDC, X2, Y2) tmpPixel2 = GetPixel(SBitmapDC, X2 - (X - FirstPoint.X), Y2 - (Y - FirstPoint.Y)) If tmpPixel2 <> MaskColor Then If tmpPixel1 <> tmpPixel2 Then GoTo NextX End If 'SetPixel Form1.Picture2.hdc, x2, y2, 300000 Next X2 Next Y2 mouseyx.X = X - FirstPoint.X mouseyx.Y = Y - FirstPoint.Y FindBitmapMask = mouseyx Exit Function End If NextX: Next X NextY: Next Y mouseyx.X = -1 FindBitmapMask = mouseyx End Function Public Function LoadGraphicDC(sFilename As String) As Long On Error Resume Next Dim LoadGraphicDCTEMP As Long, tmpObject As Long LoadGraphicDCTEMP = CreateCompatibleDC(GetDC(0)) SelectObject LoadGraphicDCTEMP, LoadPicture(sFilename) LoadGraphicDC = LoadGraphicDCTEMP End Function
'***MODUULI*** Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Const WM_CLOSE = &H10 Public Declare Function timeGetTime Lib "winmm.dll" () As Long Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Public Type POINTAPI X As Long Y As Long End Type Public Sub Wait(TimeOut As Long) Dim TimeNow As Long TimeNow = timeGetTime() Do DoEvents Loop While TimeNow + TimeOut > timeGetTime() End Sub Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long Randomize Rand = Int((High - Low + 1) * Rnd) + Low End Function Public Function MouseMoveSmooths(DestinationPointX, DestinationPointY As Long) Dim POINT As POINTAPI Dim X, Y, StartPointX, StartPointY GetCursorPos POINT StartPointX = POINT.X StartPointY = POINT.Y X = StartPointX - DestinationPointX Y = StartPointY - DestinationPointY Do Until X = 0 And Y = 0 DoEvents GetCursorPos POINT DoEvents If X > 0 Then X = X - 1 POINT.X = POINT.X - 1 ElseIf X < 0 Then X = X + 1 POINT.X = POINT.X + 1 End If If Y > 0 Then Y = Y - 1 POINT.Y = POINT.Y - 1 ElseIf Y < 0 Then Y = Y + 1 POINT.Y = POINT.Y + 1 End If Dim randi2 As Integer Randomize randi2 = Int((Rnd * 15) + 2) Wait (randi2 / 10) DoEvents SetCursorPos POINT.X, POINT.Y DoEvents Loop End Function
'***Form1:sestä 2 funktiota*** Option Explicit Public cScript As New clscScript Public CommentColor As Long Public StringColor As Long Public KeysColor As Long Public SetupKeys As Boolean Public LoginPacket As Boolean Public Pause As Boolean Private Declare Function SaveDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function Getasynckeystate Lib "user32" Alias "GetAsyncKeyState" (ByVal VKEY As Long) As Integer Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRGN As Long, ByVal bRedraw As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpbi As BITMAPINFO, ByVal wUsage As Long) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long 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) As Long Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Private Type POINTAPI X As Long Y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Dim SelWnd As Long Private Const SWP_NOMOVE = 2 Private Const SWP_NOSIZE = 1 Private Const flags = SWP_NOMOVE Or SWP_NOSIZE Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 Private Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type Private Type BITMAPINFOHEADER biSize As Long biWidth As Long biHeight As Long biPlanes As Integer biBitCount As Integer biCompression As Long biSizeImage As Long biXPelsPerMeter As Long biYPelsPerMeter As Long biClrUsed As Long biClrImportant As Long End Type Private Type RGBQUAD rgbBlue As Byte rgbGreen As Byte rgbRed As Byte rgbReserved As Byte End Type Private Type BITMAPINFO bmiHeader As BITMAPINFOHEADER bmiColors As RGBQUAD End Type Private Const DIB_RGB_COLORS = 0& Private Const BI_RGB = 0& Dim Versii As String Dim stat(9) As Long Public Sub MMSetCursor(X As Long, Y As Long) Dim mousexy As POINTAPI mousexy.X = X mousexy.Y = Y ClientToScreen SelWnd, mousexy MouseMoveSmooths mousexy.X, mousexy.Y End Sub Public Function GetHP() 'Tää oli ennen GetHit Dim mouseyx(9) As POINTAPI Dim I As Long For I = 0 To 9 mouseyx(I) = FindBitmapMask(stat(I), SelWnd, 5, 8, 647, 206, 654, 216, 0) Select Case mouseyx(I).X Case Is <> -1: Number = I End Select Next I For I = 0 To 9 mouseyx(I) = FindBitmapMask(stat(I), SelWnd, 5, 8, 655, 209, 663, 220, 0) Select Case mouseyx(I).X Case Is <> -1: number2 = I End Select Next I If number2 = 0 And mouseyx(0).X < 0 Then number2 = "" GetHP = Number & number2 End Function
^ Toivottavasti joku jaksaa etsiä virhettä :D Kiitos!
stat on taulukkomuuttuja, joten sitä ei voine pistää ByRefinä funktioon (en ole VB-koneella nyt). Kokeile tehdä tämmöinen muutos:
Public Function FindBitmapMask(ByVal SBitmapDC As Long,
ByRef lähettää muuttujan sellaisenaan. Jos arvoa muuttaa funktiossa, se muuttuu funktioon syötetyssä muuttujassa.
ByVal lähettää muuttujan arvon. Arvoa voi muuttaa funktiossa sen vaikuttamatta funktioon syötetyssä muuttujassa.
ByRef on oletusasetus.
Esimerkki tästä, pastea formille ja lisää nappula:
Sub Esimerkki1(ByRef Testi As Boolean) Testi = True End Sub Sub Esimerkki2(ByVal Testi As Boolean) Testi = True End Sub Private Sub Command1_Click() Dim Kokeilu As Boolean Kokeilu = False Esimerkki1 Kokeilu MsgBox "Esimerkki1: " & Kokeilu Kokeilu = False Esimerkki2 Kokeilu MsgBox "Esimerkki2: " & Kokeilu End Sub
Sain jo toimimaan muuten. Piti siirtää moduuleista funktioita form1:seen.
Hmm... kappas, huomasinpas sellaisen asian myöskin, että olit määritellyt POINTAPI:n Privatena Formissa. Siksi siirto moduulista formille todennäköisesti auttoi. Eli siis yksinkertaisin ratkaisu ongelmaan olisi ollut poistaa POINTAPI Formista.
(Ja tosiaan, noin suuren koodimäärän sumpliminen ei ole sitä hauskinta hommaa.)
Merri kirjoitti:
Eli siis yksinkertaisin ratkaisu ongelmaan olisi ollut poistaa POINTAPI Formista.
Formin omat funktiot eivät olisi sen jälkeen toimineet. Ja tossa ei todellakaan ollut kaikki koodi. :D
Mikseivät olisi? Olet määrittänyt moduulissa POINTAPI:n julkiseksi (Public). Tämä tuo POINTAPI-tyypin kaikkialla ohjelmassa käyttöön, jolloin sitä ei tarvitse olla erikseen esim. jokaisessa muussa moduulissa, formissa ja luokkamoduulissa joka sitä käyttää.
Aihe on jo aika vanha, joten et voi enää vastata siihen.