|
-
Feb 2nd, 2000, 02:10 AM
#1
Thread Starter
Hyperactive Member
Hi all,
I have a ini file that looks like this:
[Settings]
UpdateExePath=H:\intranet\timesheets\
FileName=update.bat
Now here is my Code (API Declarations are already made)
Dim strBuffer as String
strBuffer = space(255)
n% = GetPrivateProfileString("Settings", "UpdateExePath", "", strbuffer, Len(strbuffer), inifile)
sUpdatePath = LTrim$(RTrim$(strbuffer))
sDrive = Left$(strbuffer, 2)
q% = GetPrivateProfileString("Settings", "FileName", "update.bat", strbuffer, Len(strbuffer), inifile)
sFileName = strbuffer
FullPath = sUpdatePath & sFileName
msgbox FullPath, 64, "Full Path and File"
Please pardon the coding 
Anyway, When I do the message box, only the 'sUpdatePath' variable is seen and 'sFileName' is nowhere. I've checked to make sure the sFileName gets a value and it does, but then loses it when combined together.
It seems sUpdate won't let sFile show itself.
Does anyone have any idea what I'm doing wrong or not doing?
I'm using VB3 Prof
Thanks,
JazzBass
[This message has been edited by JazzBass (edited 02-02-2000).]
-
Feb 2nd, 2000, 02:15 AM
#2
Hyperactive Member
ok I see one problem but I don't think it will fix your problem. Here is an error look what you said
[Settings]
UpdateExePath=H:\intranet\timesheets
FileName=update.bat
So when you combine those two look what you get
H:\intranet\timesheetsupdate.bat
right so you are missing the \ in between the two so what you should say is
FullPath = sUpdatePath & "\" & sFileName
There you go and maybe this will end up fixing everything
------------------
Sincerely,
Chris
:-) ;-)
just have fun out there and live life to the fullest while it is still here
Email [email protected]
-
Feb 2nd, 2000, 02:31 AM
#3
Thread Starter
Hyperactive Member
PITBULLCJR
Thanks, but I was trying to change the INI file and I forgot to fix that when I pasted it. I have since fixed in my original post.
I tried it, but that did not work. 
Thanks again,
JazzBass
-
Feb 2nd, 2000, 05:58 PM
#4
Frenzied Member
You'll probably find that one of the returned strings from the function has a CHR(0) (NULL) in it causing the rest of the string to disappear; The problem could be in the way you are reading the .INI file - try this function, I never had any problems with it;
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFilename As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFilename As String) As Long
Function ReadINI(fname As String, Section As String, KeyName As String, IniDefault As String, ExpLength As Long) As String
Dim FindNul As Integer
Dim returned As Long
Dim junk As String * 300
ReadINI = ""
returned = GetPrivateProfileString(Section, KeyName, IniDefault, junk, ExpLength, fname)
FindNul = InStr(junk, Chr(0))
If FindNul > 1 Then
ReadINI = Left(junk, FindNul - 1)
ElseIf FindNul = 1 Then
ReadINI = IniDefault
Else
ReadINI = junk
End If
ReadINI = Trim(ReadINI)
End Function
The extra FindNull stuff is not included in the example in VB-WORLD TIPS and if it is missing it doesn't always work properly...
Call it using;
MyString=Readini([filename],[section],[key],[default value],[expected length])
If you're interested, here is the WriteINI function;
Sub WriteINI(fname As String, Section As String, KeyName As String, IniValue As String)
Dim returned As Long
returned = WritePrivateProfileString(Section, KeyName, IniValue, fname)
End Sub
Call it using;
WriteINI [filename],[section],[key], [value]
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
-
Feb 2nd, 2000, 09:55 PM
#5
Thread Starter
Hyperactive Member
Mark,
Thanks a lot. That's exactly what the problem was. Thanks for the code.
JazzBass
------------------
21 yr old beginner VB Programmer
VB 6 Professional @ Home
VB 3 Professional @ the Office
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
|