Results 1 to 3 of 3

Thread: [RESOLVED] Compile Error: Constant expression required? Help!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Resolved [RESOLVED] Compile Error: Constant expression required? Help!

    It highlights this sub:
    Code:
    Public Sub CalculateBD(txtInput As TextBox, lblOutput As Label, lengthfornumber As Long)
        Dim i
        Dim character(Len(txtInput.Text))
        For i = 1 To Len(txtInput.Text)
            character(i) = Mid$(txtInput.Text, i, 1)
            If character(i) = "0" Or character(i) = "1" Then
            
            Else
                Call MsgBox("The data you entered is not a 1 or a 0! ", vbCritical Or vbDefaultButton1, "Incorrect Data!")
                Exit Sub
            End If
        Next i
        Dim multiplynumber As Long
        multiplynumber = 1
        For i = lengthfornumber To 1 Step -1
            If i = lengthfornumber Then
                multiplynumber = 1
            Else
                multiplynumber = multiplynumber * 2
            End If
            If character(i) = "1" Then
                lblOutput.Caption = lblOutput.Caption + multiplynumber
            End If
        Next i
    End Sub
    What it highlights is in bold. Please help. i do not understand why it is doing this...
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Compile Error: Constant expression required? Help!

    This:
    Code:
    Dim character(Len(txtInput.Text))
    Does not work. Instead try:
    Code:
    Dim character()
    Redim character(Len(txtInput.Text))
    Or better:
    Code:
    Dim character() As String
    Redim character(1 To Len(txtInput.Text))

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Compile Error: Constant expression required? Help!

    Okay. Worked! Thanks!
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

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