achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 Im trying to get a part of a picture.```Dim itemnumDim itempicDim MaxFramesMaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32itemnum = GetPlayerEquipment(MyIndex, weapon)If itemnum > 0 Thenitempic = Item(itemnum).PicPicture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp")ElseExit SubEnd If```It highlights```MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32```What am i doing wrong? Link to comment Share on other sites More sharing options...
Scott Posted January 21, 2012 Share Posted January 21, 2012 ```Dim itemnumDim itempicDim MaxFrames```You need to declare what type of variables these will be.ex```Dim MaxFrames as Long```and Subscript out of range means your trying to access an element of an array that does not exist, make sure itempic is within the proper range of the DDSD_Item array. Link to comment Share on other sites More sharing options...
achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 still gives me the error Link to comment Share on other sites More sharing options...
Scott Posted January 21, 2012 Share Posted January 21, 2012 If it's still subscript out of range than read the last part of my post, if not what error is it now? Link to comment Share on other sites More sharing options...
achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 ```Dim itemnumDim itempicDim MaxFrames As ByteDim DDSD_Item As DDSURFACEDESC2MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32itemnum = GetPlayerEquipment(MyIndex, weapon)If itemnum > 0 Thenitempic = Item(itemnum).PicPicture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp")ElseExit SubEnd If```give me "compile error expexted array"and highlights the DDSD_Item Link to comment Share on other sites More sharing options...
Scott Posted January 21, 2012 Share Posted January 21, 2012 Why do you have this here now?```Dim DDSD_Item As DDSURFACEDESC2```This should already be declared in the modDirectDraw7, not to mention your trying to call it as an array when it's not which was causing your error. Link to comment Share on other sites More sharing options...
achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 Because it still gives me a subscript out of range without it. Link to comment Share on other sites More sharing options...
Scott Posted January 21, 2012 Share Posted January 21, 2012 Than fix the subscript error, its simple your trying to access a part of an array which does not exist, so the number in the itempic variable is 1 of 2 things.1.Lower than 12.Above your max item images Link to comment Share on other sites More sharing options...
achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 nope neither… I just changed it to >= 0 and my max item images is not part seeing as its only item number 3 of 255 Link to comment Share on other sites More sharing options...
Scott Posted January 21, 2012 Share Posted January 21, 2012 You don't even have a type declared for itempic in the last snipit you posted, a subscript out of range error means your trying to access a part of an array that does not exist, so make sure your not feeding any numbers above or below its range into that array.Example.If an array is set to be 1-10and you try to call 11 or 0 you get a subscript out of range.```Dim TestArray(1 To 10) as LongTestArray(11) = 4```This would give you a subscript out of range because it's not using a number between 1 and 10 which is the min/max elements of this array. Link to comment Share on other sites More sharing options...
achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 Ok well can you help me because I am new to coding XD I do have a type now it is a long.Private Sub Picture1_Click()Dim itemnum As LongDim itempic As LongDim MaxFramesitempic = Item(itemnum).PicMaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32itemnum = GetPlayerEquipment(MyIndex, weapon)If itemnum > 0 ThenPicture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp")ElseExit SubEnd IfEnd SubThat was the whole code.also its in the frmmainsorry for the double post.[Please do not double post.] Link to comment Share on other sites More sharing options...
Scott Posted January 21, 2012 Share Posted January 21, 2012 1\. It seems MaxFrames lost its type again.2.What are you trying to do here?3.Use code tags please makes it easier to read4.Format your code its annoying to read like that.```Dim itemnum As LongDim itempic As LongDim MaxFrames As Byte MaxFrames = (DDSD_Item(itempic).lWidth / 2) / 32 itemnum = GetPlayerEquipment(MyIndex, weapon) If itemnum > 0 Then itempic = Item(itemnum).Pic Picture1.Picture = LoadPicture("data files\graphics\items\" & MaxFrames & ".bmp") Else Exit Sub End If```This should fix the subscript error, you where trying to use itemnum before you assigned it. Link to comment Share on other sites More sharing options...
achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 Trying to show equiped items in a special menu. Link to comment Share on other sites More sharing options...
Scott Posted January 21, 2012 Share Posted January 21, 2012 Look how its done in Sub BltEquipment() you need to blt it. Link to comment Share on other sites More sharing options...
achap89 Posted January 21, 2012 Author Share Posted January 21, 2012 can u help me XDI can get it to show an image but i cant get it to go to the second part of the image and not show it all.in the highlighted portion I get(DDSD_Item(itempic).lWidth / 2) / 32 is the error Link to comment Share on other sites More sharing options...
Scott Posted January 22, 2012 Share Posted January 22, 2012 Doing it the way your trying to is going about it wrong, copy how its done with Equipment, look at Sub BltEquipment() for how it's done in that case. Link to comment Share on other sites More sharing options...
achap89 Posted January 22, 2012 Author Share Posted January 22, 2012 I have looked at it… Once again I am a new coder I have no idea what any of it is about. So can you please help me. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now