|
-
May 22nd, 2006, 06:36 PM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] some probs and questions
1.
VB Code:
Public Function GetExplorerOptions()
'Get the options for the explorer
FileOpen(1, ApplicationDataExplorerOptionsURL, OpenMode.Input)
StartHomePageOnLoad = LineInput(1).Trim
RestoreLastWebPagesOnLoad = LineInput(1).Trim
DeleteCookiesOnClose = LineInput(1).Trim
DefaultSearchEngine = LineInput(1).Trim
EnabledPopupBlocker = LineInput(1).Trim
NotifyPopupBlocked = LineInput(1).Trim
FileClose(1)
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:
xk = Weekday(fdate, FirstDayOfWeek.Sunday)
Select Case xk
Case 1
mtdate = "Monday"
Case 2
mtdate = "Sunday"
Case 3
mtdate = "Tuesday"
Case 4
mtdate = "Wenesday"
Case 5
mtdate = "Thursday"
Case 6
mtdate = "Friday"
Case 7
mtdate = "Saturday"
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.
-
May 22nd, 2006, 06:51 PM
#2
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
 
-
May 22nd, 2006, 07:08 PM
#3
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:
Public Function ReturnAValue() [B][U]As String[/U][/B]
Dim aValue As String
'Use aValue here.
[B][U]Return aValue[/U][/B]
End Function
If you don't want to return a value then create a procedure instead of a function:
VB Code:
Public [B][U]Sub[/U][/B] DontReturnAValue()
'Do something here.
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:
Public Sub SomeSub()
Dim str As String '<- Unused local variable
MessageBox.Show("Hello World")
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:
Dim fdate As Date = Date.Today
Select Case fdate.DayOfWeek
Case DayOfWeek.Sunday
Case DayOfWeek.Monday
Case DayOfWeek.Tuesday
Case DayOfWeek.Wednesday
Case DayOfWeek.Thursday
Case DayOfWeek.Friday
Case DayOfWeek.Saturday
End Select
What's even easier is this:
VB Code:
Dim dayName As String = fdate.DayOfWeek.ToString
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.
-
May 22nd, 2006, 07:22 PM
#4
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|