|
-
Jun 6th, 2001, 03:11 PM
#1
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...
-
Jun 6th, 2001, 03:15 PM
#2
Addicted Member
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
-
Jun 6th, 2001, 03:18 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|