visual basic stuff

Discussion in 'Scripting & Programming' started by zxspectrum, Apr 4, 2007.

  1. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    OK people im stuck on something that is probably going to be really simple

    What im trying to do is when a frog( lblf1 , lblf2 , lblf3) is eaten by a monster (gollum) 1, the frogs to dissappear, with the message box to say various things??

    On a plus side for me i am getting no squiggly blue lines which is a first for me , i cant think why it wont work though.

    Below is the actual code, and ive put the code in the Gollum label.
    Any help would be great.

    If lblGollum.Text = lblF1.Text Then '
    lblF1.Visible = False
    MessageBox.Show("yum yum tasty frog ")
    End If

    If lblGollum.Text = lblF2.Text Then
    lblF2.Visible = False
    MessageBox.Show(" that frog needs more salt ")
    End If
    If lblGollum.Text = lblF3.Text Then
    lblF3.Visible = False
    MessageBox.Show(" Id prefer a Subway ")
    End If
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  2. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    Nowhere near enough code on there to deduce anything. It just lays out the conditions that determine the specifics of the messagebox text to be shown.
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  3. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    OK ill try and give it you in english lol. Basically that gollum touches the frog icon etc and what i am after is a messagebox saying one of the three quotes. As far as i can see if they should work as i think im telling VB that if the gollum (lblgollum.text) gets a frog (lblfrog.text) then the message should appear.
    Displaying a message box cant be that hard, the only other things i can think of is to try and put it in a timer, though i think thats wrong or pointless or maybe i have missed a ine of code. Am i right in thinking i dont need to declare anything in relation to the message box ie dim messagebox as string ???

    Thanks
    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  4. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    you are indeed correct, messagebox is a builtin method and doesnt need to be dim'ed.

    However, this doesnt give nearly enough information to make a deduction. If you want to zip up the project i could take a look at the complete source, but i think you need to really step through the code to see whats happening.

    Also, if this is a direct quote from your code, you arent using your statements neatly. Whilst the code as listed should work as intended, you really want to use either if/else statements, or a case statement. IE:

    Code:
    If lblGollum.Text = lblF1.Text Then 
        lblF1.Visible = False
        MessageBox.Show("yum yum tasty frog ")
    ElseIf lblGollum.Text = lblF2.Text Then
        lblF2.Visible = False
        MessageBox.Show(" that frog needs more salt ")
    ElseIf lblGollum.Text = lblF3.Text Then
        lblF3.Visible = False
        MessageBox.Show(" Id prefer a Subway ")
    Else
       'Enter Any code here that should be actioned should none of
       'the above conditions be true.
    End If
    
    or
    Code:
    Select Case lblGollum.Text 
        Case lblF1.Text 
             lblF1.Visible = False
             MessageBox.Show("yum yum tasty frog ")
        Case lblF2.Text 
             lblF2.Visible = False
             MessageBox.Show(" that frog needs more salt ")
        Case lblF3.Text 
             lblF3.Visible = False
             MessageBox.Show(" Id prefer a Subway ")
        Case Else
             'Place code here to fire should none of the above
             'conditions be true
    End Select
    
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  5. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Im with you Fergal and if its ok with you ill send you the project in a zip file. Ill have to nip home though as i have 2 versions of the same project. The first one has been done by a lad in our group, who has put way too much code in timers etc, the version im trying to do is to get the code smaller by using case statements etc.

    I appreciate the offer
    Thanks
    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  6. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Ok fergal the best way to do this is for me to send you both copies of the programs. There is closer and closer 2. Closer 2 works but if you look at the code it is somewehat extensive and the tutor thinks the lad has copied it from somewhere.

    So closer 2 is starting to be my version where i am aiming to get the code looking shorter but with the same effects. The message box example you showed me still does not work i get nothing in fact so i must be missing something, i even tried to put it in a timer to see if that would work but to no avail.

    As well as the 2 examples , i have sent you a copy of the actual assignment, not for you to do all the code for me, but if its ok with you id like some pointers on what to use etc, like case statements or select staements.

    Thanks for your help, but if you feel its too much for you then please dont worry as ill be plodding on with it anyway

    Eddie
     

    Attached Files:

    Certifications: BSc computing and information systems
    WIP: 70-680
  7. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    By the way if anyone else feels they can help without actually writing the program but in the form of pointers then please feel free.

    Any help is appreciated

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  8. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    Im not really seeing where the above code is coming from. Which function is it located in?

    EDIT:
    I could be missing it, but there doesnt appear to be any code which is changing the text value of lblF(n) or lblGollum = so the text of these two is remaining the same and therefore the above code would never fire.

    It almost looks to me like you are trying to make it check so that when the gollum icon is occupying the same space as the frog, the frog disappears and you get this error message, is that right? If thats the case, I wouldnt use the text field, but rather do some sort of check to see if the gollum and frog co-ordinates are the same - ideally you would use a timer to do this, firing every 0.5 to 1 second - and to be honest i personally would have it in a second thread so that it doesnt affect your ability to use the application.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  9. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Im asuming your on about the messagebox here???

    Its located in the lblgollum , the red box??

    Hope that helps??

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  10. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    I dont have any code in that - however i do see the lblgollum.click event handler - which is empty.

    If thats what you are using, then thats your problem. That event only fires when the user actually clicks on the object. It will never fire in any other event on its current setup.

    What you need to do it essentially set up a timer event that fires every so many milliseconds that checks the position of the gollum and the frogs relative to each other, and then fires off the desired commands when the two positions are the same.

    Does that make sense?
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  11. Crito

    Crito Banned

    505
    14
    0
    I think the OnMouseMove or OnMouseHover methods are what you're looking for. Though moving the mouse over an object may make it not be visible on screen, that doesn't actually change the visible property itself.
     
    Certifications: A few
    WIP: none
  12. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    Im not sure those methods are viable either though, as as far as i understand it, this event should fire whether the user is looking at the frog or not (correct me if im wrong here).

    Basically, as i understand it, the gollum makes a beeline for the nearest frog and, once its caught it, eats it - so once its caught it, it should display the message and make the frog in question disappear.

    In order to do that, you need a function that is independant upon the user interacting with either the frog or gollum icons - which means a timer event firing at regular intervals, checking their relative positions.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  13. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    OK im with you , ill set it up for a timer event etc. But i did try this before with no results. One thing thats just popped into my head is even though the gollum does touch the frog etc and therefore the posiatins are more or less the same, the gollum slightly overlaps leaving about 2mm (on screen) visible to see etc

    Would this throw the position checking out of sync etc , as its not totally covering the whoole of the frog, or am i being stupid???

    Edd
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  14. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Hey fergal im not too sure what you mean by this bit here

    ' and to be honest i personally would have it in a second thread so that it doesnt affect your ability to use the application'.

    I understand the timer concept though

    Cheers
    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  15. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    OK bit of good news for a change tho this is presenting me with another problem.

    If Timer6.Enabled = True Then
    lblGollum.Text = lblF2.Text
    lblF1.Visible = False
    MessageBox.Show("9")

    I did this just to test the water so to speak, then i got loads of message boxes and basically i had to shuit the prog down etc .

    Now im presuming that i have to end the procedure so that i dont get more boxes appearing as i only want the one.

    Ed
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  16. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    OK im getting there i just need to work out the code for stopping the timer which i dont think will be hard. But another thing that is puzzling me is when the gollum eats the frog the gollum turns to 2 and the no 1 forg dissappears.

    Now the only thing i can think of is that all the code in timers 1,2,3 are all to ****. The code in them anyway needs shortening with case select statements but this is where ill struggle lol, but its going to be worth it me thinks??

    Any ideas
    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  17. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    Ok. Your application runs in a single thread. meaning that everything progresses in a linear fashion, one after the other. For instance, if you set a button to go check a DB for information before coming back and displaying it on screen, and the search takes a while, the app 'freezes' whilst it runs the search.

    However, you can create additional threads within the app to run certain things that take time, without affecting the status of the main application. Threads are a bit tricky to get the hang of (trust me, i learned the hard way - and i only know a little about them so far), and it might not be required for this app but its something i would consider if you find your app constantly freezing when running.

    For the timer, you want to try something like this:
    Code:
    Public Class Form1
        Dim Timer As New Timer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer.Interval = 10000 '10 seconds
    
            AddHandler Timer.Tick, AddressOf TickResponse
        End Sub
    
        Private Sub TickResponse(ByVal sender As Object, ByVal e As System.EventArgs)
            MessageBox.Show("Timer has ticked")
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Timer.Start()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Timer.Stop()
        End Sub
    End Class
    
    Copy this code into a new project, and add two buttons to the form. button1 starts and button2 stops the timer.

    Bear in mind i code in VS2005, not VS2003 like you, so there may be a minor difference in how this is handled, but i dont believe so.

    You could also initialise timer.start on form load, it doesnt need to be tied to any buttons, or labels, etc.

    As far as the problem with the positioning is concerned, you would likely find that, depending on how you coded it, it would run the comparison off the top left corner on both icons (or the centre point, i believe theres a position method for that), so only when these positions match up would it work.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  18. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    for changing target, you are going to need to include something in the distance comparison sub so that only visible frogs are compared to decide where to go to.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  19. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    If Timer6.Enabled = True Then
    lblGollum.Text = lblF1.Text
    Timer6.Stop()
    lblF1.Visible = False
    MessageBox.Show("YUM YUM TASTY FROG")
    ElseIf lblGollum.Text = lblF2.Text Then
    Timer6.Stop()
    lblF2.Visible = False
    MessageBox.Show(" THAT FROG NEEDS MORE SALT")
    ElseIf lblGollum.Text = lblF3.Text Then
    Timer6.Stop()
    lblF3.Visible = False
    MessageBox.Show("ID PREFER A SUBWAY")

    End If
    Thats what ive come up with so far Fergal, and it does work to an extent. Ill get the message but im getting the gollum, which is a letter G on my form turning to the number of the frog its eaten etc, that shouldnt be a problem. The only other thing i can think of is to do the whole code again on the three timers as i think that they are misleading to say the least if that makes sense ??

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  20. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    If Timer6.Enabled = True Then
    lblGollum.Text = lblF1.Text
    Timer6.Stop()
    lblF1.Visible = False
    MessageBox.Show("YUM YUM TASTY FROG")
    ElseIf lblGollum.Text = lblF2.Text Then
    Timer6.Stop()
    lblF2.Visible = False
    MessageBox.Show(" THAT FROG NEEDS MORE SALT")
    ElseIf lblGollum.Text = lblF3.Text Then
    Timer6.Stop()
    lblF3.Visible = False
    MessageBox.Show("ID PREFER A SUBWAY")

    End If
    Thats what ive come up with so far Fergal, and it does work to an extent. Ill get the message but im getting the gollum, which is a letter G on my form turning to the number of the frog its eaten etc, that shouldnt be a problem. The only other thing i can think of is to do the whole code again on the three timers as i think that they are misleading to say the least if that makes sense ??

    Eddie
     
    Certifications: BSc computing and information systems
    WIP: 70-680

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.