Format() problem in imported project

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
I have a project written a year or so ago and in use on a handheld computer terminal. It works fine. In three places it uses the Format() function, as in:
VB.NET:
strTagIDToCollapse = Format(gnumRFIDTagValueToWrite, "00")
- ensures a single figure appears as 01, 02 etc.
or
VB.NET:
Format(Date.Now, "dd/MM/yyyy")
- you know the sort of thing. Works fine.
I want to create a new project exactly based on the existing one. I created the new project, added in all the same dlls, added all the same References, ticked all the same boxes (and I have checked everything several times).
I imported the .vb from the original project into the new project, but where there are Format(whatever) items, I get the following errors for each instance of Format():
HTML:
Error	1	Argument not specified for parameter 'format' of 'Public Shared Function Format(enumType As System.Type, value As Object, format As String) As String'.
then
HTML:
Error	4	Value of type 'Date' cannot be converted to 'System.Type'.
Needless to say, I don't get these errors in the original project but I do in the clone.

What references or etc. do I need to get rid of the errors?

I think the second error of each pair will go away when the first one is sorted.

Thank you.
 
One simple solution would be :-

VB.NET:
strTagIDToCollapse = String.Format("{0:00}", gnumRFIDTagValueToWrite)
 
Thank you. But I wonder why my cloned project fell over at those lines? Does specifying 'String.' remove the need for a reference? If so, which one? Again, all references in the original project are present in the clone.
 
From the Object browser, it looks like it is assuming System.Enum.Format (because you havent specificially told it String.Format):-

VB.NET:
Public Shared Function Format(ByVal enumType As System.Type, ByVal value As Object, ByVal format As String) As String
    Member of System.Enum
 
Your code used a call to some Format method, which could be anything and compilers starts looking for known places that has a Format function with a compatible signature. It apparantly only found one Format function "Format(enumType...." which is not something I know right away (*edit: InertiaM found it looks like), so it is probably a function available somewhere in your project or references, but of course it doesn't match the one you used to call. I think your original call was for the Microsoft.VisualBasic Format function. This is a VB runtime function, and in a default project this is available because (a) the library it is in is always referenced in VB projects and (b) that namespace is globally imported by default in new projects. InteriaM suggested you use the Format instance method of the String class, which I also agree with.
 
Back
Top