Results 1 to 7 of 7

Thread: guys really, plz help :)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    13

    guys really, plz help :)

    I can now bitblt, cept I am new to arrays and keyboard input. First of all, I REALY need to know how to use key input to do things efficiently, all of VBs defualt things SUCK. Isnt there a getsynckey api? Also, if I make a type for tiles, how would I assign each tile a value then be able to retrieve that value?
    the type looks like this:

    Code:
    Type tiles as integer
       x as integer
       y as integer
       tv as integer 'tile value..like lava, etc.
    end type
    how would I assign each tile a value and then recall it?
    Code:
    dim tile(maxtilesvar) as integer
    I want it to basically say if it is the tile(0) then assign or view its tv, x, and y.
    Also where is a good place to learn about text saving? DON'T FORGET HELP WITH KEY input is desired! THANKS GUYS
    Msgbox "MUAHAHA"

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    About the keys:
    To test which keys has been pressed, use the KeyDown event of your main form.
    If you want to know more about it, just create a new VB project with an empty form. In the form's code you place:
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.  
    3.   Debug.Print "KeyCode: " & KeyCode & ", Shift: " & Shift
    4.  
    5. End Sub

    In the immediate window, you'll see which keys has been pressed and which shift mask it has (shift = 1, ctrl = 2, alt = 4).
    Look at the KeyCodeConstants and ShiftConstants in the object browser (press F2 in the VB IDE to access it).

    About the tiles:
    I would suggest you to name the user defined type 'tile', since one variable will hold information of only one tile. There's no need to store the X and Y in the tile, since it can be retrieved by the array index. If you are only interested in the type of a tile (the tv value), there's no need to use a user defined type, but this way you can store other information as well, like resistance. (It's a lot harder to move around in a swamp than on grass plains, for example.)

    Dimension the tile array like this:
    Code:
    Dim Tiles(tileCountX - 1, tileCountY - 1) As Tile
    Important note: Normally, the lowest index of an array is 0, so if you want an array of n elements, you should give it the dimension n-1 ! I admit this behaviour is indesirable, but you have to live with it.

    To fill the tiles, you can do something like this:
    VB Code:
    1. For x = 0 to tileCountX - 1
    2.         For y = 0 to tileCountY - 1
    3.             Tiles(x, y).tv = value   'The source can be anything: another array, a text file, etc...
    4.         Next y
    5.     Next x
    You can retrieve the tile value the same way: value = Tiles(x, y).tv

    Another tip: install a copy of MSDN on your machine, if you haven't done so yet.

    Good luck!

  3. #3
    Zaei
    Guest
    Originally posted by riis

    Important note: Normally, the lowest index of an array is 0, so if you want an array of n elements, you should give it the dimension n-1 ! I admit this behaviour is indesirable, but you have to live with it.
    It is certainly strange behavior. C++ arrays are defined with the number of elements, then run from 0 to numElements - 1.

    Z.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What if you use
    Option Base 1
    ?

    I think this sets the array base to be 1
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Zaei
    Guest
    It does, but then you get used to using base one, and thats just strange =).

    Z.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. 'in a module
    2. Public Const DT_CENTER = &H1
    3. Public Const DT_WORDBREAK = &H10
    4. Public Type RECT
    5.     Left As Long
    6.     Top As Long
    7.     Right As Long
    8.     Bottom As Long
    9. End Type
    10. Public Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
    11. Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    12. Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    13. Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    14. Public Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    15. Public  Cnt As Long, sSave As String, sOld As String, Ret As String
    16. Public Tel As Long
    17.  
    18. Public Function GetPressedKey() As String
    19.     For Cnt = 32 To 128
    20.         'Get the keystate of a specified key
    21.         If GetAsyncKeyState(Cnt) <> 0 Then
    22.             GetPressedKey = Chr$(Cnt)
    23.             Exit For
    24.         End If
    25.     Next Cnt
    26. End Function
    27.  
    28. Public Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
    29.     Ret = GetPressedKey
    30.     If Ret <> sOld Then
    31.         sOld = Ret
    32.         sSave = sSave + sOld
    33.     End If
    34. End Sub
    35.  
    36. 'on your form
    37.  
    38. Private Sub Form_Load()
    39.     'KPD-Team 1999
    40.     'URL: [url]http://www.allapi.net/[/url]
    41.     'E-Mail: [email][email protected][/email]
    42.     Me.Caption = "Key Spy"
    43.     'Create an API-timer
    44.     SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
    45. End Sub
    46.  
    47. Private Sub Form_Paint()
    48.     Dim R As RECT
    49.     Dim mStr As String
    50.     mStr = "Start this project, go to another application, type something, switch back to this application "
    51.     mStr = mStr & "and unload the form. If you unload the form, a messagebox with all the typed keys "
    52.     mStr = mStr & "will be shown."
    53.     'Clear the form
    54.     Me.Cls
    55.     'API uses pixels
    56.     Me.ScaleMode = vbPixels
    57.     'Set the rectangle's values
    58.     SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
    59.     'Draw the text on the form
    60.     DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
    61. End Sub
    62.  
    63. Private Sub Form_Resize()
    64.     Form_Paint
    65. End Sub
    66.  
    67. Private Sub Form_Unload(Cancel As Integer)
    68.     'Kill our API-timer
    69.     KillTimer Me.hwnd, 0
    70.     'Show all the typed keys
    71.     MsgBox sSave
    72. End Sub

  7. #7
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    0 based arrays > all =]
    To understand recursion, one must first understand the concept of recursion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width