Results 1 to 11 of 11

Thread: [RESOLVED] Access of Shared member, constant member, enum member etc...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    201

    Resolved [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

  2. #2
    Hyperactive Member
    Join Date
    Apr 2011
    Location
    England
    Posts
    421

    Re: Access of Shared member, constant member, enum member etc...

    Can you paste the code where Agent is Declared

  3. #3
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    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.

  4. #4
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    201

    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

  6. #6
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    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.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    201

    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

  8. #8
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Access of Shared member, constant member, enum member etc...

    Place this at the very top of your code file:

    Code:
    Option Strict On

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    201

    Resolved 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

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    201

    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
  •  



Click Here to Expand Forum to Full Width