|
-
Apr 5th, 2002, 02:07 PM
#1
Thread Starter
Fanatic Member
returned ini values have ||||||| at end
I am pulling info from a .ini file and the value in a variable looks like this:
VALUE||||||||||||||
What are those | things and can I just do a replace | with nothing?
Thanks.
-
Apr 5th, 2002, 02:11 PM
#2
Trim it
They are junk, and Trim should remove them
-
Apr 5th, 2002, 02:13 PM
#3
Thread Starter
Fanatic Member
Already doing this and not triming it off.
Code:
gsLocation = Trim(Temp)
-
Apr 5th, 2002, 02:14 PM
#4
It's Ascii 124 - a pipe sometimes called 'logical or' symbol
It's on the Keyboard, usually on the \ (backslash) key
Code:
mystr = "VALUE||||||"
mystr=Replace(mystr,chr124),"")
-
Apr 5th, 2002, 02:15 PM
#5
-
Apr 5th, 2002, 02:15 PM
#6
PS: are you using GetPrivateProfileString or some other api to read the INI file? That works better.
-
Apr 5th, 2002, 02:22 PM
#7
Thread Starter
Fanatic Member
The following doesn't work either:
gsLocation = Replace(Trim(Temp), Chr(124), "")
HERE IS THE WHOLE SECTION OF CODE:
Dim ret As Long
Dim Temp As String * 50
Dim sLoc As String
sLoc = "c:\windows\File.ini"
ret = GetPrivateProfileString("Location", "FullPath", sLoc, Temp, Len(Temp), sLoc)
If ret = 0 Then
Beep
Else
gsLocation = Replace(Trim(Temp), Chr(124), "")
End If
.....
-
Apr 5th, 2002, 02:24 PM
#8
real quick do this
msgbox Right(gsLocation,1)
tell me the messagebox says
-
Apr 5th, 2002, 02:25 PM
#9
I give up. Something else is going on. Replace works just fine when I try it on my machine here.
-
Apr 5th, 2002, 02:25 PM
#10
after setting gsLocation of course
-
Apr 5th, 2002, 02:27 PM
#11
Thread Starter
Fanatic Member
Cander - nothing appears so I am going to say it's a space maybe or could it be null?
-
Apr 5th, 2002, 02:29 PM
#12
a null .
here try this
Code:
Do Until Asc(Right(Temp, 1)) <> 0
Temp = Left(Temp, Len(strName) - 1)
DoEvents
Loop
gsLocation = Temp
-
Apr 5th, 2002, 02:30 PM
#13
oops change strName to Temp
-
Apr 5th, 2002, 02:33 PM
#14
Thread Starter
Fanatic Member
Cander - That didn't work either.
-
Apr 5th, 2002, 02:33 PM
#15
arggh. well im tapped out of ideas
-
Apr 5th, 2002, 02:40 PM
#16
Join the club. He's doing something else somewhere or he's working with hosed data.
Oh. wait. Hosed data - he isn't init - ing the temp string
Code:
Dim Temp as String *50
'add
Temp = string(chr(0), 50) ' initilaize it to all chr(0)
....
After you get a RETURN
Temp = left(temp,instr(temp,chr(0)-1)
See if that doesn't help
-
Apr 5th, 2002, 02:48 PM
#17
Thread Starter
Fanatic Member
Give me a type mismatch error on this line.
Temp = string(chr(0), 50) ' initilaize it to all chr(0)
-
Apr 5th, 2002, 02:52 PM
#18
Frenzied Member
Do you need to use a fixed length string?
That is causing all your problems
-
Apr 5th, 2002, 02:57 PM
#19
Thread Starter
Fanatic Member
Yeah, I hear you on that one. I tried without and it doesn't like that for some reason.
Here is where I got info on it:
http://www.vb-world.net/files/tip17.html
-
Apr 5th, 2002, 03:15 PM
#20
I inverted the arguments. If you can code you can fix it, too.
Jeez Louise.
Code:
Temp = string(50,vbNull) ' it to all chr(0)
This is why you have the trailing crud. GetPRivateProfileString uses null-terminated string because it is written in C
-
Apr 5th, 2002, 03:19 PM
#21
Frenzied Member
This is what I always use and it works without problems.
VB Code:
'Add this stuff to a module
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, _
ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, _
ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
Sub ReadIniFile(SectorName As String, KeyName As String, Inifile As String)
'Param1
'The header of the INI file section the value is in.
'Param2
'The name of the value to read.
'Param3
'The value to return if a valid value cannot be read. Make it something that would definitely not be read, such as "(error)".
'Param4
'A fixed-length string that will receive either the string read from the file or lpDefault.
'Param5
'The length in characters of lpReturnedString.
'Param6
'The filename of the INI file to read from
Dim uname As String ' receives the value read from the INI file
Dim slength As Long ' receives length of the returned string
uname = Space(255) ' provide enough room for the function to put the value into the buffer
slength = GetPrivateProfileString(SectorName, KeyName, "(error)", uname, 255, Inifile)
RetString = Left(uname, slength) ' extract the returned string from the buffer
End Sub
Sub WriteIniFile(ByVal SectorName As String, ByVal KeyName As String, ByVal KeyValue As String, ByVal Inifile As String)
'Param1
'The section of the INI file to write to.
'Param2
'The name of the value to set.
'Param3
'The string to set as the value.
'Param4
'The filename of the INI file to write to.
Dim Retval As Long ' return value
' Set the string value.
Retval = WritePrivateProfileString(SectorName, KeyName, KeyValue, Inifile)
End Sub
'Then to use it in a form add this code
Dim retString as String
Call ReadINIFile("MyApp", "DataSource", iniFile)
'where MyApp is the category, DataSource is the key,
'and inifile is the full path and file name of your inifile
'Then check to see what was returned
If retString = "(error)" then
'The key wasnt found in the INI file
'so you could write a default value here if u wanted
Call WriteIniFile("MyApp", "DataSource", "C:\Temp", iniFile)
Else
'The value was found
msgBox retString
End if
-
Apr 5th, 2002, 06:48 PM
#22
Thread Starter
Fanatic Member
Here is some code I found here at vb-world that works great.
Function TrimNull(sNullString As String) As String
'=========================================================
'=========================================================
Dim iLen As Integer
Dim iTemp As Integer
Dim sTemp As String
iLen = Len(sNullString)
iTemp = InStr(sNullString, Chr$(0))
If iTemp <> 0 Then
sTemp = Left$(sNullString, iTemp - 1)
sNullString = sTemp
End If
TrimNull = sNullString
End Function
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
|