Results 1 to 4 of 4

Thread: [RESOLVED] Help: Variable not defined

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    1

    Resolved [RESOLVED] Help: Variable not defined

    well hi.. i Got this Variable not defined error(durationinms) .. and I cant seem to find a solution for it so :
    Code:
    Public Function MP3DurationInMs()
    On Error GoTo TheError
    Dim TotalTime As String * 128
    Dim T As String
     TheFile$ = Chr$(34) + Trim(MP3File$) + Chr$(34)
        mciSendString "set " & TheFile & " time format ms", TotalTime, 128, 0&
        mciSendString "status " & TheFile & " length", TotalTime, 128, 0&
        mciSendString "set " & TheFile & " time format frames", 0&, 0&, 0&
        DurationInMs = Val(TotalTime)
        Exit Function
    TheError: MsgBox Err.Description, , " Error"
    
    End Function
    i was using a MP3 class... added it to my project.. i can test run it .. and all will work.. but the moment i want to compress i get the Variable not defined error.. ..however i thought it IS defined. ? any help lplz

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Help: Variable not defined

    Welcome to VBForums

    It isn't defined in your code, but based on the name it appears that is was defined at some point - and since then you have added MP3 to the start of the function name, but didn't update the name on that line.

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Help: Variable not defined

    In Visual Basic 6 (and below), the the way functions returns values is not the same as other languages. In VB6 We assign the value we want to return to a variable with the same name as the function name.

    Code:
    Public Function DurationInMs()
        '...
        DurationInMs = Val(TotalTime)    '<-- we are returning the value to function caller
    
    End Function
    So the correct thing for what you want might be this.

    Code:
    Public Function MP3DurationInMs()
        '...
        MP3DurationInMs = Val(TotalTime)    '<-- we are returning the value to function caller
    
    End Function
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help: Variable not defined

    Quote Originally Posted by Pradeep1210
    ...In VB6 We assign the value we want to return to a variable with the same name as the function name....
    It's not a variable but rather the function itself and the proof of that is that you don't have to Dim it.

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