|
-
Feb 20th, 2003, 07:52 PM
#1
Thread Starter
Member
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
-
Feb 20th, 2003, 08:37 PM
#2
If you are tring to create a variable name from two strings, you can't.
-
Feb 20th, 2003, 09:07 PM
#3
Thread Starter
Member
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
-
Feb 21st, 2003, 12:09 AM
#4
Set up a Case statement something like
VB Code:
Select Case colorn
Case "red"
bitblt carscreen.hDC, 0, 0, 50, 50, paperred.hDC, 0, 0, SRCCOP
Case "blue"
bitblt carscreen.hDC, 0, 0, 50, 50, paperblue.hDC, 0, 0, SRCCOP
Case "green"
bitblt carscreen.hDC, 0, 0, 50, 50, papergreen.hDC, 0, 0, SRCCOP
End Select
-
Feb 21st, 2003, 03:10 AM
#5
VB Code:
Private Function GetObjectByName(ByVal Name As String) As Object
Dim Obj As Object
For Each Obj In Me.Controls
If LCase(Obj.Name) Like LCase(Name) Then
Set GetObjectByName = Obj
Exit For
End If
Next Obj
End Function
Private Sub Form_Load()
GetObjectByName("text1").Text = "hello there"
End Sub
in your case you could do something like:
VB Code:
bitblt carscreen.hDC, 0, 0, 50, 50, GetObjectByName("paper" & colorn).hDC, 0, 0, SRCCOP
-
Feb 21st, 2003, 03:18 AM
#6
This might work:
firstdc= Me.Controls("paper" & colorn).hDC
-
Feb 21st, 2003, 03:20 AM
#7
Hehe, there's always a better way
-
Feb 21st, 2003, 12:51 PM
#8
Thread Starter
Member
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.
-
Feb 21st, 2003, 01:18 PM
#9
Thread Starter
Member
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:
Dim backpiece As Integer
Dim middlepiece As Integer
Dim frontpiece As Integer
Dim bbtype As Integer
Dim backpiecedc As String
Dim middlepiecedc As String
Dim frontpiecedc As String
Dim backdc As String
Dim middledc As String
Dim frontdc As String
Dim backdcwidth As Integer
Dim backdcheight As Integer
Dim middledcwidth As Integer
Dim middledcheight As Integer
Dim frontdcwidth As Integer
Dim frontdcheight As Integer
Dim offset As Integer
Dim backdcground As Integer
Dim middledcground As Integer
Dim frontdcground As Integer
Dim color As Integer
Dim front As String
Dim colorn As String
--------------------------------------------------------------
Private Sub backarrowdown_Click()
backpiece = backpiece - 1
bbtype = 1
refreshimage
End Sub
Private Sub backarrowup_Click()
backpiece = backpiece + 1
bbtype = 1
refreshimage
End Sub
Private Sub colorblue_Click()
color = 1
bbtype = 1
colorn = "blue"
refreshimage
End Sub
Private Sub colorred_Click()
color = 2
bbtype = 1
colorn = "red"
refreshimage
End Sub
Private Sub Form_Load()
backpiece = 1
middlepiece = 1
frontpiece = 1
bbtype = 1
color = 2
refreshimage
End Sub
Private Sub frontarrowdown_Click()
frontpiece = frontpiece - 1
bbtype = 1
refreshimage
End Sub
Private Sub frontarrowup_Click()
frontpiece = frontpiece + 1
bbtype = 1
refreshimage
End Sub
Private Sub midarrowdown_Click()
middlepiece = middlepiece - 1
bbtype = 1
refreshimage
End Sub
Private Sub midarrowup_Click()
middlepiece = middlepiece + 1
bbtype = 1
refreshimage
End Sub
Private Sub refreshimage()
BitBlt carscreen.hDC, 0, 0, 800 * 15, 350 * 15, refreshbox.hDC, 0, 0, SRCCOPY
If backpiece = 1 Then
If color = 2 Then
backdc = fiftyfivecrownvicbackred.hDC
backdcwidth = fiftyfivecrownvicbackred.Width
backdcheight = fiftyfivecrownvicbackred.Height
backdcground = 350 - (fiftyfivecrownvicbackred.Height / 15)
End If
If color = 1 Then
backdc = fiftyfivecrownvicbackblue.hDC
backdcwidth = fiftyfivecrownvicbackblue.Width
backdcheight = fiftyfivecrownvicbackblue.Height
backdcground = 350 - (fiftyfivecrownvicbackblue.Height / 15)
End If
End If
If backpiece = 2 Then
backdc = fiftyfiveimperialbackred.hDC
backdcwidth = fiftyfiveimperialbackred.Width
backdcheight = fiftyfiveimperialbackred.Height
backdcground = 350 - (fiftyfiveimperialbackred.Height / 15)
End If
If backpiece = 3 Then
backdc = fiftyfivedevillebackred.hDC
backdcwidth = fiftyfivedevillebackred.Width
backdcheight = fiftyfivedevillebackred.Height
backdcground = 350 - (fiftyfivedevillebackred.Height / 15)
End If
If backpiece = 4 Then
backdc = fiftyfivedevillesedanbackred.hDC
backdcwidth = fiftyfivedevillesedanbackred.Width
backdcheight = fiftyfivedevillesedanbackred.Height
backdcground = 350 - (fiftyfivedevillesedanbackred.Height / 15)
End If
If backpiece = 5 Then
backdc = fiftyfivetwotensedanbackred.hDC
backdcwidth = fiftyfivetwotensedanbackred.Width
backdcheight = fiftyfivetwotensedanbackred.Height
backdcground = 350 - (fiftyfivetwotensedanbackred.Height / 15)
End If
If middlepiece = 1 Then
If color = 2 Then
middledc = fiftyfivecrownvicmiddlered.hDC
middledcwidth = fiftyfivecrownvicmiddlered.Width
middledcheight = fiftyfivecrownvicmiddlered.Height
middledcground = 350 - (fiftyfivecrownvicmiddlered.Height / 15)
End If
If color = 1 Then
middledc = fiftyfivecrownvicmiddleblue.hDC
middledcwidth = fiftyfivecrownvicmiddleblue.Width
middledcheight = fiftyfivecrownvicmiddleblue.Height
middledcground = 350 - (fiftyfivecrownvicmiddleblue.Height / 15)
End If
End If
If middlepiece = 2 Then
middledc = fiftysixcrownvicmiddlered.hDC
middledcwidth = fiftysixcrownvicmiddlered.Width
middledcheight = fiftysixcrownvicmiddlered.Height
middledcground = 350 - (fiftysixcrownvicmiddlered.Height / 15)
End If
If middlepiece = 3 Then
middledc = fiftyfivespecialmiddlered.hDC
middledcwidth = fiftyfivespecialmiddlered.Width
middledcheight = fiftyfivespecialmiddlered.Height
middledcground = 350 - (fiftyfivespecialmiddlered.Height / 15)
End If
If frontpiece = 1 Then
If color = 2 Then
frontdc = fiftyfivecrownvicfrontred.hDC
frontdcwidth = fiftyfivecrownvicfrontred.Width
frontdcheight = fiftyfivecrownvicfrontred.Height
frontdcground = 350 - (fiftyfivecrownvicfrontred.Height / 15)
End If
If color = 1 Then
frontdc = fiftyfivecrownvicfrontblue.hDC
frontdcwidth = fiftyfivecrownvicfrontblue.Width
frontdcheight = fiftyfivecrownvicfrontblue.Height
frontdcground = 350 - (fiftyfivecrownvicfrontblue.Height / 15)
End If
End If
If frontpiece = 2 Then
frontdc = fiftyfiveimperialfrontred.hDC
frontdcwidth = fiftyfiveimperialfrontred.Width
frontdcheight = fiftyfiveimperialfrontred.Height
frontdcground = 350 - (fiftyfiveimperialfrontred.Height / 15)
End If
If frontpiece = 3 Then
frontdc = fiftyfivefleetwoodfrontred.hDC
frontdcwidth = fiftyfivefleetwoodfrontred.Width
frontdcheight = fiftyfivefleetwoodfrontred.Height
frontdcground = 350 - (fiftyfivefleetwoodfrontred.Height / 15)
End If
If bbtype = 1 Then
BitBlt carscreen.hDC, 0, backdcground, backdcwidth, backdcheight, backdc, 0, 0, SRCCOPY
BitBlt carscreen.hDC, backdcwidth / 15, middledcground, middledcwidth, middledcheight, middledc, 0, 0, SRCCOPY
BitBlt carscreen.hDC, (backdcwidth / 15 + middledcwidth / 15), frontdcground, frontdcwidth, frontdcheight, frontdc, 0, 0, SRCCOPY
End If
bbtype = 0
carscreen.Refresh
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.
-
Feb 21st, 2003, 01:21 PM
#10
Edit your post and put [ vbcode ] [ /vbcode ] tags (without spaces) for the code you pasted...
-
Feb 21st, 2003, 01:40 PM
#11
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:
Private Sub refreshimage()
BitBlt carscreen.hDC, 0, 0, 800 * 15, 350 * 15, refreshbox.hDC, 0, 0, SRCCOPY
If backpiece = 1 Then
If Color = 2 Then
backdc = fiftyfivecrownvicbackred.hDC
backdcwidth = fiftyfivecrownvicbackred.Width
backdcheight = fiftyfivecrownvicbackred.Height
backdcground = 350 - (fiftyfivecrownvicbackred.Height / 15)
ElseIf Color = 1 Then
backdc = fiftyfivecrownvicbackblue.hDC
backdcwidth = fiftyfivecrownvicbackblue.Width
backdcheight = fiftyfivecrownvicbackblue.Height
backdcground = 350 - (fiftyfivecrownvicbackblue.Height / 15)
End If
ElseIf backpiece = 2 Then
backdc = fiftyfiveimperialbackred.hDC
backdcwidth = fiftyfiveimperialbackred.Width
backdcheight = fiftyfiveimperialbackred.Height
backdcground = 350 - (fiftyfiveimperialbackred.Height / 15)
ElseIf backpiece = 3 Then
backdc = fiftyfivedevillebackred.hDC
backdcwidth = fiftyfivedevillebackred.Width
backdcheight = fiftyfivedevillebackred.Height
backdcground = 350 - (fiftyfivedevillebackred.Height / 15)
ElseIf backpiece = 4 Then
backdc = fiftyfivedevillesedanbackred.hDC
backdcwidth = fiftyfivedevillesedanbackred.Width
backdcheight = fiftyfivedevillesedanbackred.Height
backdcground = 350 - (fiftyfivedevillesedanbackred.Height / 15)
ElseIf backpiece = 5 Then
backdc = fiftyfivetwotensedanbackred.hDC
backdcwidth = fiftyfivetwotensedanbackred.Width
backdcheight = fiftyfivetwotensedanbackred.Height
backdcground = 350 - (fiftyfivetwotensedanbackred.Height / 15)
End If
If middlepiece = 1 Then
If Color = 2 Then
middledc = fiftyfivecrownvicmiddlered.hDC
middledcwidth = fiftyfivecrownvicmiddlered.Width
middledcheight = fiftyfivecrownvicmiddlered.Height
middledcground = 350 - (fiftyfivecrownvicmiddlered.Height / 15)
ElseIf Color = 1 Then
middledc = fiftyfivecrownvicmiddleblue.hDC
middledcwidth = fiftyfivecrownvicmiddleblue.Width
middledcheight = fiftyfivecrownvicmiddleblue.Height
middledcground = 350 - (fiftyfivecrownvicmiddleblue.Height / 15)
End If
ElseIf middlepiece = 2 Then
middledc = fiftysixcrownvicmiddlered.hDC
middledcwidth = fiftysixcrownvicmiddlered.Width
middledcheight = fiftysixcrownvicmiddlered.Height
middledcground = 350 - (fiftysixcrownvicmiddlered.Height / 15)
ElseIf middlepiece = 3 Then
middledc = fiftyfivespecialmiddlered.hDC
middledcwidth = fiftyfivespecialmiddlered.Width
middledcheight = fiftyfivespecialmiddlered.Height
middledcground = 350 - (fiftyfivespecialmiddlered.Height / 15)
End If
If frontpiece = 1 Then
If Color = 2 Then
frontdc = fiftyfivecrownvicfrontred.hDC
frontdcwidth = fiftyfivecrownvicfrontred.Width
frontdcheight = fiftyfivecrownvicfrontred.Height
frontdcground = 350 - (fiftyfivecrownvicfrontred.Height / 15)
ElseIf Color = 1 Then
frontdc = fiftyfivecrownvicfrontblue.hDC
frontdcwidth = fiftyfivecrownvicfrontblue.Width
frontdcheight = fiftyfivecrownvicfrontblue.Height
frontdcground = 350 - (fiftyfivecrownvicfrontblue.Height / 15)
End If
ElseIf frontpiece = 2 Then
frontdc = fiftyfiveimperialfrontred.hDC
frontdcwidth = fiftyfiveimperialfrontred.Width
frontdcheight = fiftyfiveimperialfrontred.Height
frontdcground = 350 - (fiftyfiveimperialfrontred.Height / 15)
ElseIf frontpiece = 3 Then
frontdc = fiftyfivefleetwoodfrontred.hDC
frontdcwidth = fiftyfivefleetwoodfrontred.Width
frontdcheight = fiftyfivefleetwoodfrontred.Height
frontdcground = 350 - (fiftyfivefleetwoodfrontred.Height / 15)
End If
If bbtype = 1 Then
BitBlt carscreen.hDC, 0, backdcground, backdcwidth, backdcheight, backdc, 0, 0, SRCCOPY
BitBlt carscreen.hDC, backdcwidth / 15, middledcground, middledcwidth, middledcheight, middledc, 0, 0, SRCCOPY
BitBlt carscreen.hDC, (backdcwidth / 15 + middledcwidth / 15), frontdcground, frontdcwidth, frontdcheight, frontdc, 0, 0, SRCCOPY
End If
bbtype = 0
carscreen.Refresh
End Sub
-
Feb 21st, 2003, 01:48 PM
#12
And the keyword "Me" referes to the currect form you are using...
-
Feb 21st, 2003, 01:53 PM
#13
Thread Starter
Member
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.
-
Feb 21st, 2003, 02:19 PM
#14
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"
-
Feb 21st, 2003, 02:36 PM
#15
Same thing but shorter...
VB Code:
Private Sub refreshimage()
Dim Back As Object, Middle As Object, Front As Object
BitBlt carscreen.hDC, 0, 0, 800 * 15, 350 * 15, refreshbox.hDC, 0, 0, SRCCOPY
If backpiece = 1 Then
If Color = 2 Then
Set Back = fiftyfivecrownvicbackred
ElseIf Color = 1 Then
Set Back = fiftyfivecrownvicbackblue
End If
ElseIf backpiece = 2 Then
Set Back = fiftyfiveimperialbackred
ElseIf backpiece = 3 Then
Set Back = fiftyfivedevillebackred
ElseIf backpiece = 4 Then
Set Back = fiftyfivedevillesedanbackred
ElseIf backpiece = 5 Then
Set Back = fiftyfivetwotensedanbackred
End If
If middlepiece = 1 Then
If Color = 2 Then
Set Middle = fiftyfivecrownvicmiddlered
ElseIf Color = 1 Then
Set Middle = fiftyfivecrownvicmiddleblue
End If
ElseIf middlepiece = 2 Then
Set Middle = fiftysixcrownvicmiddlered
ElseIf middlepiece = 3 Then
Set Middle = fiftyfivespecialmiddlered
End If
If frontpiece = 1 Then
If Color = 2 Then
Set Front = fiftyfivecrownvicfrontred
ElseIf Color = 1 Then
Set Front = fiftyfivecrownvicfrontblue
End If
ElseIf frontpiece = 2 Then
Set Front = fiftyfiveimperialfrontred
ElseIf frontpiece = 3 Then
Set Front = fiftyfivefleetwoodfrontred
End If
backdc = Back.hDC
backdcwidth = Back.Width
backdcheight = Back.Height
backdcground = 350 - (Back.Height / 15)
middledc = Middle.hDC
middledcwidth = Middle.Width
middledcheight = Middle.Height
middledcground = 350 - (Middle.Height / 15)
frontdc = Front.hDC
frontdcwidth = Front.Width
frontdcheight = Front.Height
frontdcground = 350 - (Front.Height / 15)
If bbtype = 1 Then
BitBlt carscreen.hDC, 0, backdcground, backdcwidth, backdcheight, backdc, 0, 0, SRCCOPY
BitBlt carscreen.hDC, backdcwidth / 15, middledcground, middledcwidth, middledcheight, middledc, 0, 0, SRCCOPY
BitBlt carscreen.hDC, (backdcwidth / 15 + middledcwidth / 15), frontdcground, frontdcwidth, frontdcheight, frontdc, 0, 0, SRCCOPY
End If
bbtype = 0
carscreen.Refresh
End Sub
-
Feb 21st, 2003, 03:12 PM
#16
Thread Starter
Member
Thanks guys, im off to work now, but in 9 hours im gonna be back and see if this works. I owe ya
-
Feb 22nd, 2003, 01:34 PM
#17
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|