|
Check this[^] little troubleshooting guide first.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi. I am a 15 years old and program things for fun, I happen to be working on a SNAKE game and ran into a little problem. I notice that the 'head' only eats the 'food' if it is exactly on the pixel of location as the 'food'. How can I fix this problem.
This is a copy of my head_move event procedure:
Private Sub Head_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Head.Move<br />
<br />
If (Me.Head.Location.Y = Me.Food.Location.Y) And (Me.Head.Location.X = Me.Food.Location.X) Then 'checks wheather or not head had eaten the food<br />
createfood() 'creates new food using random number generator<br />
End If<br />
If Me.Head.Location.Y > 320 Then 'determines wheather or not head is in panel<br />
Game() 'resets all variables<br />
End If<br />
If Me.Head.Location.Y < 0 Then 'determines wheather or not head is in panel<br />
Game() 'resets all variables<br />
End If<br />
If Me.Head.Location.X > 384 Then 'determines wheather or not head is in panel<br />
Game() 'resets all variables<br />
End If<br />
If Me.Head.Location.X < 0 Then 'determines wheather or not head is in panel<br />
Game() 'resets all variables<br />
End If<br />
End Sub
superprogrammingdude is out yo.
|
|
|
|
|
superprogrammingdude wrote:
If (Me.Head.Location.Y = Me.Food.Location.Y) And (Me.Head.Location.X = Me.Food.Location.X) Then 'checks wheather or not head had eaten the food
You'd have to check if the Head.Location.X (and .Y) values fall between a range of values around where the food sits.
If (My.Head.Location.Y > (Me.Food.Location.Y - 5) AndAlso _
(My.Head.Location.Y < (Me.Food.Location.Y + 5) AndAlso _
(My.Head.Location.X > (Me.Food.Location.X - 5) AndAlso _
(My.Head.Location.X < (Me.Food.Location.X + 5) Then
'checks wheather or not head had easten the food
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm trying to view and print HPGL formatted graphics. Where I work wonk pop for a dll or controll, so I'm trying to roll my own.
I looked at the specs for it and thought to myself, "holy crap, this is gonna suck..."
so I opted for a different tract... I know that office 97 had the ability to import that format in, but everything after that dosent...
sooooo, i googled hpgl.exe to get the filter. I'm running office 02 and 03 and it still works.
so hers my question:
I want to use vb.net to creat a program to insert this graphic into excel, copy that pic and paste it into a picture box and view and/or print from there.
i know i can do this in a vba macro, but to back up a bit:
we have a DOS based program that scans and graphs data. when we want to print the graph it dumps the .hgl file into another dos program then to the printer through a batch file like so: c:\pp.exe test.hgl
I want to replace pp.exe w/ my program.
we can run it in a dos window, but for some reason we cant snagit, and i've tried all type of capture programs.
so with some research, I come up with this:
<br />
Private Sub insertImg()<br />
Dim ThisApplication As New Excel.ApplicationClass<br />
Dim ThisWorkBook As Excel.Workbook<br />
'ThisApplication.Visible = True<br />
Dim _stFileName As String = "c:\Test.xls"<br />
Dim _stLOGO As String = "c:\test.hgl"<br />
Dim missing As Object = System.Reflection.Missing.Value<br />
<br />
Try<br />
ThisWorkBook = ThisApplication.Workbooks.Open(_stFileName, missing, missing, 5, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)<br />
<br />
Dim ThisSheet As Excel.Worksheet = CType(ThisWorkBook.Sheets(1), Excel.Worksheet)<br />
Dim oRange As Excel.Range = CType(ThisSheet.Cells(10, 1), Excel.Range)<br />
Dim oImage As Image = Image.FromFile(_stLOGO, False)'@@@<br />
System.Windows.Forms.Clipboard.SetDataObject(oImage, True)<br />
ThisSheet.Paste(oRange, _stLOGO)<br />
<br />
ThisSheet.Copy()<br />
picFromXl.Image = Clipboard.GetDataObject<br />
<br />
Catch oEx As Exception<br />
MsgBox(oEx.ToString, MsgBoxStyle.OKCancel, "ooops...")<br />
Finally<br />
<br />
ThisApplication.Quit()<br />
ThisWorkBook = Nothing<br />
ThisApplication = Nothing<br />
End Try<br />
End Sub 'insertImage<br />
when it gets to @@@ in the comments, it throws an exception:
An unhandled exception of type 'System.InvalidCastException' occurred in hpglViewer.exe
Additional information: Specified cast is not valid.
I just can't figure it out, any sugestions...?
Thanx,
Will
|
|
|
|
|
You trying to get the Image object to parse an .HGL file, a format which it knows nothing about. That's why your getting the InvalidCastException. You have to get Excel to import the Image for you, though I don't know, off the top of my head, how to do it. I can tell you that there is an import method (Open, I think) that is in the Excel Object Model.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
here is where i'm at now...
i open excell, insert the hgl file and it shows up, i copy it. so right there i fugure it's on the clipboard because i can paste it somewhere else.
code:
<br />
Dim xlApp As Excel.Application<br />
Dim xlBook As Excel.Workbook<br />
Dim xlSheet As Excel.Worksheet<br />
Dim obj As Object<br />
<br />
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)<br />
xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)<br />
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)<br />
<br />
xlSheet.Application.Visible = True<br />
xlSheet.Range("A1").Select()<br />
xlBook.ActiveSheet.Pictures.Insert("C:\atest.hgl").Select()<br />
xlApp.ActiveSheet.Shapes("Picture 1").Copy()<br />
<br />
If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then<br />
Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()<br />
If oDataObj.GetDataPresent(DataFormats.Bitmap) Then 'this gets skiped<br />
Dim oImgObj As System.Drawing.Image = CType(oDataObj.GetData(DataFormats.Bitmap, True), Object)<br />
oImgObj.Save("c:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)<br />
End If<br />
End If<br />
<br />
Try<br />
picHpgl.Image = CType(obj, Image)<br />
Catch ex As Exception<br />
picHpgl.Image = Nothing<br />
Finally<br />
xlBook.SaveAs(CType("c:\temp.xls", Object))<br />
xlApp.Quit()<br />
Kill("c:\temp.xls")<br />
End Try<br />
<br />
End<br />
i thought when the graphic got copied, it was copied as a bitmap... i can paste it to MS paint by hand.
so i am at a loss now...
i am useing vs.net 2003, office 2002 now, running xp...
as soon as i have found a way to attach the project and an hgl file, i will...
|
|
|
|
|
You would probably have to set a breakpoint at this line
If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
then execute your code. When that line is reached, step through the code one line at a time and watch the values that are returned from the Clipboard.Getxxxx functions. This will tell you what your missing, like the actual datatype that is being returned from the clipboard.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there any way to clear the Command$
Command$= ""
Erase Command$
are not working
|
|
|
|
|
VB6 I assume...
No, it's ReadOnly. Why would you want to?
There is alos no such thing an "Erase" statement, unless you coded a function or method by that name...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i thought the erase statement cleared the contents of an array in vb.
Dim a(10) as String
Erase a
|
|
|
|
|
Whoops! You right, there is! I've been using VB since VB5 and never knoew it was there. Also, never had a reason to use it...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What's the difference between
Dim buffer() as Byte
and
Dim buffer as Byte()
|
|
|
|
|
There isn't one. They both result in type Byte() and are equal to Nothing . They're both manipulated using the exact same methods.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks dave.
so, the only difference is in style? it's up to the developer which they'd like to use? is there a preferred syntax?
-Brian
|
|
|
|
|
Not really. But in certain cases, like where you have to deserialize an XML stream back to an array, you would have to CType the XMLSerializer output to a class like this:
myClassArray = CType( myXMLSerializer.Deserialize(...), myClass() )
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
cool. so as far as initializing a array it doesn't
matter which you use. dim buffer() as byte and
dim buffer as byte() produce the same result.
it's only when casting something as an array that
you would use the array modifier on the type.
much appreciated. found this link on msdn poking
around.
http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfvbspec6_8.asp?frame=true
thanks again.
-brian
|
|
|
|
|
Earlier I asked the question about displaying the contents of a selected folder in a ListView. After Dave’s response and hours of searching books and the Internet I can’t seem to find anything about this.
What I’m looking for is something that will react in the same way that Windows Explorer does when the main window is set to ‘Thumbnails’; when a folder is opened in the TreeView, the main window displays all images as thumbnails.
How do I make this:
ListBox1.DataSource = Directory.GetFiles("C:\")
display the thumbnail images in the directory?
Does anybody have any idea how this can be accomplished?
Thanks
Brad
|
|
|
|
|
I misunderstood what you were trying to do. Here's a thumbnail viewer you can download from this very site:
http://www.codeproject.com/csharp/thumbgenerator.asp
|
|
|
|
|
Thanks.
That looks great for making thumbnails. That’s not exactly what I’m looking for but it will come in handy latter on.
I’m actually trying to create an Explorer-Style Application. I’ve figured out how to create the application but what I can’t figure out how to do is set it to display thumbnail images of any image file that is located in the directory that is currently open in the TreeView.
I know it’s possible because, in Windows Explorer, when you click ‘Thumbnails’ under the ‘View’ option, thumbnail images are displayed.
Have you ever seen the code for this before?
Thanks
Brad
|
|
|
|
|
I have not reached the level of experience necessary to directly answer your question, however, I've been looking into this as a learning exercise for myself. Perhaps in my thought processes, there will be a thread you can expand upon.
I have been looking for a way to programmatically evoke the thumbnail view, even if it had to be done by opening a specific folder path and making the setting changes via the built-in menu, but I am not seeing this option.
The System.Windows.Forms.OpenFileDialog does allow you to filter specific file types, so you can limit your view to just the image files if you wanted. The question is where is the option to view those files as thumbnails?
If it isn't a built-in class, I am thinking it should be possible to create a class to do this. When I was learning VBA, I would simply run the macro recorder and manually do what it was I wanted to code and then edit the recorded code to fit my specifications.
I am confident that there is a way to do this, it is just that we have not yet found the right set of method(s) to make it happen.
Still coaxing software out of the can after all these years...
|
|
|
|
|
Thanks again
Any input that you can provide will be helpful.
When I figure this out, assuming that I have an ounce of life left in me , I will post the result for everybody. I’ve been doing a lot of research and there just doesn’t seem to be any information about this that can be found.
Thanks
Brad
|
|
|
|
|
I did find some interesting stuff, but I don't know how related it is to exactly what you are looking to do. You may find that ASP has as much to do with the solution as VB.NET. You may be able to reverse engineer something like this to get what you need:
Dim sPath, ot, oFSO, sFolderName, i, iNode<br />
<br />
<br />
' Get Folder Path and Folder Name.<br />
<br />
sPath = Server.MapPath(Request.ServerVariables("Path_INFO"))<br />
Do Until Right(sPath, 1) = "\"<br />
sPath = Left(sPath, Len(sPath) - 1)<br />
Loop<br />
i = Len(sPath) - 1<br />
Do Until Mid(sPath, i, 1) = "\"<br />
sFolderName = Mid(sPath, i, Len(sPath) - i)<br />
i = i - 1<br />
Loop<br />
' You can set path and folder name like this:<br />
' sPath = "C:\Inetpub\wwwroot\obout\treeview\AspTreeView\"<br />
' sFolderName = "AspTreeView"<br />
<br />
' Create objects.<br />
<br />
Set oFSO = CreateObject("Scripting.FileSystemObject")<br />
Set ot = Server.CreateObject("obout_aspTreeview_Pro.tree")<br />
<br />
' Populate first node manually. In Classic first node is "root".<br />
ot.Add "", "root", " 0, 0, 128, 1)">" & sFolderName & "", True, "book.gif" <br />
<br />
' Show folders and files.<br />
Call AddFolder(sPath, "../" & Escape(sFolderName), "root")<br />
<br />
' Write treeview to page.<br />
Response.Write ot.HTML<br />
Set ot = Nothing <br />
Set oFSO = Nothing<br />
<br />
<br />
<br />
Function AddFolder(pth, dpt, parentID)<br />
Dim oF, oFolder, oFile, oSubFolder, oItem<br />
<br />
Set oFolder = oFSO.GetFolder(pth)<br />
Set oSubFolder = oFolder.SubFolders<br />
Set oFile = oFolder.Files<br />
<br />
' Display Subfolders.<br />
For Each oItem In oSubFolder <br />
iNode = iNode + 1<br />
ot.Add parentID, "z" & iNode, "<span onclick='ob_os(this)'> " & oItem.Name & "</span>"<br />
Call AddFolder(oItem.Path, dpt & "/" & Escape(oItem.Name), "z" & iNode)<br />
Next<br />
<br />
' Display Files.<br />
For Each oF In oFile<br />
iNode = iNode + 1<br />
ot.Add parentID, "z" & iNode, " <a href=" & dpt & "/" & Escape(oF.Name) & ">" & oF.Name & "</a>", , "page.gif" <br />
Next<br />
End Function<br />
http://www.obout.com/obout/treeview/asptreeview/explorer.asp
Some other promising links:
Explorer shell extension software downloads
http://www.brightdownloads.com/software/6531.htm
Still coaxing software out of the can after all these years...
|
|
|
|
|
I found a link here that might be helpful:
http://www.codeproject.com/books/1930110286_10.asp
Still coaxing software out of the can after all these years...
|
|
|
|
|
Thanks again!
I’m jumping back-and-fourth right but I’ll be back to this TreeView thing latter. It looks like the article that you suggested just might do the trick!
Thanks
Brad
|
|
|
|
|
I happen to have the book entitled 101 Visual Basic .NET Applications and application # 35 is "Create an Explorer-Style Application," however, it contains everything except a thumbnail view option.
All 101 code samples are available for download under "Companion Content" at the following URL:
http://www.microsoft.com/mspress/books/companion/6510.asp
I also poked around in the Object Browser and found this:
Image.GetThumbnailImage Method
<br />
Public Function GetThumbnailImage( _<br />
ByVal thumbWidth As Integer, _<br />
ByVal thumbHeight As Integer, _<br />
ByVal callback As Image.GetThumbnailImageAbort, _<br />
) As Image<br />
Still coaxing software out of the can after all these years...
|
|
|
|
|