|
-
Apr 28th, 2011, 08:48 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Access of Shared member, constant member, enum member etc...
Hi guys,
Cannot appear to be able to get this function to not have the above error.... Any ideas?
Code:
Private Function GetIncidentActions(ByVal FromAgentID As Integer, ByVal ToAgentID As Integer, ByVal incidentAction As Integer, ByVal ActionDate As Date) As String
Dim str As String = String.Empty
str += String.Format("({0}) ", ActionDate.ToString())
Select Case incidentAction
Case 1
str += str = "Assigned By "
str += str.Format("{0} for {1}", New Agent(FromAgentID).DisplayName, New Agent(ToAgentID).DisplayName)
Case 2
str += "Action By "
If FromAgentID <> ToAgentID Then
str += str.Format("{0} for {1}", New Agent(FromAgentID).DisplayName, New Agent(ToAgentID).DisplayName)
Else
str += New Agent(FromAgentID).DisplayName
End If
Case 4
str += "Closed By "
str += New Agent(FromAgentID).DisplayName
End Select
Return str
End Function
Oh ther error is on both 'str.format'
Many thanks
Dave
-
Apr 28th, 2011, 08:52 AM
#2
Hyperactive Member
Re: Access of Shared member, constant member, enum member etc...
Can you paste the code where Agent is Declared
-
Apr 28th, 2011, 09:05 AM
#3
Re: Access of Shared member, constant member, enum member etc...
If you hover your mouse over top does it give you a suggestion to fix it? The Format function of the String class is static (shared) and you will want to call it through the String class and not an instance of the String itself. You already did it with String.Empty.
-
Apr 28th, 2011, 09:06 AM
#4
Re: Access of Shared member, constant member, enum member etc...
'Format' is a shared method of the String class - it is unrelated to string instances. VB has traditionally allowed developers to do silly things like access shared members via instances.
You want to use "String.Format" instead.
-
Apr 28th, 2011, 10:11 AM
#5
Thread Starter
Addicted Member
Re: Access of Shared member, constant member, enum member etc...
Hiya,
Thanks for the reply, 'Agent' isn't really declared it is a command from an SDK i'm working with...
I changed both str.format to String.Format but the code now crashes with :
"Conversion from string "(06/04/2011 13:48:20)" to type 'double' is not valid."
Many thanks
Dave
-
Apr 28th, 2011, 10:16 AM
#6
Re: Access of Shared member, constant member, enum member etc...
I don't think that error is happening in the code you posted. So you are going to have to post the relevant code and which line you are getting the error on.
As a side note, you may want to look into the StringBuilder class.
-
Apr 29th, 2011, 03:01 AM
#7
Thread Starter
Addicted Member
Re: Access of Shared member, constant member, enum member etc...
Hiya
Thanks for your help here is the function with the code that calls it. I have marked the line that it fails on...
Code:
Private Function GetIncidentActions(ByVal FromAgentID As Integer, ByVal ToAgentID As Integer, ByVal incidentAction As Integer, ByVal ActionDate As Date) As String
Dim str As String = String.Empty
str += String.Format("({0}) ", ActionDate.ToString())
Select Case incidentAction
Case 1
str += str = "Assigned By " '<----- Step Over Fails On This Line?!
str += String.Format("{0} for {1}", New Agent(FromAgentID).DisplayName, New Agent(ToAgentID).DisplayName)
Case 2
str += "Action By "
If FromAgentID <> ToAgentID Then
str += String.Format("{0} for {1}", New Agent(FromAgentID).DisplayName, New Agent(ToAgentID).DisplayName)
Else
str += New Agent(FromAgentID).DisplayName
End If
Case 4
str += "Closed By "
str += New Agent(FromAgentID).DisplayName
End Select
Return str
End Function
For Each row As DataRow In tbl.Rows
iPadIncidentRTB.SelectionColor = Color.Blue
iPadIncidentRTB.SelectedText += String.Format("{0}{1}", GetIncidentActions(Convert.ToInt32(row("iAgentID")), Convert.ToInt32(row("iNewAgentID")), Convert.ToInt32(row("iIncidentActionID")), Convert.ToDateTime(row("dActionDate"))), Environment.NewLine)
iPadIncidentRTB.SelectionColor = Color.Black
iPadIncidentRTB.SelectedText += String.Format("{0}{1}", row("cResolution").ToString(), Environment.NewLine)
Next
It's failing with the error :
"Conversion from string "(06/04/2011 13:48:20)" to type 'double' is not valid."
Any help / pointers greatly apreciated.
Many thanks
Dave
-
Apr 29th, 2011, 09:03 AM
#8
Re: Access of Shared member, constant member, enum member etc...
Place this at the very top of your code file:
-
May 18th, 2011, 08:34 AM
#9
Thread Starter
Addicted Member
Re: Access of Shared member, constant member, enum member etc...
Hi,
Thanks For your reply. After reading up on 'Option Strict On' I added it to the top of the code. It then took a few hours to go through and make the necessary changes but all is now working fine and dare i say it better / faster than it was peviously...
I'll be using 'Option Strict On' in all my code from now on!!
Many thanks for all your help.
Dave
-
May 18th, 2011, 08:38 AM
#10
Re: Access of Shared member, constant member, enum member etc...
you do understand why this line failed right?
str += str = "Assigned By "
hint... it's the bolded part...
str += str = "Assigned By "
shouldn't be there...
:/
-tg
-
May 18th, 2011, 10:24 AM
#11
Thread Starter
Addicted Member
Re: Access of Shared member, constant member, enum member etc...
Hi Techgnome,
Yes I noticed that when i was going through sorting the other issues. Its amazing what a good sleep can do :-D
Many thanks
Dave
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
|