1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

More VB stuff

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

  1. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Ive been working hard ona vb assignment for uni and im starting to get wound up now. The bloke who wrote a lot of the code, really ****ed up by having tons and tons of code. He was being really chilish about rewriting it.

    So ive basically had to do it with help from Fergal ect, in the form of pointers. Now my code looks a lot better than his and its using case select statements etc.

    One feature this program needs to have is a random feature, where we click a button, then a form pops up and you have give the frog a name which then places a frog on a random place in the pond etc.

    Now i have it so that the frog button is clicked and the new formpops up but ive been told, by the same guy that the case select statements will have to be rewritten as the code for the new frog involves random and arrays etc.

    Looking at my code (see previous posting) i have a case select for 3 frogs etc, which are place on the form, is there anyway i can sort of merger the 2 of the events to work together. I badly need help as this bloke is starting to wind me up. He knows his stuff on vb , but his attitude overall is questionable, his reason for not using case select statemens was that he was not a fan of them??? WTF isnt that totally irrelelvant

    Anyway rant over, hopefully i can have a little more help from you guys in the form of pointers

    Thanks
    Eddie:oops:
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    Without knowing the code all I can say that the apparant suggestion that 'random' and 'case' are not compatible is rubbish.

    I don't know VB much, but usualy the random() function, or something with a similar name, returns a random value between 0 and some max value. You multiply that with a scaling factor to give you a random x-coord, and similar for a y-coord.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Grand , thats a weight off my mind Harry , cheers

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

    Fergal1982 Petabyte Poster

    4,196
    171
    211
    with clever programming, and careful forethought, almost any function you write can be written in such a way as to apply to any object of the same type. all you need to do is input the appropriate values into the function (one of which would be the identifier for the object in question).

    Its all a matter of determining what you need to do, and how to write it in the correct manner. for instance you could, as i showed you previously, write a sub for each frog individually, determining if its selected and if so, change its location based on the direction information supplied.

    Alternatively, as i showed you, you could write a single, separate function designed to take the frog its passed, determine direction and apply it to that frog. all you need to do then, is pass the selected frog into the subroutine. to do that dynamically isnt necessarily a major issue. Without looking at the code specificaly, i cant provide a specific example, but i believe you could 'group' the frogs into a set group (which would allow you to dynamically add or remove frogs from that group), and then determine the currently selected item within that grouping (allowing only one selection at a time).

    Its all a matter of perspective and taking the time to clearly think about what you want to achieve, and how best to do this.

    Fergal
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  5. zxspectrum

    zxspectrum Gigabyte Poster Premium Member

    1,666
    54
    139
    Hey Fergal, hows it going

    I did take a lot of your advice and basically the example you showed me was used, but i did it in three bits. IE case 1,2,3 etc and then wrote all the code for that.

    Now reading the assignment again, we have to have a new frog procedure when clicking a button, which i did a separate form for. The method i have used has a drawback of haveing three forgs on the pond at the same time, although ideally i could do with one on to start with and then clciking the new frog button would create a new one on so on.

    So ive been told to use a combo box instead of the form and then use an array setup etc. which i can do to an extent, i can get the code in etc but something is missing or then wrong.

    As i said i have the case set up in place which is this


    Select Case lblf1
    Case "1"
    setdirection(lblf1)


    and Select Case dirselected
    Case "U"
    lbl.top = lbl.top - 5
    Case "UR"
    lbl.top = lbl.top - 5
    lbl.left = lbl.left + 5
    Case "R"
    lbl.left = lbl.left - 5
    Case "DR"
    lbl.top = lbl.top + 5
    lbl.left = lbl.left + 5
    case "D" lbl.top
    Case "DL"
    lbl.top = lbl.top + 5
    lbl.left = lbl.left - 5
    Case "L"
    lbl.left = lbl.left - 5
    Case "UL"
    lbl.top = lbl.top - 5
    lbl.left = lbl.left - 5
    End Select


    So thats my forg procedure so far the array set up im going to try and implement is along the lines of this

    Dim cbobox(9) As Array
    Dim lblf1 As New Label
    cbobox.items.add(0) = "" & Text
    cbobox(1) = "" & Text
    cbobox(1) = "" & Text
    cbobox(2) = "" & Text
    cbobox(3) = "" & Text
    cbobox(4) = "" & Text
    cbobox(5) = "" & Text
    cbobox(6) = "" & Text
    cbobox(7) = "" & Text
    cbobox(8) = "" & Text
    cbobox(9) = "" & Text

    Now i get the feeling i am missing somthing here as well, im just not 100%

    All the stuff you have tiold me last week hasnt been wasted, its helped me quite a lot, the problem with me is i am so new to vb and in this case you have to treat me like a computer and puch the information into me lol. Nah only kidding, its new to me and im struggling thats all

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

Share This Page

Loading...