Results 1 to 40 of 389

Thread: ChatGPT

Threaded View

  1. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: ChatGPT

    Quote Originally Posted by yereverluvinuncleber View Post
    My question to chat GPT: how do I animate GDI+ images using VB6?

    The answer: To animate GDI+ images using VB6, you can follow the steps below:

    Load the images: Load all the images that you want to use in the animation into an Image array using the Image.FromFile method.

    Set up the animation loop: Create a loop that will run the animation continuously. You can use a Timer control to create the loop.

    Draw the images: In the Timer control's event handler, use the Graphics.DrawImage method to draw each image in the array onto the form.

    Set the delay: To control the speed of the animation, use the Timer control's Interval property to set the delay between each frame.

    Here is an example code to help you get started:

    > vbnet <
    Code:
    Private imageArray() As Image
    Private currentIndex As Integer = 0
    
    Private Sub Form_Load()
        ' Load the images
        ReDim imageArray(3)
        imageArray(0) = Image.FromFile("image1.png")
        imageArray(1) = Image.FromFile("image2.png")
        imageArray(2) = Image.FromFile("image3.png")
        imageArray(3) = Image.FromFile("image4.png")
    
        ' Set up the animation loop
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        ' Draw the current image
        Dim g As Graphics
        Set g = Me.CreateGraphics
        g.DrawImage imageArray(currentIndex), 0, 0
    
        ' Increment the index and wrap around to the start of the array
        currentIndex = (currentIndex + 1) Mod UBound(imageArray) + 1
    End Sub
    In this example, we load four images into an array and use a Timer control to draw the images on the form. The Timer control's Interval property is set to 100 milliseconds, which means the animation will update every 100 milliseconds. The Timer1_Timer event handler draws the current image in the array onto the form using the Graphics.DrawImage method. The currentIndex variable is used to keep track of the current image index, and it is incremented and wrapped around to the start of the array in each timer tick to create the animation loop.

    END

    Not bad but still not spot on. Doesn't seem to know about VB6 but still impressive.
    That's VB.Net code.....well VB.Net-ish.....That Form Load event is definitely VB6 since in VB.Net it would be Form1_Load(sender as object, e as EventArgs). The code is using GDI+ to draw as we would in .Net. Even then it's still a bit wrong. We wouldn't call CreateGraphics like that for a Form. The Paint event in WinForms has a graphics object we can use so no need to call CreateGraphics ever.

    In any case, ChatGPT has trouble getting VB6 queries correctly. It's best language is Python. It very rarely gets Python queries wrong.

    [EDIT]

    Oh yea, and we don't have Set in VB.Net. That code is a mish-mash of VB6 and VB.Net. Seems ChatGPT is not quite sure what it is writing.
    Last edited by Niya; Feb 15th, 2023 at 09:24 PM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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