Results 1 to 4 of 4

Thread: Problem in appending string into variable

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Problem in appending string into variable

    hi! can anybody please help me with this..how can append a string into the current_user variable let say current_user = "daimous" then i want to append something after the current_user say "the great" so that i have "daimous the great" in the variable.. how can I do this? by the way, i've already tried current_user = current_user & " the great" but the "the great" string is always missing. i included my code below to give you a clear idea of what my problem is...hope you could help me with this..thanks a bunch!

    VB Code:
    1. Private Enum EXTENDED_NAME_FORMAT
    2.     NameUnknown = 0
    3.     NameFullyQualifiedDN = 1
    4.     NameSamCompatible = 2
    5.     NameDisplay = 3
    6.     NameUniqueId = 6
    7.     NameCanonical = 7
    8.     NameUserPrincipal = 8
    9.     NameCanonicalEx = 9
    10.     NameServicePrincipal = 10
    11. End Enum
    12.  
    13. Private Declare Function GetUserNameEx Lib "secur32.dll" Alias _
    14. "GetUserNameExA" (ByVal NameFormat As EXTENDED_NAME_FORMAT, _
    15. ByVal lpNameBuffer As String, ByRef nSize As Long) As Long
    16.  
    17. Private Sub Command1_Click()
    18.      Dim sBuffer As String, Ret As Long
    19.      sBuffer = String(256, 0)
    20.      Ret = Len(sBuffer)
    21.      If GetUserNameEx(NameSamCompatible, sBuffer, Ret) <> 0 Then
    22.            current_user = Left$(sBuffer, Ret) & " the great"
    23.      Else
    24.            current_user = Environ("USERNAME") & " the great"
    25.      End If
    26.  
    27.      msgbox current_user,vbOkOnly
    28. End SUb


    Output: ABS\Administrator
    *Note: "the great" is missing.. I want the great to appear after 'ABS\Administrator'.

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Problem in appending string into variable

    It's there if you use the following:

    VB Code:
    1. Debug.Print current_user

    But it doesn't show up with MsgBox for some reason. Strange.

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Problem in appending string into variable

    NO, even if I stored it into a variable and manipulate that variable it still give me the same problem.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Problem in appending string into variable

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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