VBScript to VB error - vb.net

I have been rewriting some of my old VBscript code to VB code.I am almost done with everything but I get an error at one place.
VB Script
Session("FirstName") = Request.Cookies("FirstName").Item
VB
Session.Add("FirstName", Request.Cookies("FirstName").Item)
and the error is
BC30455: Argument not specified for parameter 'key' of 'Public Default Property Item(key As String) As String'.
Can anybody tell me how to correct this error or atleast what does the error mean?
Thanks in advance.

Session.Add("FirstName", Request.Cookies("FirstName"))
should work , when you use .Item it is expecting a key for Item such as:
Session.Add("FirstName", Request.Cookies("FirstName").Item("ItemKey"))

Related

VB error: Overload resolution failed because no accessible accepts this number of arguements

I can't seem to get past this error that appears with this code block:
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", True).SetValue("cmd /C")
The full error is as follows:
BC30516 Visual Basic AND VB.NET Overload resolution failed because no accessible accepts this number of arguments.
Looked all over for solutions and none seem to exist or work.
Any help would be appreciated.
OpenSubKey returns a Registry​Key and SetValue needs at least 2 parameters. You are only passing one. There are good example in the documentation.

VB.net warning with VB6 code: how to fix it?

How can I use this code:
VB6.LoadResString(i)
without getting this warning:
Public Function LoadResString(ID As Integer) As String is obsolete:
'Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported
within 32 bit processes only. http://go.microsoft.com/fwlink/?linkid=160862'.
The posted link in the error and other info in the MSDN site only say to me "ehy, this is obsolete in your framework, don't use it", but what if I need it (Loads a string from a resource (.res) file.)?
How can I write it without getting that warning message?
UPDATE: Thanks, but nothing worked...

MVVM Light RaisePropertyChanged Error

I followed examples of RaisePropertyChanged for the MVVM Light libraries in a WPF application. This seems like it should be valid. Event the code hints seem to think so. But when I build, Visual Studio gives me an error and then highlights RaisePropertyChanged with light blue squiggleys. Anyone seen this issue? Is there something obvious I'm missing?
Private _selectedServerInstance As String
Property SelectedServerInstance As String
Get
Return _selectedServerInstance
End Get
Set(value As String)
_selectedServerInstance = value
RaisePropertyChanged(Function() Me.SelectedServerInstance) //Error on build
End Set
End Property
' Looks ok until I build. The Error for each line with RaisePropertyChanged using a lambda property selector is:
' error BC30518: Overload resolution failed because no accessible 'RaisePropertyChanged' can be called with these arguments:
for RaisePropertyChanged:
References required to assemblies 'System.Linq.Expressions', 'System.Runtime', 'System.ObjectModel'.
Check References in your project.
System.Runtime and System.ObjectModel are not in the list of references to choose. Is this because they are 'facade' references, and rarely get used except in the crazy case of mvvm-light?

Runtime errors might occur when converting 'dao.Field' to 'String'. VB6 to VB.NET

I have converted a VB6 project to VB.NET using Visual Studio 2008. I have some code that throws an error for invalid cast type when for doa.Field to String Type.
Here is the code that I am working with:
If rstLogin.BOF = True And rstLogin.EOF = True Then
MsgBox("User name not found, please try again!", , "Login")
frmLogin.txtUserName.Focus()
System.Windows.Forms.SendKeys.Send("{Home}+{End}")
Else
If Trim(inPassword) = Clean(rstLogin.Fields.Item("PassWord")) Then
Call MoveUserRecord(rstLogin)
LogUserIn = True
Else
MsgBox("Invalid Password, please try again!", , "Login")
frmLogin.txtPassword.Focus()
System.Windows.Forms.SendKeys.Send("{Home}+{End}")
End If
End If
The error is:
Unable to cast COM object of type 'dao.FieldClass' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
The error is thrown on the part of the code for the password.
If Trim(inPassword) = Clean(rstLogin.Fields.Item("PassWord")) Then
I have tried to add .ToString() to everything that I could add it to, and I still get the same error. Can someone please tell me what I am doing wrong, and how I can fix this?
Hans Passant was really close with is answer. In order for you to fix the error, and for your code to compile correctly. You will need to use:
rstLogin.Fields("PassWord").Value.ToString()
I have tested this, and I am sure that it will work.

Write String.Join(Of T) in VB.Net

I have a simple code in C#:
Console.WriteLine(string.Join<char>("", ""));
And I can't convert it to VB.Net. Even reflector show me code in VB like:
Console.WriteLine(String.Join(Of Char)("", ""))
But it can't be compiled becouse I have an starge error:
Error 1 Expression expected.
It looks like VB.Net don't have this generic method at all.
Both project use Net Framework 4.
Why this error happened?
UPD:
I've create a custom class and copy Join(Of T) declaration to it:
Class string2
Public Shared Function Join(Of T)(ByVal separator As String, ByVal values As System.Collections.Generic.IEnumerable(Of T)) As String
Return "1"
End Function
End Class
Console.WriteLine(string2.Join(Of Char)("", ""))
It works
UPD2:
My compilation string, where you can see that I'm using Net4:
http://pastebin.com/TYgS3Ys3
Do you have a code element named String somewhere in your project?
Based on the answer you have added to this question (where you indicate that changing String to [String] appears to have solved the problem), I guessed that this may be the result of a naming collision.
I was able to duplicate the error you are seeing -- "Expression expected" -- by adding a module to my project called String and defining a (non-generic) Join method from within that module.
This may not be the specific scenario you find yourself in. But the fact that the code works for you with [String] is, to me, very compelling evidence of a simple namespace collision.
Based on the documentation for the "Expression expected" error, I'm guessing you haven't included the entire section of code where this error is appearing for you.
Do you have a lingering operator such as + or = somewhere?
(The VB.NET code you posted is indeed equivalent to the C# code above it and should compile no problem. This is why I suspect the real issue lies elsewhere.)
String.Join<T>(string, IEnumerable<T>) is useful with LINQ, for standard joins is better to use the String.Join(string, string()) overload.
In C#, "" as Char produces an empty Char (\0). Writing the same thing ("") in VB produces an empty string which is not the same as an empty char. In order to produce an empty character, you'll have to write New Char().
Your VB code therefore becomes:
Console.WriteLine(String.Join(Of Char)(New Char(), New Char()))
Edit
I just checked and it appears String.Join does not support the format you're specifying.
Instead, it goes as follows:
Join(separator As String, value As String()) As String
Your code should be as follows:
Console.WriteLine(String.Join("", New String() {""}))
String.Join(Of Char)(str1, str2) wasn't added til .net 4, it seems. That's why your custom class worked -- it had the declaration, but the String class in the framework you're actually using doesn't.
Check your settings and references to make sure you're targeting .net 4 all around -- cause that's the only thing that seems able at this point to stop the call from working.
Here the solution:
Console.WriteLine([String].Join(Of Char)("", ""))
Why this problem occurs only with generic method? I wish I know...