Results 1 to 17 of 17

Thread: editing string to recognize .hDC

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    41

    editing string to recognize .hDC

    I have a BUNCH of pictureboxes with pictures in them, each with just a little different name.. for instance.

    paperred
    paperblue
    papergreen
    paperorange

    Now what im tryin to do it BitBlt then into a larger picture box as I need them. I tried to do it this way.. paraphrased

    -------------------------------------------------------------------------
    dim colorn as string
    if color=1 then colorn="red"
    firstdc= "paper" & colorn & ".hDC"
    bitblt carscreen.hDC, 0, 0, 50, 50, firstdc, 0, 0, SRCCOPY
    --------------------------------------------------------------------------

    Now, I know everything works, cause I replaced firstdc with just paperred.hDC and it worked fine. How do I go about combining the string so the VB can recognize it as the actual paperred picture box and paperred.hDC im really confused and have been trying to get this to work for days.

    Also I did this
    firstdc= paperred.hDC
    Please dont give me different ways to do this like making it one big picture box, I need to do it this way.. Thanks in advance

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    41
    how can I have the string content to be recognized as the actual picture box.. there has to be a way to do this.. hmmmm

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Set up a Case statement something like

    VB Code:
    1. Select Case colorn
    2.     Case "red"
    3.         bitblt carscreen.hDC, 0, 0, 50, 50, paperred.hDC, 0, 0, SRCCOP      
    4.     Case "blue"
    5.         bitblt carscreen.hDC, 0, 0, 50, 50, paperblue.hDC, 0, 0, SRCCOP      
    6.     Case "green"
    7.         bitblt carscreen.hDC, 0, 0, 50, 50, papergreen.hDC, 0, 0, SRCCOP      
    8. End Select

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    VB Code:
    1. Private Function GetObjectByName(ByVal Name As String) As Object
    2.     Dim Obj As Object
    3.    
    4.     For Each Obj In Me.Controls
    5.         If LCase(Obj.Name) Like LCase(Name) Then
    6.             Set GetObjectByName = Obj
    7.             Exit For
    8.         End If
    9.     Next Obj
    10. End Function
    11.  
    12. Private Sub Form_Load()
    13.     GetObjectByName("text1").Text = "hello there"
    14. End Sub

    in your case you could do something like:
    VB Code:
    1. bitblt carscreen.hDC, 0, 0, 50, 50, GetObjectByName("paper" & colorn).hDC, 0, 0, SRCCOP

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    This might work:

    firstdc= Me.Controls("paper" & colorn).hDC

  7. #7
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Hehe, there's always a better way

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    41
    Cool im gonna go give it a try now, yea, I have literally hundreds of different pics like paper, can.. blah blah blah all with 6 or 7 colors each.. Ill tell ya what works.

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    41
    hmm still not working, I tried to use the me.controls and that didnt work... i dont understand what that is really, how does me.controls work? I mean, what does it recognize as me? i guess that applies to CVMichaels post as well cause he uses a similar statement.. when using me.controls its still not recognizing it when I try to pass the variable to the final variable that gets bitblt.. I dont know.. I probobly have 1 to many variable passes that I dont need first of all... confusing, here im putting up my code so maybe someone can help. just replace paper with fiftyfivecrownvicback and youll see what im talking about, and you could see how im doing it now, similar to the way MartinLiss would have me do it, way too much typing when your gonna have hundreds of different objects with 6 colors for each object ya know?
    VB Code:
    1. Dim backpiece As Integer
    2. Dim middlepiece As Integer
    3. Dim frontpiece As Integer
    4. Dim bbtype As Integer
    5. Dim backpiecedc As String
    6. Dim middlepiecedc As String
    7. Dim frontpiecedc As String
    8. Dim backdc As String
    9. Dim middledc As String
    10. Dim frontdc As String
    11. Dim backdcwidth As Integer
    12. Dim backdcheight As Integer
    13. Dim middledcwidth As Integer
    14. Dim middledcheight As Integer
    15. Dim frontdcwidth As Integer
    16. Dim frontdcheight As Integer
    17. Dim offset As Integer
    18. Dim backdcground As Integer
    19. Dim middledcground As Integer
    20. Dim frontdcground As Integer
    21. Dim color As Integer
    22.  
    23. Dim front As String
    24. Dim colorn As String
    25. --------------------------------------------------------------
    26. Private Sub backarrowdown_Click()
    27.     backpiece = backpiece - 1
    28.     bbtype = 1
    29.     refreshimage
    30. End Sub
    31.  
    32. Private Sub backarrowup_Click()
    33.     backpiece = backpiece + 1
    34.     bbtype = 1
    35.     refreshimage
    36. End Sub
    37.  
    38. Private Sub colorblue_Click()
    39.     color = 1
    40.     bbtype = 1
    41.     colorn = "blue"
    42.     refreshimage
    43. End Sub
    44.  
    45. Private Sub colorred_Click()
    46.     color = 2
    47.     bbtype = 1
    48.     colorn = "red"
    49.     refreshimage
    50. End Sub
    51.  
    52. Private Sub Form_Load()
    53.     backpiece = 1
    54.     middlepiece = 1
    55.     frontpiece = 1
    56.     bbtype = 1
    57.     color = 2
    58.     refreshimage
    59. End Sub
    60.  
    61. Private Sub frontarrowdown_Click()
    62.     frontpiece = frontpiece - 1
    63.     bbtype = 1
    64.     refreshimage
    65. End Sub
    66.  
    67. Private Sub frontarrowup_Click()
    68.     frontpiece = frontpiece + 1
    69.     bbtype = 1
    70.     refreshimage
    71. End Sub
    72.  
    73. Private Sub midarrowdown_Click()
    74.     middlepiece = middlepiece - 1
    75.     bbtype = 1
    76.     refreshimage
    77. End Sub
    78.  
    79. Private Sub midarrowup_Click()
    80.     middlepiece = middlepiece + 1
    81.     bbtype = 1
    82.     refreshimage
    83. End Sub
    84.  
    85. Private Sub refreshimage()
    86.     BitBlt carscreen.hDC, 0, 0, 800 * 15, 350 * 15, refreshbox.hDC, 0, 0, SRCCOPY
    87.     If backpiece = 1 Then
    88.         If color = 2 Then
    89.             backdc = fiftyfivecrownvicbackred.hDC
    90.             backdcwidth = fiftyfivecrownvicbackred.Width
    91.             backdcheight = fiftyfivecrownvicbackred.Height
    92.             backdcground = 350 - (fiftyfivecrownvicbackred.Height / 15)
    93.         End If
    94.         If color = 1 Then
    95.             backdc = fiftyfivecrownvicbackblue.hDC
    96.             backdcwidth = fiftyfivecrownvicbackblue.Width
    97.             backdcheight = fiftyfivecrownvicbackblue.Height
    98.             backdcground = 350 - (fiftyfivecrownvicbackblue.Height / 15)
    99.         End If
    100.     End If
    101.     If backpiece = 2 Then
    102.         backdc = fiftyfiveimperialbackred.hDC
    103.         backdcwidth = fiftyfiveimperialbackred.Width
    104.         backdcheight = fiftyfiveimperialbackred.Height
    105.         backdcground = 350 - (fiftyfiveimperialbackred.Height / 15)
    106.     End If
    107.     If backpiece = 3 Then
    108.         backdc = fiftyfivedevillebackred.hDC
    109.         backdcwidth = fiftyfivedevillebackred.Width
    110.         backdcheight = fiftyfivedevillebackred.Height
    111.         backdcground = 350 - (fiftyfivedevillebackred.Height / 15)
    112.     End If
    113.     If backpiece = 4 Then
    114.         backdc = fiftyfivedevillesedanbackred.hDC
    115.         backdcwidth = fiftyfivedevillesedanbackred.Width
    116.         backdcheight = fiftyfivedevillesedanbackred.Height
    117.         backdcground = 350 - (fiftyfivedevillesedanbackred.Height / 15)
    118.     End If
    119.     If backpiece = 5 Then
    120.         backdc = fiftyfivetwotensedanbackred.hDC
    121.         backdcwidth = fiftyfivetwotensedanbackred.Width
    122.         backdcheight = fiftyfivetwotensedanbackred.Height
    123.         backdcground = 350 - (fiftyfivetwotensedanbackred.Height / 15)
    124.     End If
    125.     If middlepiece = 1 Then
    126.         If color = 2 Then
    127.             middledc = fiftyfivecrownvicmiddlered.hDC
    128.             middledcwidth = fiftyfivecrownvicmiddlered.Width
    129.             middledcheight = fiftyfivecrownvicmiddlered.Height
    130.             middledcground = 350 - (fiftyfivecrownvicmiddlered.Height / 15)
    131.         End If
    132.         If color = 1 Then
    133.             middledc = fiftyfivecrownvicmiddleblue.hDC
    134.             middledcwidth = fiftyfivecrownvicmiddleblue.Width
    135.             middledcheight = fiftyfivecrownvicmiddleblue.Height
    136.             middledcground = 350 - (fiftyfivecrownvicmiddleblue.Height / 15)
    137.         End If
    138.     End If
    139.     If middlepiece = 2 Then
    140.         middledc = fiftysixcrownvicmiddlered.hDC
    141.         middledcwidth = fiftysixcrownvicmiddlered.Width
    142.         middledcheight = fiftysixcrownvicmiddlered.Height
    143.         middledcground = 350 - (fiftysixcrownvicmiddlered.Height / 15)
    144.     End If
    145.     If middlepiece = 3 Then
    146.         middledc = fiftyfivespecialmiddlered.hDC
    147.         middledcwidth = fiftyfivespecialmiddlered.Width
    148.         middledcheight = fiftyfivespecialmiddlered.Height
    149.         middledcground = 350 - (fiftyfivespecialmiddlered.Height / 15)
    150.     End If
    151.     If frontpiece = 1 Then
    152.         If color = 2 Then
    153.             frontdc = fiftyfivecrownvicfrontred.hDC
    154.             frontdcwidth = fiftyfivecrownvicfrontred.Width
    155.             frontdcheight = fiftyfivecrownvicfrontred.Height
    156.             frontdcground = 350 - (fiftyfivecrownvicfrontred.Height / 15)
    157.         End If
    158.         If color = 1 Then
    159.             frontdc = fiftyfivecrownvicfrontblue.hDC
    160.             frontdcwidth = fiftyfivecrownvicfrontblue.Width
    161.             frontdcheight = fiftyfivecrownvicfrontblue.Height
    162.             frontdcground = 350 - (fiftyfivecrownvicfrontblue.Height / 15)
    163.         End If
    164.     End If
    165.     If frontpiece = 2 Then
    166.         frontdc = fiftyfiveimperialfrontred.hDC
    167.         frontdcwidth = fiftyfiveimperialfrontred.Width
    168.         frontdcheight = fiftyfiveimperialfrontred.Height
    169.         frontdcground = 350 - (fiftyfiveimperialfrontred.Height / 15)
    170.     End If
    171.     If frontpiece = 3 Then
    172.         frontdc = fiftyfivefleetwoodfrontred.hDC
    173.         frontdcwidth = fiftyfivefleetwoodfrontred.Width
    174.         frontdcheight = fiftyfivefleetwoodfrontred.Height
    175.         frontdcground = 350 - (fiftyfivefleetwoodfrontred.Height / 15)
    176.     End If
    177.     If bbtype = 1 Then
    178.                 BitBlt carscreen.hDC, 0, backdcground, backdcwidth, backdcheight, backdc, 0, 0, SRCCOPY
    179.                 BitBlt carscreen.hDC, backdcwidth / 15, middledcground, middledcwidth, middledcheight, middledc, 0, 0, SRCCOPY
    180.                 BitBlt carscreen.hDC, (backdcwidth / 15 + middledcwidth / 15), frontdcground, frontdcwidth, frontdcheight, frontdc, 0, 0, SRCCOPY
    181.     End If
    182.     bbtype = 0
    183.     carscreen.Refresh
    184. End Sub
    -----------------------------------------------------------
    please HELP, I gotta make it so you can take any one of these fiftyfivecrownvicback, fiftyfivefeetwoodfront, fiftysixcrownvicmid and so on and add "red", "blue", "green" ect.. onto it and then get it down to the BitBlt and have BitBlt recognize it as the picturebox and not just a string...
    Last edited by TheeLord; Feb 21st, 2003 at 01:47 PM.

  10. #10
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Edit your post and put [ vbcode ] [ /vbcode ] tags (without spaces) for the code you pasted...

  11. #11
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    I see several things that you should do in your code...

    You don't declare ANY variables...
    You have no idea how to use the If ... Then ... ElseIf ... End If
    And why do you have to get the objects by a string ??

    Anyways... here's how your code SHOULD look like
    VB Code:
    1. Private Sub refreshimage()
    2.     BitBlt carscreen.hDC, 0, 0, 800 * 15, 350 * 15, refreshbox.hDC, 0, 0, SRCCOPY
    3.    
    4.     If backpiece = 1 Then
    5.         If Color = 2 Then
    6.             backdc = fiftyfivecrownvicbackred.hDC
    7.             backdcwidth = fiftyfivecrownvicbackred.Width
    8.             backdcheight = fiftyfivecrownvicbackred.Height
    9.             backdcground = 350 - (fiftyfivecrownvicbackred.Height / 15)
    10.         ElseIf Color = 1 Then
    11.             backdc = fiftyfivecrownvicbackblue.hDC
    12.             backdcwidth = fiftyfivecrownvicbackblue.Width
    13.             backdcheight = fiftyfivecrownvicbackblue.Height
    14.             backdcground = 350 - (fiftyfivecrownvicbackblue.Height / 15)
    15.         End If
    16.     ElseIf backpiece = 2 Then
    17.         backdc = fiftyfiveimperialbackred.hDC
    18.         backdcwidth = fiftyfiveimperialbackred.Width
    19.         backdcheight = fiftyfiveimperialbackred.Height
    20.         backdcground = 350 - (fiftyfiveimperialbackred.Height / 15)
    21.     ElseIf backpiece = 3 Then
    22.         backdc = fiftyfivedevillebackred.hDC
    23.         backdcwidth = fiftyfivedevillebackred.Width
    24.         backdcheight = fiftyfivedevillebackred.Height
    25.         backdcground = 350 - (fiftyfivedevillebackred.Height / 15)
    26.     ElseIf backpiece = 4 Then
    27.         backdc = fiftyfivedevillesedanbackred.hDC
    28.         backdcwidth = fiftyfivedevillesedanbackred.Width
    29.         backdcheight = fiftyfivedevillesedanbackred.Height
    30.         backdcground = 350 - (fiftyfivedevillesedanbackred.Height / 15)
    31.     ElseIf backpiece = 5 Then
    32.         backdc = fiftyfivetwotensedanbackred.hDC
    33.         backdcwidth = fiftyfivetwotensedanbackred.Width
    34.         backdcheight = fiftyfivetwotensedanbackred.Height
    35.         backdcground = 350 - (fiftyfivetwotensedanbackred.Height / 15)
    36.     End If
    37.    
    38.     If middlepiece = 1 Then
    39.         If Color = 2 Then
    40.             middledc = fiftyfivecrownvicmiddlered.hDC
    41.             middledcwidth = fiftyfivecrownvicmiddlered.Width
    42.             middledcheight = fiftyfivecrownvicmiddlered.Height
    43.             middledcground = 350 - (fiftyfivecrownvicmiddlered.Height / 15)
    44.         ElseIf Color = 1 Then
    45.             middledc = fiftyfivecrownvicmiddleblue.hDC
    46.             middledcwidth = fiftyfivecrownvicmiddleblue.Width
    47.             middledcheight = fiftyfivecrownvicmiddleblue.Height
    48.             middledcground = 350 - (fiftyfivecrownvicmiddleblue.Height / 15)
    49.         End If
    50.     ElseIf middlepiece = 2 Then
    51.         middledc = fiftysixcrownvicmiddlered.hDC
    52.         middledcwidth = fiftysixcrownvicmiddlered.Width
    53.         middledcheight = fiftysixcrownvicmiddlered.Height
    54.         middledcground = 350 - (fiftysixcrownvicmiddlered.Height / 15)
    55.     ElseIf middlepiece = 3 Then
    56.         middledc = fiftyfivespecialmiddlered.hDC
    57.         middledcwidth = fiftyfivespecialmiddlered.Width
    58.         middledcheight = fiftyfivespecialmiddlered.Height
    59.         middledcground = 350 - (fiftyfivespecialmiddlered.Height / 15)
    60.     End If
    61.        
    62.     If frontpiece = 1 Then
    63.         If Color = 2 Then
    64.             frontdc = fiftyfivecrownvicfrontred.hDC
    65.             frontdcwidth = fiftyfivecrownvicfrontred.Width
    66.             frontdcheight = fiftyfivecrownvicfrontred.Height
    67.             frontdcground = 350 - (fiftyfivecrownvicfrontred.Height / 15)
    68.         ElseIf Color = 1 Then
    69.             frontdc = fiftyfivecrownvicfrontblue.hDC
    70.             frontdcwidth = fiftyfivecrownvicfrontblue.Width
    71.             frontdcheight = fiftyfivecrownvicfrontblue.Height
    72.             frontdcground = 350 - (fiftyfivecrownvicfrontblue.Height / 15)
    73.         End If
    74.     ElseIf frontpiece = 2 Then
    75.         frontdc = fiftyfiveimperialfrontred.hDC
    76.         frontdcwidth = fiftyfiveimperialfrontred.Width
    77.         frontdcheight = fiftyfiveimperialfrontred.Height
    78.         frontdcground = 350 - (fiftyfiveimperialfrontred.Height / 15)
    79.     ElseIf frontpiece = 3 Then
    80.         frontdc = fiftyfivefleetwoodfrontred.hDC
    81.         frontdcwidth = fiftyfivefleetwoodfrontred.Width
    82.         frontdcheight = fiftyfivefleetwoodfrontred.Height
    83.         frontdcground = 350 - (fiftyfivefleetwoodfrontred.Height / 15)
    84.     End If
    85.    
    86.     If bbtype = 1 Then
    87.         BitBlt carscreen.hDC, 0, backdcground, backdcwidth, backdcheight, backdc, 0, 0, SRCCOPY
    88.         BitBlt carscreen.hDC, backdcwidth / 15, middledcground, middledcwidth, middledcheight, middledc, 0, 0, SRCCOPY
    89.         BitBlt carscreen.hDC, (backdcwidth / 15 + middledcwidth / 15), frontdcground, frontdcwidth, frontdcheight, frontdc, 0, 0, SRCCOPY
    90.     End If
    91.    
    92.     bbtype = 0
    93.     carscreen.Refresh
    94. End Sub

  12. #12
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    And the keyword "Me" referes to the currect form you are using...

  13. #13

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    41
    I edited the code, put all the variables and stuff, this aint all of it by any means, this is working just fine, but im going to be adding dozens more of these if statements and then for each if statement like 6 of the color Ifs.. so its gonna be a whole lot of if statements, Id just like to have it easier to read and less typing and less work overall when I keep going and going with these. I still dont understand that me.controls if someone could explain that. Thanks

    Edit: thats what I though CV thanks.

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    You and CVMichael may have crossed posts, but Me is just a shortcut way of saying the name of the current form, and Controls is a collection of all the controls on that form. So if for example if Text1 were the only control on Form1, then all the following do the same thing

    Form1.Text1.Text = "blah"
    Form1.Controls(0).Text = "blah"
    Me.Controls(0).Text = "blah"

  15. #15
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Same thing but shorter...
    VB Code:
    1. Private Sub refreshimage()
    2.     Dim Back As Object, Middle As Object, Front As Object
    3.    
    4.     BitBlt carscreen.hDC, 0, 0, 800 * 15, 350 * 15, refreshbox.hDC, 0, 0, SRCCOPY
    5.    
    6.     If backpiece = 1 Then
    7.         If Color = 2 Then
    8.             Set Back = fiftyfivecrownvicbackred
    9.         ElseIf Color = 1 Then
    10.             Set Back = fiftyfivecrownvicbackblue
    11.         End If
    12.     ElseIf backpiece = 2 Then
    13.         Set Back = fiftyfiveimperialbackred
    14.     ElseIf backpiece = 3 Then
    15.         Set Back = fiftyfivedevillebackred
    16.     ElseIf backpiece = 4 Then
    17.         Set Back = fiftyfivedevillesedanbackred
    18.     ElseIf backpiece = 5 Then
    19.         Set Back = fiftyfivetwotensedanbackred
    20.     End If
    21.    
    22.     If middlepiece = 1 Then
    23.         If Color = 2 Then
    24.             Set Middle = fiftyfivecrownvicmiddlered
    25.         ElseIf Color = 1 Then
    26.             Set Middle = fiftyfivecrownvicmiddleblue
    27.         End If
    28.     ElseIf middlepiece = 2 Then
    29.         Set Middle = fiftysixcrownvicmiddlered
    30.     ElseIf middlepiece = 3 Then
    31.         Set Middle = fiftyfivespecialmiddlered
    32.     End If
    33.    
    34.     If frontpiece = 1 Then
    35.         If Color = 2 Then
    36.             Set Front = fiftyfivecrownvicfrontred
    37.         ElseIf Color = 1 Then
    38.             Set Front = fiftyfivecrownvicfrontblue
    39.         End If
    40.     ElseIf frontpiece = 2 Then
    41.         Set Front = fiftyfiveimperialfrontred
    42.     ElseIf frontpiece = 3 Then
    43.         Set Front = fiftyfivefleetwoodfrontred
    44.     End If
    45.    
    46.     backdc = Back.hDC
    47.     backdcwidth = Back.Width
    48.     backdcheight = Back.Height
    49.     backdcground = 350 - (Back.Height / 15)
    50.    
    51.     middledc = Middle.hDC
    52.     middledcwidth = Middle.Width
    53.     middledcheight = Middle.Height
    54.     middledcground = 350 - (Middle.Height / 15)
    55.    
    56.     frontdc = Front.hDC
    57.     frontdcwidth = Front.Width
    58.     frontdcheight = Front.Height
    59.     frontdcground = 350 - (Front.Height / 15)
    60.    
    61.     If bbtype = 1 Then
    62.         BitBlt carscreen.hDC, 0, backdcground, backdcwidth, backdcheight, backdc, 0, 0, SRCCOPY
    63.         BitBlt carscreen.hDC, backdcwidth / 15, middledcground, middledcwidth, middledcheight, middledc, 0, 0, SRCCOPY
    64.         BitBlt carscreen.hDC, (backdcwidth / 15 + middledcwidth / 15), frontdcground, frontdcwidth, frontdcheight, frontdc, 0, 0, SRCCOPY
    65.     End If
    66.    
    67.     bbtype = 0
    68.     carscreen.Refresh
    69. End Sub

  16. #16

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    41
    Thanks guys, im off to work now, but in 9 hours im gonna be back and see if this works. I owe ya

  17. #17

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    41
    That works perfectly, pretty much exactly what I was looking for, I didnt know you can declare a variable as an object, thats cool as hell. I just didnt want to type out 5 or 6 lines for every object that the EU is going to be able to choose from. Thanks alot man.

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