+ Reply to Thread
Results 1 to 3 of 3

Subscript Out of Range

Hybrid View

  1. #1
    Registered User
    Join Date
    08-25-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    19

    Subscript Out of Range

    I am trying to write a program in VBA to calculate GPA.

    The form has a listbox to slect grades and a textbox for users to enter the credits.

    I need to store the grades in an array once btnrecord is clicked and once user clicks BtnCalculate, I want to calculate the GPA and display the result in another textbox.

    I am getting "Subscript out of range error" in the array with the following code.

    
    Private Sub btnRecord_Click()
        
       Dim x As Long
          Dim temparray() As Variant
          
           If (IsNumeric(TextBox1.Text) = False) Then
            MsgBox "You must enter an integer number"
        Exit Sub
        End If
         
        ReDim temparray(1 To TextBox1.Text)
         
         
         For I = 1 To TextBox1.Text
         
            
                Select Case Me.ListBox1.Value
                    Case "A+"
                        temparray(x) = (4.33 * n)
                    Case "A"
                        temparray(x) = (4 * n)
                   Case "A-"
                        temparray(x) = (3.67 * n)
                    Case "B+"
                        temparray(x) = (3.33 * n)
                   Case "B"
                        temparray(x) = (3 * n)
                   Case "B"
                       temparray(x) = (2.67 * n)
                   Case "C+"
                        temparray(x) = (2.33 * n)
                    Case "C"
                        temparray(x) = (2 * n)
                   Case "C-"
                       temparray(x) = (1.67 * n)
                    Case "D+"
                        temparray(x) = (1.33 * n)
                    Case "D"
                        temparray(x) = (1 * n)
                   Case "D-"
                       temparray(x) = (0.67 * n)
               End Select
            
          Next I
    ReDim Preserve temparray(x)
        
    End Sub

    Please help.

    Thanks,
    Blyzzard

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Subscript Out of Range

    You need to put a value in x before using it.
    Gary's Student

  3. #3
    Registered User
    Join Date
    08-25-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Subscript Out of Range

    I am not sure about how many courses will be there in each trancript, so cannot set the upperbound.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. subscript out of range
    By josros60 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2013, 06:33 PM
  2. Subscript out of range error while populating array from range.
    By Aussiexile in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2010, 02:22 AM
  3. Subscript out of range error when trying to select a range
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2010, 07:57 PM
  4. subscript out of range
    By palm101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2009, 04:13 AM
  5. Subscript Out of range
    By mmf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2008, 06:55 PM

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