Results 1 to 4 of 4

Thread: [RESOLVED] [2005] some probs and questions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Resolved [RESOLVED] [2005] some probs and questions

    1.

    VB Code:
    1. Public Function GetExplorerOptions()
    2.         'Get the options for the explorer
    3.         FileOpen(1, ApplicationDataExplorerOptionsURL, OpenMode.Input)
    4.         StartHomePageOnLoad = LineInput(1).Trim
    5.         RestoreLastWebPagesOnLoad = LineInput(1).Trim
    6.         DeleteCookiesOnClose = LineInput(1).Trim
    7.         DefaultSearchEngine = LineInput(1).Trim
    8.         EnabledPopupBlocker = LineInput(1).Trim
    9.         NotifyPopupBlocked = LineInput(1).Trim
    10.         FileClose(1)
    11.     End Function

    I use Call GetExplorerOptions to get it!

    Something wrong with the public function GetExplorerOptions() line, this is how I have always done it, so what have I done wrong?

    Error: Function without an 'As' clause; return type of Object assumed.

    2. What is meant by an 'unused local variable'?

    3.
    Code:
    VB Code:
    1. xk = Weekday(fdate, FirstDayOfWeek.Sunday)
    2.         Select Case xk
    3.             Case 1
    4.  
    5.                 mtdate = "Monday"
    6.             Case 2
    7.  
    8.                 mtdate = "Sunday"
    9.             Case 3
    10.  
    11.                 mtdate = "Tuesday"
    12.             Case 4
    13.  
    14.                 mtdate = "Wenesday"
    15.             Case 5
    16.  
    17.                 mtdate = "Thursday"
    18.             Case 6
    19.  
    20.                 mtdate = "Friday"
    21.             Case 7
    22.  
    23.                 mtdate = "Saturday"
    24.         End Select

    Error: Operands of type Object used in expressions for 'Select', 'Case' statements; runtime errors could occur

    Appears to be programmed correctly!!!

    Thanks Guys
    Last edited by arcon5; May 22nd, 2006 at 06:41 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] some probs and questions

    1) Most functions are declared as such:

    [Public|Private] Function <Function Name> (argument list) As <Return Type>

    When you don't specify the return type, the default type of object is added, which is basically NEVER a good idea. You should ALWAYS specify the type of the return, even if the type is Object.

    2) Never seen that message, but it probably means a variable declared within a sub or function is not actually used anywhere in the sub or function. This wouldn't harm anything, but it would take up a small amount of space (unless it was optimized away), and could indicate a bigger problem.

    3) Can't answer: Need to see the line that declares variable xk.
    My usual boring signature: Nothing

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] some probs and questions

    1. In VB.NET a function must have a return type and it should return an object of that type, e.g.
    VB Code:
    1. Public Function ReturnAValue() [B][U]As String[/U][/B]
    2.     Dim aValue As String
    3.  
    4.     'Use aValue here.
    5.  
    6.     [B][U]Return aValue[/U][/B]
    7. End Function
    If you don't want to return a value then create a procedure instead of a function:
    VB Code:
    1. Public [B][U]Sub[/U][/B] DontReturnAValue()
    2.     'Do something here.
    3. End [B][U]Sub[/U][/B]
    2. It means that you've declared a variable in a method and never used it, e.g.:
    VB Code:
    1. Public Sub SomeSub()
    2.     Dim str As String '<- Unused local variable
    3.  
    4.     MessageBox.Show("Hello World")
    5. End Sub
    3. You have almost certainly declared the 'xk' variable as type Object instead of type Integer, or quite possibly not specified a type at all, in which case it defaults to Object. ALWAYS, ALWAYS, ALWAYS specify the type of EVERY variable. I would advise not using the Weekday function at all and doing this:
    VB Code:
    1. Dim fdate As Date = Date.Today
    2.  
    3. Select Case fdate.DayOfWeek
    4.     Case DayOfWeek.Sunday
    5.  
    6.     Case DayOfWeek.Monday
    7.  
    8.     Case DayOfWeek.Tuesday
    9.  
    10.     Case DayOfWeek.Wednesday
    11.  
    12.     Case DayOfWeek.Thursday
    13.  
    14.     Case DayOfWeek.Friday
    15.  
    16.     Case DayOfWeek.Saturday
    17.  
    18. End Select
    What's even easier is this:
    VB Code:
    1. Dim dayName As String = fdate.DayOfWeek.ToString
    2.  
    3. MessageBox.Show(dayName)
    You'll find that that will give you the correct day name without need for a Select Case. Smart use of enumerated types like DayOfWeek make your life easier.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Re: [2005] some probs and questions

    jmcilhinney, on all 3 questions you are correct! Thank you.

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