Results 1 to 10 of 10

Thread: [RESOLVED] help

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Resolved [RESOLVED] help

    in VB i have this code to deducte resources for a place.

    Do Until i <= 300

    metal1 = ship2_no.Text * 300
    metalt = CLng(Label1.Caption - metal1)

    i = metalt < 300
    MsgBox ("Not Enough")
    i = i + 3
    Loop


    wot ive tried to do is this if i have enough for 6 items but i ask for 10 how to i make it stop on 6 and not do into - figures?

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: help

    Hey KPS,

    I don't totally understand what you want. How about telling us more.

    The only thing I can see is :
    i = metalt < 300
    This line is just setting i to true or false.

    Do you mean :
    If I < 300 then ...

    If you want to exit the loop at this point then use Exit Do
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: help

    that sounds rite ill give it a try thanks

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: help

    okay ive taken the do out ive now got this

    If ship2_no.Text Then
    metal1 = ship2_no.Text * 300 ' this works out how much is needed eg 300 * 300
    metalt = CLng(Label1.Caption - metal1) ' this sutracts amount 1000 - 900

    If metal1 > 300 Then ' this part is where i want it to say if metal1 is more that how much we have then msgbox then only allow how many it can produce or dont allow any sort of thing
    MsgBox ("Not Enough")
    End If
    End If

    if that makes more sence

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: help

    I dont understand? it looks like u have what you need...

    VB Code:
    1. If ship2_no.Text Then
    2.         metal1 = ship2_no.Text * 300
    3.         metalt = CLng(Label1.Caption - metal1)
    4.        
    5.         If metal1 > 300 Then
    6.             MsgBox "Not Enough"
    7.         End If
    8.     End If
    so if metal1 is more than 300 then say Not Enough?

    also, on a side note, try to use the VBCODE tags around your code. makes it easier
    to read...
    Just click VBcode in the quick reply, then paste or type your code, then click VBCode again Thanks!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: help

    VB Code:
    1. If metal1 > 300 Then
    should be
    VB Code:
    1. If metal1 > metalt Then msg box

    wot happens is when i say 30 units for example ,it does this 30*300 then 10000 which is the total amount i have- 9000 which is the calculations total fantastic that works fine it deducts and everyones happy

    if i order 40 at 300 cost 12000 then it does 10000 - 12000 im in the red as were by 2000.

    i want it to say no carnt by all them then to end the process or build as many as allowed

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: help

    something like this?

    if too many then ask the user if they want to just use whats there...
    if No.. exits sub
    if yes.. then.. do your code
    VB Code:
    1. If ship2_no.Text Then
    2.         metal1 = ship2_no.Text * 300
    3.         metalt = CLng(Label1.Caption - metal1)
    4.        
    5.         If metal1 > metalt Then
    6.             If MsgBox("Not enough to build that many! Would you like to use whats available? (" & _
    7.             Label1.Caption & ")", vbYesNo + vbQuestion, "Not Enough") = vbNo Then Exit Sub
    8.             metal1 = metalt
    9.             'do othe code..
    10.            
    11.         End If
    12.     End If
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: help

    It looks like Static is heading you in the right direction. How about this slight tweak ?
    VB Code:
    1. If ship2_no.Text Then
    2.     metal1 = ship2_no.Text * 300
    3.     metalt = CLng(Label1.Caption - metal1)
    4.    
    5.     If metal1 > metalt Then
    6.         If MsgBox("Not enough to build that many! Would you like to use whats available? (" & _
    7.         Label1.Caption & ")", vbYesNo + vbQuestion, "Not Enough") = vbNo Then Exit Sub
    8.         metal1 = metalt
    9.        
    10.         'do othe code... Build the maximum amount
    11.     Else
    12.         'there's enough, so build it.
    13.     End If
    14. End If
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: help

    i will try this thanks guys

    /me wishes i didnt start this project. Once its finished ill publish it ok here for more info visit www.mmfak.co.uk/sw.htm i think it is or just go to www.mmfak.co.uk click on links and its the sub_wars link
    Last edited by KPS.; Jun 23rd, 2006 at 09:40 AM.

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: help

    found it issue resolved
    Last edited by KPS.; Jun 23rd, 2006 at 09:51 AM.

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