Results 1 to 3 of 3

Thread: I have never seen anything like this..Can someone HELP!?!?!?!?!?

  1. #1
    magadass
    Guest

    I have never seen anything like this..Can someone HELP!?!?!?!?!?

    Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

    Private Sub Command1_Click()
    Dim strSysDir As String
    Dim Temp As String
    strSysDir = Space(144)
    GetSystemDirectory strSysDir, 144
    MsgBox strSysDir & "\blah.txt"
    End Sub


    Run that code and you will notice no matter what you do the strSysDir will not combine with the blah.txt and I cant figure out why not!! Maybe a Vb bug or something but what I want is c:\windows\blah.txt or if your in nt I want it to display c:\winnt\blah.txt or if you have a differently named windows directory and so on.

    I found a solution...It has a trailing null character I had to trim off..But using replace crashed vb so I trimmed it off manually...

  2. #2
    Addicted Member
    Join Date
    Feb 2001
    Location
    NJ
    Posts
    148
    You have to strip the null value that the api puts in the string. Try this, it worked for me:

    Code:
    Option Explicit
    
    Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    
    Private Sub Command1_Click()
    
    Dim strSysDir As String
    Dim Temp As String
    
      strSysDir = Space(144)
      GetSystemDirectory strSysDir, 144
      
      strSysDir = StripNull(strSysDir)
      
      MsgBox strSysDir & "\blah.txt"
      
    End Sub
    
    Public Function StripNull(ByVal strString As String)
    
    Dim NullCharPos As Integer
    
        NullCharPos = InStr(strString, Chr(0))
        If NullCharPos > 0 Then
          StripNull = Left(strString, NullCharPos - 1)
        Else
          StripNull = strString
        End If
    
    End Function



    ADO, SQL, Access, HTML, ASP, XML
    Visual Basic 6.0 SP5 Enterprise Edition
    VB.Net


  3. #3
    magadass
    Guest
    Yeah I just figured that out like right before I looked back on here..Thanks Anyways tho...

    I tried using replace chr(0) but it crashed..wierd stuff

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