I'm trying to get information about specific branches in TFS, so to start, I'm trying to create a variable to assign as a BranchHistoryTreeItem. However, when I pass in the ItemSpec, I'm getting an error on Spec (not the definition, but where it's passed into GetBranchHistory):
Value of type 'Microsoft.TeamFoundation.VersionControl.Client.ItemSpec' cannot be converted to '1-dimensional array of Microsoft.TeamFoundation.VersionControl.Client.ItemSpec'
I understand the error, but I'm not entirely sure why it throwing it. Isn't this data type exactly what it's looking for? I believe I have the ItemSpec declared correctly, but I'm a bit lost here. Can anyone offer some advice on why I'm getting this? Code:
Sub GetBranchInfo()
Dim tfs As New TfsTeamProjectCollection(Common.BuildServerURI)
Dim Version = tfs.GetService(Of VersionControlServer)()
Dim Spec As New ItemSpec("$/Project1", RecursionType.None)
Dim BranchHistory As New BranchHistoryTreeItem(Version.GetBranchHistory(Spec, VersionSpec.Latest))
End Sub
GetBranchHistory takes an array of ItemSpecs.
My VB is a little rusty, but I think you want something like:
Dim Spec As New ItemSpec("$/Project1", RecursionType.None)
Dim Specs(1) = new ItemSpec() {Spec}
Dim BranchHistory As New BranchHistoryTreeItem(Version.GetBranchHistory(Specs, VersionSpec.Latest))
Related
Dim policy_key() As RenewalClaim.PolicyKeyType
policy_key(0).policyEffectiveDt = date_format_string(ld_EffectiveDate)
Getting error at Line2.
An Error occured - Object reference not set to an instance of an object.
Each element of object arrays also needs to be declared as a new object too.
Dim policy_key() As RenewalClaim.PolicyKeyType
Redim policy_key(0)
policy_Key(0) = new RenewalClaim.PolicyKeyType
policy_key(0).policyEffectiveDt = date_format_string(ld_EffectiveDate)
QUICK TIP: When declaring classes structures etc, it is useful to name them so you can see what type they are....
e.g.
cls_Policy_Key for a class
str_Policy_Key for a structure etc.
When you come back to your code after a year.. you will thank yourself for doing so.
Dim policy_key() As RenewalClaim.PolicyKeyType
is part of your problem. When you are declaring policy_key() you are actually declaring it as an array with no elements. If you don't particularly need to use an array, for example, if you don't need to add objects to a particular element number, you might be better using a list and declaring it like this
Dim policy_key As New List(Of RenewalClaim.PolicyKeyType)
This way, you can add items easily without having to resize your array each time - The code is a little longer than Trevor's answer, but less prone to errors when you extend your code -
dim newPolicy_Key as RenewalClaim.PolicyKeyType
newPolicy_Key.policyEffectiveDt = date_format_string(ld_EffectiveDate)
policy_Key.add(newPolicyKey)
I'm currently trying to figure out the basics of remote function calls via vb .NET. I feel pretty helpless however, because their just isn't any useful documentation for the most simple of tasks.
What I'm trying to do atm is starting the transaction CO13, write the confirmation number in the appropriate field and cancel the order. Even this simple tasks turned out to be a pain in the ass. I'm still not sure how to access and modify the contents of a specific field. There are some examples with tables for excel in the net, but hat's about it. What I have so far is this (login is working and in another function):
Public Function stornieren() As Boolean
Dim ordernr As String
Dim confirmationnr
Dim confirmation As Object
Dim R3 As Object
Dim CO13 As Object
Dim result
R3 = CreateObject("SAP.Functions")
ordernr = TextBox3.Text
confirmationnr = TextBox4.Text
CO13 = R3.Add("RFC_CALL_TRANSACTION_USING")
CO13.exports("TCODE") = "CO13"
CO13.exports("MODE") = "S"
confirmation = CO13.exports("RUECK")
confirmation.value = confirmationnr
result = CO13.call
End Function
RUECK is the Field Name. I want to write the value of "confirmationnr" into the field RUECK. "confirmation.value = confirmationnr" throws the error message "the object variable could not be determined" and "NullReferenceException" was not handled. Sounds to me like the object is empty.
Thanks in advance.
EDIT: Now trying via BAPIs and particularly BAPI_PRODORDCONF_CANCEL. I have no idea about the syntax though. Any help would be appreciated.
When initialising a list or a queue or a stack or anything similar, which method is preferred?
Dim q as Queue(Of Integer) = New Queue(Of Integer)
or
Dim q as New Queue(Of Integer)
Also, I've started to use New for string and integer variables - is this stupid? Is there any disadvantage to using New rather than just setting the variable to the default setting? E.g.
Dim Num1 As New Integer
Dim Str1 As New String("")
Dim Bool1 As New Boolean
Thank you!
If you'd ask programmers whether they like typing more or less when writing a program then the usual answer is "less!". If you ask them whether they like more or less bugs, the usual answer is "less!" Those are conflicting goals.
The As New syntax has been part of VB.NET for a very long time. It however does come with strings attached, you leave it entirely up to the runtime to figure out whether or not a new object should be created. That does tend to be a bug generator. Sometimes you really do want to create a new object, even though the variable is already assigned. It is also rather ambiguous, in this snippet for example:
For ix As Integer = 0 To 42
Dim q As New Queue(Of Integer)
'' etc...
Next
Question is: do you get one instance of the queue, created in the first pass of the loop or do you get 43 of them? What was actually intended by the programmer? It isn't very clear from the syntax.
There is a 3rd alternative that you overlooked and the one I prefer. Available since VB9 (aka VS2008) called "type inference". Where you don't specify the type of the variable but leave it up to the compiler to figure it out. This option needs to be turned on with Option Infer On, it is turned on by default. It combines the advantages of the abbreviated syntax that As New has and still lets you create the object explicitly in your code with the New statement:
Option Infer On
...
For ix As Integer = 0 To 42
Dim q = New Queue(Of Integer)
'' etc...
Next
Where q is inferred to be of type Queue by the compiler and it is crystal clear that the code generates 43 instances of the queue. The exact equivalent in the C# language is the var keyword.
I am trying to run this line of code:
Dim OrderedFiles() As String = Directory.GetFiles(FilePath).OrderBy(x >= x.CreationTime)
I get an error on x saying x is not declared.
I have my project set to Option Strict Off and Option Infer On. If I turn ON Option Strict then I get thousands of errors from the project(it is inherited) and I don't have the time to fix all of them, but x no longer gives me an error. I have googled until I want to throw my computer out the window.
Any help on how to correct this statement would be appreciated.
Edit:
I was hoping for a more elegant solution but here is what I came up with to solve this particular problem.
Dim fileList() As String = Directory.GetFiles(FilePath)
Dim fileDate(fileList.Length - 1) As DateTime
For i As Integer = 0 To fileList.Length - 1
fileDate(i) = New FileInfo(fileList(i)).CreationTime
Next
Array.Sort(fileDate, fileList)
With EmailTemplates_DropDownList
.DataSource = fileList.Reverse.Take(5)
.DataBind()
End With
It is not particularly elegant but it does the job. I was hoping for a one liner LINQ solution and I just don't have the background in LINQ to know how to do the job, time to go buy a book.
I'm not sure where you got this syntax from:
OrderBy(x >= x.CreationTime)
That almost looks like the C# syntax of
OrderBy(x => x.CreationTime)
but I believe in VB you would use
OrderBy(Function(x) x.CreationTime)
That's certainly what the example in Enumerable.OrderBy would suggest.
EDIT: At that point you'll get a different error, as per Steve's post... but he hasn't corrected the syntax. I suspect you want:
Dim OrderedFiles() As FileInfo = new DirectoryInfo(FilePath).GetFiles().
OrderBy(Function(x) x.CreationTime).
ToArray()
Directory.GetFiles() returns the names of files (including their paths) in the specified directory.
It's not possible to use x.CreationTime, x is a string
Probably you should use DirectoryInfo
Dim di as DirectoryInfo = new DirectoryInfo(FilePath)
Dim OrderedFiles = di.GetFiles().OrderBy(Function(x) x.CreationTime).Take(3)
Dim fi as FileInfo
For each fi in OrderedFiles
Console.WriteLine(fi.FullName)
Next
how can I convert an object type to a GUID type in VB.NET?
I'm not sure what exactly you want but this might help:
Dim g = CType(obj, System.Guid)
If you want to convert a string to a Guid:
Dim g = New Guid(myString)
If you are looking to create the object as a new guid, use the following call:
dim objvar as guid = System.GUID.NewGuid()
edit Your question is a little unclear when you say "convert". If you already have the object created and assigned, use DirectCast to create an object that the Visual Studio environment will recognize.
Mehrdad's sample will work, however it is always best to declare the data type for all your variables:
Dim g As Guid = objectVariable
In this case there is no need to use CType or DirectCast.