+ Reply to Thread
Results 1 to 5 of 5

Do Loops

Hybrid View

kathhying Do Loops 11-08-2011, 09:11 AM
Domski Re: Do Loops 11-08-2011, 09:17 AM
kathhying Re: Do Loops 11-08-2011, 09:20 AM
Domski Re: Do Loops 11-08-2011, 09:24 AM
Domski Re: Do Loops 11-08-2011, 09:34 AM
  1. #1
    Registered User
    Join Date
    10-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2010 (mac)
    Posts
    10

    Do Loops

    Is there something wrong in this program?


    Sub DetailProduct()
    
    Dim code As String
    Dim Length As Single
    Dim Diameter As Single
    Dim Colour As String
    Dim ok As Boolean
    
    ok = False
    
    Do
        code = InputBox("Please enter the 3 character product code.")
        
        If code = "" Then
            Exit Sub
        End If
    
        If IsNumeric(code) Then
            ok = False
            MsgBox "Error - you have entered the numeric input."
        Else
            If Len(code) <> 3 Then
                ok = False
                MsgBox "error- please enter 3 character product code."
            Else
                ok = True
               Length = UCase(Left(code, 1, 1))
      
                Diameter = UCase(Mid(code, 1, 2))
         
                Colour = UCase(Right(code, 1))
            
                Select Case Length
                    Case "A"
                        Length = 250
                    Case "B"
                        Length = 500
                    Case "C"
                        Length = 1000
                    Case "D"
                        Length = 3000
                    Case Else
                        MsgBox "error"
                End Select
            
                Select Case Diameter
                    Case "K"
                        Diameter = 30
                    Case "L"
                        Diameter = 45
                    Case "M"
                        Diameter = 60
                    Case "N"
                        Diameter = 100
                    Case Else
                        MsgBox "error"
                End Select
            
                Select Case Colour
                    Case "W"
                        Colour = "red"
                    Case "X"
                        Colour = "green"
                    Case "Y"
                        Colour = "blue"
                    Case "Z"
                        Colour = "white"
                    Case Else
                        MsgBox "error"
                End Select
            End If
        End If
    
    
    Loop Until code = "END"
    
    MsgBox "The input " & code & " would produce the cylinder is " & Length & "mm by " & Diameter & "mm and is " & Colour
    
    End Sub

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Do Loops

    This:

    Length = UCase(Left(code, 1, 1))

    should only be:

    Length = UCase(Left(code, 1))

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    10-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2010 (mac)
    Posts
    10

    Re: Do Loops

    Hi i have already changed it, but it still doesnt work.

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Do Loops

    Length and Diameter should be declared as String's by the look of it.

    Dom

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Do Loops

    Still needs a bit of work but hopefully this will point you in the right direction:

    Sub DetailProduct()
    
    Dim code As String
    Dim Length As String
    Dim Diameter As String
    Dim Colour As String
    Dim ok As Boolean
    
    ok = False
    
    Do
        code = InputBox("Please enter the 3 character product code.")
        
        If code = "" Or code = "END" Then
            Exit Sub
        End If
    
        If IsNumeric(code) Then
            ok = False
            MsgBox "Error - you have entered the numeric input."
        Else
            If Len(code) <> 3 Then
                ok = False
                MsgBox "error- please enter 3 character product code."
            Else
                ok = True
               Length = UCase(Left(code, 1))
      
                Diameter = UCase(Mid(code, 2, 1))
         
                Colour = UCase(Right(code, 1))
            
                Select Case Length
                    Case "A"
                        Length = 250
                    Case "B"
                        Length = 500
                    Case "C"
                        Length = 1000
                    Case "D"
                        Length = 3000
                    Case Else
                        MsgBox "error"
                End Select
            
                Select Case Diameter
                    Case "K"
                        Diameter = 30
                    Case "L"
                        Diameter = 45
                    Case "M"
                        Diameter = 60
                    Case "N"
                        Diameter = 100
                    Case Else
                        MsgBox "error"
                End Select
            
                Select Case Colour
                    Case "W"
                        Colour = "red"
                    Case "X"
                        Colour = "green"
                    Case "Y"
                        Colour = "blue"
                    Case "Z"
                        Colour = "white"
                    Case Else
                        MsgBox "error"
                End Select
            End If
        End If
    
    MsgBox "The input " & code & " would produce the cylinder is " & Length & "mm by " & Diameter & "mm and is " & Colour
    
    Loop
    
    End Sub

    Dom

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1